fs-modernize¶
Clean up a project that works around tdfs4ds, without changing its business logic: the audit, the map from each work-around to the feature that replaces it, the order of the work and the definition of done.
name: "Feature Store: Modernize a workflow"
description: "Clean up an existing tdfs4ds project that works around the framework (helper modules re-implementing tdfs4ds functions, patched internals, direct writes to FS_* tables, loops around run or roll_out, hand-written expiry of entities, staging tables, hand-made reports) without changing its business logic: the audit searches, the map from each work-around to the tdfs4ds feature that replaces it, the order of the work and the definition of done. Invoke when the user says a project uses tdfs4ds but not properly, or asks to simplify, modernise or upgrade a feature-store workflow. SKIP for a new pipeline (use fs-upload / td-analytics-workflow) and for a health report of a registered store (use fs-sanity-check)."
argument-hint: "
Clean up a project so that it uses tdfs4ds as designed, and prove that it still computes the same thing.
User context: $ARGUMENTS
Related skills¶
| Step | Skill | Why |
|---|---|---|
| Time | fs-rollout |
Replace hand-made date handling: one clock, one roll_out, appended business dates. |
| Scale | fs-filter |
Entity buckets: bound the spool without a staging table; recursive views. |
| Lifecycle | fs-upload |
Changing a registered view: update in place, never remove and register again. |
| Lifecycle | fs-inspect |
Finding processes, removal, reports: the calls that replace hand-written helpers. |
| Lifecycle | fs-document |
Hand-written documentation loaded last. |
| Storage | fs-relocate |
Primary index, partitioning or a table of their own, with the history. |
| Verify | fs-modernize-verify |
API check, pattern test, stub run, comparison with the original. |
| After | fs-sanity-check |
Can run() and roll_out() still refresh every process? |
Stay inside the framework¶
A process is a view, run only by run() / roll_out(), and nothing else writes the FS_T_* tables: a refresh reproduces only what those two calls do. A loop around them, a custom step that closes validity periods or a DELETE on a storage table leaves values a refresh cannot rebuild. Use the options instead (close_absent_entities=True, a FilterManager, a TimeManager, roll_out(data_domain=...)). The table of replacements is in fs-upload (Stay inside the framework); the map below adds what a clean-up usually meets.
The rules¶
- Business logic is frozen. A clean-up changes how a process runs, never what it computes. Three changes slip in without anyone deciding them:
- an incremental cache replacing a full recomputation, which misses restated source rows;
valid_time_columnreplacing a join, which loses a filter the join applied;- a "simplified" helper view that drops a
DISTINCT, a tie-break in aQUALIFYor aCOALESCE. A row whose replacement could change values is marked changes in the audit and needs the owner's decision. - A framework option before custom code. What stays custom is plain SQL in views.
- Nothing writes to
FS_*tables, and nothing patches tdfs4ds. A patched internal breaks at the next upgrade: upgrade instead, and assert the minimum version in the connection cell. - Work in a parallel copy, on another store. The cleaned version and the original never run on the same store (they would register the same views and overwrite each other's values).
- Project preference, not a framework rule: notebooks call tdfs4ds directly, and helper modules only build SQL strings. Say so when you apply it.
Audit: what to search for¶
Search the project's notebooks and modules (rg on the folder, notebooks included). Each hit goes to the audit table.
| Look for | Search | Why |
|---|---|---|
| Helper modules importing tdfs4ds | rg -l "import tdfs4ds" outside the notebooks |
they often re-implement a tdfs4ds call |
| Private imports | rg "tdfs4ds\.\w+\._\|from tdfs4ds\..* import _" |
internals change between versions |
| Patched internals | rg "tdfs4ds\.\w+(\.\w+)* = " |
a function replaced at run time |
| Global state set by hand | rg "FEATURE_STORE_TIME\s*=" |
the valid time belongs to a TimeManager or run(at=) |
| Direct writes to the store | rg -i "(insert into\|update\|delete from\|merge into)\s+\S*FS_" |
values a refresh cannot rebuild |
| Loops around a process | rg -B2 "run\(\|roll_out\(" then read the loop |
one date at a time, or one segment at a time by hand |
| Hand-written expiry | rg -i "validend\|until_changed\|period\s*\(" |
entities closed outside the run |
| Re-registration by removal | rg "remove_process" next to upload_features |
new process id, history and documentation lost |
| Processes found by tag or name pattern | rg -i "like '%\|startswith\(" on catalog reads |
get_process_id(view) answers it |
| Staging tables | rg -i "create (multiset \|volatile )?table" |
often a spool workaround (see fs-filter) |
| Recursive SQL | rg -i "with recursive" |
slow and refused in some view shapes |
| Hand-made reports or cleanup | rg -i "dbc\.\|qrylog\|drop (table\|view)" |
sanity checks, removal plans and exports exist |
| One frozen dataset per date | rg -B3 "build_dataset\(.*as_of" inside a loop |
one history with leads and lags (fs-dataset, Training and scoring data) |
| Every feature into a training table | rg -i "create (multiset )?table .*train"; get_list_features( feeding build_dataset |
select on a snapshot, train on the selected features, read views |
| A helper that grew back after the wrappers went | the same def in several notebooks |
check each line against an upload_features option (fs-upload, A small registration call) |
| Hard-coded source names | rg "[A-Z_]+\.[A-Z_]+" in SQL strings |
one configuration cell instead |
Before the rewrite, check the calls the project makes against the installed version:
import tdfs4ds
problems = tdfs4ds.check_api_usage(["notebooks", "src"]) # names that do not exist, unknown arguments
for p in problems:
print(p["file"], p["cell"], p["line"], p["name"], p["problem"])
Replacement map¶
| The project does | tdfs4ds feature | Check |
|---|---|---|
| a connection helper | tdfs4ds.open_session(env_file, database=...) or tdfs4ds.connect(...) |
same store, same read-only stores |
sets tdfs4ds.DATA_DOMAIN by hand |
tdfs4ds.create_data_domain(...) / select_data_domain(...) |
one data domain per independent pipeline |
| finds a process id by tag or name | tdfs4ds.get_process_id(view), domain_processes(domain), get_process_info(pid) |
the same id as before |
| removes then registers a process to change it | registers the same view again (update in place) | same id, history and documentation kept |
loops on dates calling run or roll_out |
one roll_out(data_domain=...) on the domain clock |
one COMPLETED row per process and date |
| moves a cursor by hand | set_domain_time_manager(tm); soft clones follow it |
sanity_check() reports no time finding |
closes absent entities with UPDATE/DELETE |
upload_features(..., close_absent_entities=True) |
same closed entities at each date |
| a staging table to bound the spool | entity buckets with a FilterManager (fs-filter) |
same values, one COMPLETED row per segment |
| recursive SQL | bounded hops or pointer doubling in a plain view (fs-filter) |
same rows on the real chains |
| hand-written profiling or checks | sanity_check, feature_extremes, follow_up_report, plot_features |
|
| a training table built from N snapshots, the label joined from the next one | build_historical_dataset(..., feature_offsets={'<LABEL>': ['+1 month']}) read at each snapshot instant |
same rows at each instant; the population rule for "absent next period" restated and agreed |
DELETE on FS_T_* or catalog rows |
plan_removal(...) then write_removal_script(plan) |
the script's --apply ends with verify_removal: nothing left |
Audit table¶
Fill one row per finding, before changing anything:
| # | Where | What it does | Replacement | Business-logic risk | Decision |
|---|---|---|---|---|---|
| 1 | notebook, cell | none / check / changes |
- none: the replacement cannot change a value (a lookup helper, a report).
- check: it should not, and the verification will show it (a loop replaced by
roll_out). - changes: it may (an incremental design, a dropped filter). The owner decides; the default is to keep the logic. List what is kept on purpose.
Order of the work¶
- Read the data flow, notebook by notebook: sources, views, processes, datasets, consumers.
- Run the audit and fill the table.
- Pin the tdfs4ds version, read its CHANGELOG from the project's version on, and run
check_api_usage. - One data domain per independent pipeline. For example the training features and the model scores in two domains, so scores never show up among the training features.
- Rewrite in this order: time (
fs-rollout), scale (fs-filter), lifecycle (fs-upload,fs-inspect,fs-document). - Delete the helpers nothing calls any more.
- Verify (
fs-modernize-verify), on a separate store, against the original results. - Write the README: before, after, why, and the project's rules for the next contributor.
Definition of done¶
-
check_api_usagereturns nothing for the cleaned notebooks. - No code writes to an
FS_*table, no loop drivesrunorroll_out, no tdfs4ds internal is patched. - Every process is refreshed by
run()/roll_out()alone:sanity_check()says so. - Values equal the original at the reference date, every difference explained.
- Every changes row of the audit has the owner's decision.
- README and audit table delivered.
What usually goes wrong¶
| Symptom | Cause | Fix |
|---|---|---|
| Different values after a rebuild | rows written by hand were never replayed | replay from the first date: roll_out(..., time_id_start=1, force_compute=True) |
| Values under an old process id no longer read | the process was removed and registered again | register the same view, never remove it first; rebuild the history under the current id with a replay from the first date |
| Documentation gone | same cause | register in place; re-document with rebuild_documentation(objects=[...]) |
| Overlapping or missing validity periods | dates computed out of order | one roll_out over the whole calendar, from the first date |
| A run is slower after segmentation | each segment pays the fixed cost of the run | fewer, larger buckets |
| A helper copied into several notebooks after the wrappers were removed | it did what upload_features already does (a dataset at registration, skipping a computed date) |
replace each line by its option (fs-upload, A small registration call) |
| The training table holds every feature of the entity | "take everything", selection afterwards | select on a snapshot, train on a history of the selected features (fs-dataset) |
| Code in the README or a slide does not run | a paraphrase that looks like code | check every quoted line against the files (fs-modernize-verify) |
| Dates skipped after a change | a date already COMPLETED is not recomputed | force_compute=True from the first date after any logic change |