Skip to content

Maintain a workflow

A workflow changes after it goes live: a feature is added, a process is rewritten, a feature is retired, a table needs another primary index. Each recipe below says when to use it, the steps, and what to check afterwards.

All recipes stay inside the framework: processes are registered with upload_features and refreshed with run() / roll_out(). Never write to FS_T_* or the catalogs by hand, and never loop around run() in your own code.

Add a feature to a process

When: the process view gains a column you want as a feature.

  1. Add the column to the process view.
  2. Register the process again with the longer feature_names list. The same view keeps its PROCESS_ID.

    pid = tdfs4ds.upload_features(
        df='MY_DB.FEAT_ENG_CUSTOMER',                   # the process view
        entity_id=['CUSTOMER_ID'],
        feature_names=['amount_sum', 'amount_max'],     # 'amount_max' is new
        run_now=False, return_process_id=True)
    

(df can be the 'schema.view' name, as here, or the DataFrame of the view.) 3. The new feature has no history. A history is built forward only, so replay it from the first date. With a TimeManager:

```python
tdfs4ds.roll_out([pid], time_manager=tm, time_id_start=1, force_compute=True)
```

Without one, tdfs4ds.run(pid, force_compute=True) computes the current time only.

Types. A registered feature keeps its stored type. If the source type no longer fits, upload_features registers nothing, returns None and the log gives the options: CAST in the view, or widen the stored type for every producer with tdfs4ds.plan_type_change(process_id=pid) (see Relocating features). The text length of new text features is rounded up to a multiple of force_varchar_length (default 1024, recorded per process; change it with tdfs4ds.set_process_options(pid, force_varchar_length=2048)).

Check: tdfs4ds.get_process_info(pid)['FEATURE_COLUMNS'] lists the feature, and the follow-up shows COMPLETED rows for every date.

Add a process

When: a new feature-engineering view for an entity.

  1. Register it with upload_features(...). If the data domain has a domain clock and the view reads it, the process gets its own soft clone of the clock, with a log line. Pass run_now=False to register without running.
  2. Replay the history from the first date of the calendar:

    tdfs4ds.roll_out(data_domain='SALES')
    

For a process outside a domain clock, use roll_out([pid], time_manager=tm). 3. Refresh the lineage so the checks and the execution plan know the process:

```python
tdfs4ds.rebuild_lineage_graph(objects=['MY_DB.NEW_VIEW'], check=True)
```

Check: the process appears in the execution plan (tdfs4ds.analyze_parallel_plan()), and tdfs4ds.sanity_check() shows nothing new for it (see Assess workflow health).

Change the SQL of a process

When: you edit the process view, or a view it reads.

  1. Study the impact first: tdfs4ds.impact_of('MY_DB.CHANGED_VIEW', new_sql=...) lists who reads the view, what the new SQL breaks or changes, and the calls to make afterwards. See Study the impact of a change.
  2. REPLACE VIEW the changed view.
  3. Record the change and look at the versions. The next upload_features or run() captures the new SQL as a version; to do it now:

    tdfs4ds.capture_process_sql([pid], dry_run=False)
    tdfs4ds.process_sql_versions(pid)
    print(tdfs4ds.process_sql_diff(pid, 1, 2))
    

See Process versions. 3. Refresh the lineage of the edited objects and check that everything downstream still compiles:

```python
tdfs4ds.rebuild_lineage_graph(objects=['MY_DB.CHANGED_VIEW'], check=True)
tdfs4ds.check_downstream_processes(['MY_DB.CHANGED_VIEW'])   # EXPLAIN on each downstream process
```
  1. Re-document what the change touches (the object and everything downstream):

    tdfs4ds.rebuild_documentation(objects=['MY_DB.CHANGED_VIEW'])
    
  2. Recompute. Values already stored stay as they were computed. To bring the history in line with the new logic, replay every date, then the processes downstream of it:

    tdfs4ds.roll_out([pid], time_manager=tm, time_id_start=1, force_compute=True)
    

Downstream processes recorded COMPLETED on the old values, so they are skipped unless you force them (force_compute=True).

Check: sql_drift and history_mixes_versions in the workflow assessment. A history computed under several SQL versions is reported as information.

Retire a feature, or remove a process with its features

When: a feature is no longer wanted, or a whole process goes.

Removals are refused when something depends on the object, and planned instead:

  1. Plan. It lists the dependents in the order they must be removed:

    plan = tdfs4ds.plan_removal(['<process id>'])      # also view names, datasets, features
    for s in plan['steps']:
        print(s['action'], s['object'], '<-', s['reason'])
    
  2. Write the script. It is a dry run until you pass --apply:

    path = tdfs4ds.write_removal_script(plan)
    
    python tdfs4ds_removal_<timestamp>.py            # what each step would remove
    python tdfs4ds_removal_<timestamp>.py --apply    # removes, in order; stops at the first failure
    
  3. The script checks afterwards that nothing is left (catalog rows, documentation, provenance, stored SQL versions, vector-index entries) and exits with code 2 if something is. tdfs4ds.dependencies.verify_removal(plan) runs the same check alone.

Called directly, remove_process, remove_feature and remove_dataset raise tdfs4ds.DependentObjectsError when something depends on the object. To remove one feature of a process that other processes also compute, scope it:

tdfs4ds.remove_feature('amount_max', entity_id=['CUSTOMER_ID'],
                       data_domain='SALES', process_id=pid)

With process_id=, the catalog entry goes only when no other process computes the feature. Stored values are kept unless the plan was made with purge_values=True. Every removal and refusal is a row of tdfs4ds.get_removal_log(). Details: Inspect & monitor.

Remove a data domain

When: a project is abandoned, or a domain was created by mistake (a typo in DATA_DOMAIN, a test run).

There is no single call for this, on purpose: a data domain is not an object of its own. It is the DATA_DOMAIN value carried by process and feature catalog rows, and tdfs4ds.get_data_domains() lists it as long as one such row exists. Removing a domain means removing what is in it, with the same guarded removal as above, so that every dependent is seen before anything goes.

  1. Plan the removal of every process of the domain, with their features and the datasets that read them:

    dom = 'MY_DOMAIN'
    pids = tdfs4ds.domain_processes(dom)            # processes of the domain, primary store only
    plan = tdfs4ds.plan_removal(pids, purge_values=True, drop_views=True)
    for s in plan['steps']:
        print(s['action'], s['object'])
    print(plan['unverified'])                       # reads that failed: resolve them first
    

    Read the steps before going further. A dataset is in the plan when it reads a feature of the domain, including a dataset of another project that joins these features with its own: decide whether it goes, or rebuild it without them first (rebuild_dataset). purge_values=True also deletes the stored values (cannot be undone); without it the FS_T_* rows stay, invisible to every catalog. drop_views=True drops the process views; leave it out to keep their SQL.

  2. Write the script, read its dry run, then apply it:

    path = tdfs4ds.write_removal_script(plan)
    
    python tdfs4ds_removal_<timestamp>.py            # what each step would remove
    python tdfs4ds_removal_<timestamp>.py --apply    # removes, in order; stops at the first failure
    

    The script checks afterwards that nothing is left and exits with code 2 if something is.

  3. Features registered in the domain with no process (their process was removed alone, with remove_process) are not in that plan. List what is left and remove it the same way:

    fc = tdfs4ds.feature_catalog(all_data_domains=True).to_pandas()
    left = fc[fc['DATA_DOMAIN'] == dom]
    plan = tdfs4ds.plan_removal(
        [(r.FEATURE_NAME, r.ENTITY_NAME, dom) for r in left.itertuples()],
        purge_values=True)
    tdfs4ds.write_removal_script(plan)
    
  4. Remove the domain's clock setting, if it has one:

    print(tdfs4ds.get_domain_time_manager(dom))     # note the clock before removing it
    tdfs4ds.detach_domain_time_manager(dom, dry_run=True)
    tdfs4ds.detach_domain_time_manager(dom)
    

    This removes the setting only; the clock's own view and table of dates stay (they are yours: drop them by hand once no other domain reads them; get_descendants on the clock's view tells you). The TimeManager objects of the removed processes are handled by step 1: with drop_views=True the plan adds a drop_time_manager step for each soft clone (<process view>_TM) or own manager that only the removed processes use (its view, and its _HIDDEN table when nothing else reads it). A manager still read by a remaining process, dataset or view, a domain clock, and a manager whose readers could not be read from the lineage are not dropped; the last are listed under unverified, the others under kept_time_managers. Without drop_views the plan is unchanged and they stay.

  5. Check: tdfs4ds.get_data_domains() no longer lists the domain, and a cheap tdfs4ds.sanity_check() reports no lineage gap left by the removal.

The admin app writes the same script in one go: Remove objects (admin and data engineer profiles), choose the domain, Plan the removal of this whole domain, read the plan, then ⬇ Removal script. It puts steps 1, 3 and 4 in one plan (the clock setting is the last step); the app itself removes nothing.

Change the primary index, the partitioning, or give a feature its own table

When: skew, a primary index that does not match the source, two processes of one entity serialised by a shared table, or a column type that must grow.

plan = tdfs4ds.plan_relocation(process_id=pid, table_tag='SALES')          # read only
plan = tdfs4ds.plan_relocation(process_id=pid, primary_index=['CUSTOMER_ID'])
print(plan['blocking'], plan['cost'])
tdfs4ds.relocate_features(plan, dry_run=True)       # what each step would do
tdfs4ds.relocate_features(plan, dry_run=False)      # apply
tdfs4ds.verify_relocation(plan)                     # read only

The history is copied and verified before the old rows are deleted (the last step), and the datasets that read the features are rewritten and checked. The free perm of the database must hold both copies until the delete. See Relocating features.

Keep statistics, lineage, documentation and the index current

What Call Why
Optimizer statistics of the FS_T_* tables tdfs4ds.check_storage_statistics() (read only), then add_missing=True, refresh=True Without statistics Teradata can misestimate dataset queries by orders of magnitude
Persisted lineage graph tdfs4ds.rebuild_lineage_graph(all_data_domains=True); objects=[...] for edited objects only The order checks, check_upstream and the execution plan read it
Documentation tdfs4ds.rebuild_documentation(force_update=False) Documents what is not yet documented; also refreshes the lineage and the index
Vector index tdfs4ds.rebuild_vector_indexing(force_rebuild=True) The consumer agent searches it
Process SQL versions tdfs4ds.capture_process_sql(all_processes=True, dry_run=False) Stores the SQL of processes not captured yet

The admin app's Maintenance panel runs each of these, or all of them in a chain, with a live log.

A schedule that works for most stores:

When What
After every change rebuild_lineage_graph(objects=[...], check=True), sanity_check()
Daily the refresh of the data (run(data_domain=...)), the cheap sanity checks
Weekly rebuild_documentation(), check_storage_statistics(), the storage checks of the sanity check (scope='full')
Before a migration sanity_check(scope='full'), then plan_migration