Skip to content

TIMX 530 - rebuild TIMDEXDatasetMetadata with static database file approach#157

Merged
ghukill merged 5 commits into
epic-TIMX-515from
TIMX-530-create-static-metadata-db-file
Aug 6, 2025
Merged

TIMX 530 - rebuild TIMDEXDatasetMetadata with static database file approach#157
ghukill merged 5 commits into
epic-TIMX-515from
TIMX-530-create-static-metadata-db-file

Conversation

@ghukill

@ghukill ghukill commented Aug 4, 2025

Copy link
Copy Markdown
Contributor

Purpose and background context

This PR begins effectively a rewrite of TIMDEXMetadataDataset, and the process of incrementally updating TIMDEXDataset to align with those changes. Major changes:

  1. Start rewrite of TIMDEXMetadataDataset, building up functionality over the next few PRs
  2. TIMDEXDataset temporarily loses the ability to filter to only "current" records
  3. Minimally implemented, but paving the way for changing how TIMDEXDataset is loaded to expect the root of the dataset, then internally know where the ETL parquet records are

This is probably the trickiest PR for epic TIMX-515. To begin building up both TIMDEXMetadataDataset and TIMDEXDataset to more fully utilize dataset metadata, it requires temporarily stripping back functionality and unit testing.

For this review, I would ask reviewers to focus most heavily on TIMDEXMetadataDataset creating and attaching to a static metadata file as the foundation for dataset metadata. Future PRs will layer on append deltas, create views, adjust how we read data, and the associated tests.

Planned, ordered next steps:

  • Write append deltas, TIMX-527
  • Create metadata projections over static DB file and append deltas, TIMX-526
  • Fully rework TIMDEXDataset.load() and dataset "location", TIMX-533
  • Rework read methods to use SQL + metadata, TIMX-529
  • Merge append deltas into static DB, TIMX-528

How can a reviewer manually see the effects of these changes?

Despite things being in a liminal state, manual testing is possible.

1- Set AWS Dev TimdexManagers credentials

2- Set env vars:

TDA_LOG_LEVEL=DEBUG
WARNING_ONLY_LOGGERS=asyncio,botocore,urllib3,s3transfer,boto3,MARKDOWN
TIMDEX_DATASET_LOCATION=s3://timdex-extract-dev-222053980223/dataset_scratch

3- Start Ipython shell with pipenv run ipython and do some setup:

import os

from timdex_dataset_api import TIMDEXDataset, TIMDEXDatasetMetadata
from timdex_dataset_api.config import configure_dev_logger

configure_dev_logger()

td = TIMDEXDataset(os.environ["TIMDEX_DATASET_LOCATION"])
tdm = TIMDEXDatasetMetadata(os.environ["TIMDEX_DATASET_LOCATION"])

4- First, note small update to TIMDEXDataset where it knows both the dataset root location and the location of the ETL parquet files:

td.location
# Out[5]: 's3://timdex-extract-dev-222053980223/dataset_scratch'

td.data_records_root
# Out[6]: 's3://timdex-extract-dev-222053980223/dataset_scratch/data/records'

5- Recreate the dataset metadata:

tdm.recreate_static_database_file()

6- Perform very simple query demonstrating the metadata database file was created and is successfully attached:

tdm.conn.query("""show databases;""")
"""
Out[8]: 
┌───────────────┐
│ database_name │
│    varchar    │
├───────────────┤
│ memory        │
│ static_db     │
└───────────────┘
"""

tdm.conn.query("""select count(*) from static_db.records;""")
"""
Out[9]: 
┌──────────────┐
│ count_star() │
│    int64     │
├──────────────┤
│      4151483 │
└──────────────┘
"""

7- If interested, reload the TIMDEXDatasetMetadata instance and see the payoff of all this work in nearly instant dataset metadata available!

tdm = TIMDEXDatasetMetadata(os.environ["TIMDEX_DATASET_LOCATION"])
tdm.conn.query("""select * from static_db.records;""")

Ticket TIMX-526 will create all the helpful tables and views once the append deltas exist as well.

Includes new or updated dependencies?

NO

Changes expectations for external applications?

NO: still only merging to feature branch epic-TIMX-515

What are the relevant tickets?

@ghukill ghukill changed the base branch from main to epic-TIMX-515 August 4, 2025 15:05
ghukill added 4 commits August 4, 2025 11:41
Why these changes are being introduced:

The current overarching work is to support the creation and
reading of a static metadata database file and append deltas.  To
get there, very little of the original TIMDEXDatasetMetadata class
is needed or wanted.

This commit begins the process of rebuilding TIMDEXDatasetMetadata,
oriented around managing a static metadata database file, and providing
a readonly projection over that and append delta paqruet files.

How this addresses that need:

TIMDEXDatasetMetadata is almost completely rebuilt, with the first
functionality being the creation of the static metadata file by
scanning the ETL records.  Then, the ability to remotely attach in
readonly mode to this metadata database file for reading.

Note: these changes are breaking.  TIMDEXDataset cannot provide
"current" records and many unit tests are broken.  This will be
addressed in future commits as we build this class back up
with new functionality.

Side effects of this change:
* TIMDEXDataset cannot provide current records
* Unit tests are either temporarily skipped or failing

Relevant ticket(s):
* https://mitlibraries.atlassian.net/browse/TIMX-530
Why these changes are being introduced:

While the TIMDEXDatasetMetadata class is rebuilt, TIMDEXDataset
itself can no longer provide "current" records from the dataaset
as it has no metadata to work with.

This is temporary until TIMDEXDatasetMetadata is rebuilt, and
TIMDEXDataset gets new functionality based on *that* new
metadata.

How this addresses that need:
* Any reference to "current records" is removed

Side effects of this change:
* TIMDEXDataset cannot provide current records

Relevant ticket(s):
* https://mitlibraries.atlassian.net/browse/TIMX-530
Why these changes are being introduced:

This is a small change now, that will lead to a larger change later.
The TIMDEX dataset is getting more structure, and this means we will
want to initialize a TIMDEXDataset instance with the root of the dataset,
but then internally there will be more opinionation about where files
should be read and written to.

How this addresses that need:

A new property 'data_records_root' is added to TIMDEXDataset that
mirrors similar properties in TIMDEXDatasetMetadata.  This informs any
operations that need to read or write ETL records where precisely they
are in the dataset.

At this time only .write() utilizes it, but in a future ticket the
load method will be heavily reworked (if not outright removed) and
this property will be fully integrated.

This is needed now to continue updates to TIMDEXMetadataDataset
for TIMX-530.

Side effects of this change:
* Initialization of TIMDEXDataset should provide the true dataset root,
not point to /data/records.  The pipeline lambda currently does this,
but will be updated in TIMX-531.

Relevant ticket(s):
* https://mitlibraries.atlassian.net/browse/TIMX-530
* https://mitlibraries.atlassian.net/browse/TIMX-531
Why these changes are being introduced:

With the big changes to TIMDEXMetadataDataset comes the need to virtually
rewrite the test suite for that class.

The changes too TIMDEXMetadataDataset are also influencing tests for
TIMDEXDataset, both how its loaded and tested for 'current' record reading.

How this addresses that need:

This begins with some basic tests around the loading, creating, and attaching
of a static database file for TIMDEXMetadataDataset.  Future tests will
more fully exercise the final views and tables created.

This commit also *temporarily* skips a bunch of tests for TIMDEXDataset
that will not pass until the ability to limit to 'current' records
is reinsated with the updated TIMDEXMetadataDataset.

Side effects of this change:
* Test suite passes, but multiple tests are temporarily skipped.

Relevant ticket(s):
* https://mitlibraries.atlassian.net/browse/TIMX-530
@ghukill ghukill force-pushed the TIMX-530-create-static-metadata-db-file branch from 27aeb0b to 7f7800d Compare August 4, 2025 15:43
@ghukill ghukill requested a review from a team August 4, 2025 15:44
@ghukill ghukill marked this pull request as ready for review August 4, 2025 15:44
@coveralls

coveralls commented Aug 4, 2025

Copy link
Copy Markdown

Pull Request Test Coverage Report for Build 16780878765

Details

  • 80 of 88 (90.91%) changed or added relevant lines in 3 files are covered.
  • 1 unchanged line in 1 file lost coverage.
  • Overall coverage decreased (-2.0%) to 94.038%

Changes Missing Coverage Covered Lines Changed/Added Lines %
timdex_dataset_api/utils.py 13 16 81.25%
timdex_dataset_api/metadata.py 61 66 92.42%
Files with Coverage Reduction New Missed Lines %
timdex_dataset_api/dataset.py 1 96.45%
Totals Coverage Status
Change from base Build 16725129203: -2.0%
Covered Lines: 347
Relevant Lines: 369

💛 - Coveralls

@jonavellecuerdo jonavellecuerdo left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great! Just have a couple questions. My main change request / question was on whether we should keep referring to the DuckDB file as a "static" DuckDB file (see comment for more details).

I also wondered:

  1. Whether the performance on my local machine was similar to yours:
Screenshot 2025-08-06 at 9 54 41 AM
  1. Whether we should add a DEBUG log also describing the time elapsed after the "Attaching to static database file" log message

  2. Where the 'database_name_varchar' comes from:

image

Comment thread timdex_dataset_api/metadata.py
Comment thread timdex_dataset_api/metadata.py
Comment thread timdex_dataset_api/utils.py Outdated
@ghukill ghukill requested a review from jonavellecuerdo August 6, 2025 15:11
@ghukill

ghukill commented Aug 6, 2025

Copy link
Copy Markdown
Contributor Author

Looks great! Just have a couple questions. My main change request / question was on whether we should keep referring to the DuckDB file as a "static" DuckDB file (see comment for more details).

I also wondered:

  1. Whether the performance on my local machine was similar to yours:

Yep! Looks about right. The static metadata file recreation takes anywhere from 30-45 seconds. And that will grow over time, but we don't need to perform very often.

  1. Whether we should add a DEBUG log also describing the time elapsed after the "Attaching to static database file" log message

If you're comfortable with it, I'll add during TIMX-526 which is focused heavily on setting up the DuckDB context! In fact, might be in there already...

  1. Where the 'database_name_varchar' comes from:

That's just a DuckDB convention for the DuckDB query `"show databases;". For a lot of DuckDB (and other DBs for that matter) their "meta" commands like this often have kind of awkward column names because it's just communicating data.

Actually, I'm realizing that's kind of two lines! It's "database_name" as the column name, and "varchar" as the column type.

@ghukill ghukill merged commit 3efe8b7 into epic-TIMX-515 Aug 6, 2025
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants