Skip to content

fs-relocate

Give features a storage table of their own, move existing features with their history, change a primary index or partitioning, and repair a dataset that reads a stale table. A relocation is always planned first; the app never executes one.


name: "Feature Store: Relocate" description: "Generate code to give features a storage table of their own (storage_tag at registration, plan_relocation / relocate_features / verify_relocation for existing features with their history), rewrite the datasets that read them (rewrite_dataset_tables), change a process's primary index or partitioning without losing history, and repair a feature whose dataset reads a stale table. Invoke when two processes of one entity are serialised by a shared FS_T_ table, when skew or the primary index must change, or when the workflow assessment reports dataset_reads_stale_table or relocation_reverted." argument-hint: "[process-id or feature][tag]" allowed-tools: "Read, Edit, Write, Bash, Glob, Grep"


Generate Python code to move features to their own storage table (FS_T_<hash>__<TAG>).

User context: $ARGUMENTS

Step Skill Why
Trigger fs-workflow-assessment dataset_reads_stale_table, relocation_reverted, skew and primary-index findings point here.
Sibling fs-upload upload_features(..., storage_tag='SALES') starts a new process in its own table.
Sibling fs-inspect check_storage_statistics, removal and the catalog exports.

Rules

  • A feature is a (data domain, entity, name) triplet; placement is recorded in FS_FEATURE_PLACEMENT (optional table, created by setup() / connect()). Editing FEATURE_TABLE by hand does nothing: every run recomputes the name from the placement.
  • The tag is appended to the historical name; value type, primary index and partitioning stay in it. One tagged table per value type. A type changes only through value_types= / plan_type_change (below).
  • Never run a relocation without the plan first. The app never executes one.
  • Precondition: every client that runs these processes must be at least 0.3.3.30. An older client writes back to the old table (relocation_reverted).

New process in its own table

tdfs4ds.upload_features(df=df, entity_id=['CUSTOMER_ID'], feature_names=['amount_sum'], storage_tag='SALES')

A feature already registered elsewhere, or shared with another process, is refused with the fix.

Existing features, with their history

plan = tdfs4ds.plan_relocation(process_id=pid, table_tag='SALES')   # or features=[('amount_sum', 'CUSTOMER_ID', 'DOM')]
print(plan['blocking'])     # shared (include_shared=True), running, unparseable dataset, view reading the old view, space
print(plan['cost'])         # rows, perm, free perm, whether the copy redistributes
tdfs4ds.relocate_features(plan, dry_run=True)       # what each step would do
tdfs4ds.write_relocation_script(plan)               # a script: dry run unless --apply, verifies afterwards
# tdfs4ds.relocate_features(plan, dry_run=False); tdfs4ds.verify_relocation(plan)

Steps: create, copy with history, verify counts, place + catalog, rewrite datasets (EXPLAIN + equal row count), lineage, statistics, clear caches, delete the old rows (last). A failure before the delete leaves the old table intact.

To change a process's primary index to the key without its bucket column: plan_relocation(process_id=pid, table_tag='KEYPI', primary_index=['KEY']), then the usual steps.

Different distribution: plan_relocation(process_id=pid, table_tag='SALES', primary_index=['CUSTOMER_ID'], partitioning='PARTITION BY ...') - the unit is the whole process (its staging table uses the process index); a feature shared with a process that keeps another index is refused.

Changing the stored type of a feature

Use it when upload_features refused a re-registration (type no longer fits), or to widen a text/number type.

plan = tdfs4ds.plan_type_change(process_id=pid)     # features of the process that no longer fit -> narrowest type holding every producer
plan = tdfs4ds.plan_type_change(types={'<FEATURE>': 'VARCHAR(2048) CHARACTER SET UNICODE'},
                                entity=['<ENTITY_COLUMN>'], data_domain='<DOMAIN>')
# or tdfs4ds.plan_relocation(process_id=pid, value_types={'<FEATURE>': '<TYPE>'})   (no tag needed; an existing tag is kept)
tdfs4ds.write_relocation_script(plan, 'type_change.py')   # dry run, then --apply; verify_relocation checks the catalog type

New FS_T_ table with the new FEATURE_VALUE type (same index/partitioning), full history copied, catalog and datasets updated, old rows deleted last. A shared feature moves for all its producers; plan['type_changes'] lists the CASTs the other processes need before their next run. value_conversion blocks when stored values do not convert.

Datasets only

tdfs4ds.rewrite_dataset_tables('DB.DATASET')                     # dry run: new DDL; the catalog's table for each feature
tdfs4ds.rewrite_dataset_tables('DB.DATASET', dry_run=False)

Snapshot, grouped, history and lag/lead datasets all round-trip; name, DATASET_ID, columns and window are kept. A view that cannot be read back is refused.

After an older client ran a relocated process

Upgrade it, then run the same plan again (relocate_features(plan, dry_run=False)): the stray rows are moved with a sequenced merge, not a plain insert.