Skip to content

fs-lineage-graph

Maintain the persisted lineage graph (FS_LINEAGE_GRAPH): full/scoped rebuild, downstream EXPLAIN impact check, re-document the impact slice, and render an interactive pyvis network.


name: "Feature Store: Persisted Lineage Graph" description: "For a developer maintaining the persisted lineage graph (FS_LINEAGE_GRAPH). Build or fully refresh the graph, scoped-refresh just the objects you edited, check which downstream processes still compile after a change, re-document from the persisted graph, and render an interactive pyvis network. Invoke when the user edited a view/process and wants to refresh lineage/documentation without re-deriving everything, or asks \"what depends on this?\" / \"did my change break anything downstream?\". SKIP for a one-off on-the-fly Sankey from a single process — use fs-lineage; SKIP for natural-language business-user Q&A — use ca-lineage." argument-hint: "[object name(s) you changed, or empty for a full rebuild]" allowed-tools: "Read, Edit, Write, Bash, Glob, Grep"


Generate Python to manage the persisted, temporal lineage graph FS_LINEAGE_GRAPH. Unlike fs-lineage (which re-derives lineage on the fly for one seed), this graph is stored once and queried in-memory with networkx — so you get the reverse / impact direction ("what depends on X?") cheaply, and can re-document only the affected slice after an edit.

User context: $ARGUMENTS

Step Skill Why
One-off lineage fs-lineage On-the-fly dependency graph + Sankey for a single process/dataset (no persistence).
Documentation fs-document Document a single process; this skill re-documents the whole store or an impact slice.
Find objects fs-inspect List process/dataset catalogs to pick object names.
Business Q&A ca-lineage Natural-language "where does this come from?" through the consumer agent.

Demos: demos/notebooks/A1 - Lineage and impact.ipynb.

Ask for any missing values before generating code: - Objects — the object name(s) you edited (for a scoped refresh), or none for a full rebuild. Names are case / "-quote / db.name insensitive and verified (a typo raises). - LLM config — only needed if rebuild_documentation will run; lineage + impact check are deterministic and need no model.

Emit the relevant pattern, substituting real values:

import tdfs4ds                                  # reads the TDFS4DS_* settings of .env
tdfs4ds.reconnect_teradata(raise_error=True)    # teradataml context from TDFS4DS_TD_HOST / _USERNAME / _PASSWORD
tdfs4ds.connect(database='<DATABASE>', create_if_missing=True)
import teradataml as tdml
tdfs4ds.select_data_domain('<DATA_DOMAIN>')   # or set TDFS4DS_DATA_DOMAIN in .env

# ---------------------------------------------------------------------------
# 1. Full rebuild / init  — re-derive the whole graph from every registered
#    process view + dataset (all data domains). Diff-based, not a wipe:
#    unchanged edges are left alone, new ones inserted, vanished ones closed,
#    and edges of objects that no longer exist pruned.
# ---------------------------------------------------------------------------
n_changes = tdfs4ds.rebuild_lineage_graph()        # all_data_domains=True
print(f"{n_changes} edge changes written")         # changes, not edges: 0 means the graph was up to date

# ---------------------------------------------------------------------------
# 2. Scoped refresh  — you edited a (possibly NON-process) view. Refresh only
#    its edges (no global wipe) and check whether downstream processes still
#    compile.  Names are verified; a typo raises ValueError.
# ---------------------------------------------------------------------------
tdfs4ds.rebuild_lineage_graph(objects=['<view_you_changed>'], check=True)

# Standalone impact check (no graph write): run EXPLAIN SELECT * on every
# registered process downstream of the change — verifies the query still
# COMPILES (a changed view's result columns can silently break consumers).
res = tdfs4ds.check_downstream_processes(['<view_you_changed>'])
print("checked:", res['checked'], "| ok:", len(res['ok']), "| broken:", len(res['broken']))
for b in res['broken']:
    print("  BROKEN:", b['view'], "->", b['error'])   # fix these processes

# ---------------------------------------------------------------------------
# 3. Query the persisted graph in-memory (networkx — one table read, no SHOW VIEW)
# ---------------------------------------------------------------------------
from tdfs4ds.lineage import get_descendants, get_ancestors, get_persisted_graph

get_descendants('<DB>', '<OBJECT>')   # impact: everything that depends on it
get_ancestors('<DB>', '<OBJECT>')     # upstream sources it depends on

# ---------------------------------------------------------------------------
# 4. Re-document from the persisted graph (needs an instruct model configured)
# ---------------------------------------------------------------------------
# Whole store, each process/dataset documented exactly once:
tdfs4ds.genai.rebuild_documentation()                       # force_update=False
# Only the impact slice of an edited object (object + all downstream), force-regenerated:
tdfs4ds.genai.rebuild_documentation(objects=['<view_you_changed>'])

# ---------------------------------------------------------------------------
# 5. Interactive pyvis visualisation (writes a self-contained HTML file)
# ---------------------------------------------------------------------------
from tdfs4ds.lineage import plot_lineage_pyvis

plot_lineage_pyvis(get_persisted_graph(), output_path='lineage.html')                 # whole graph
plot_lineage_pyvis(get_persisted_graph(seed='<DB>.<OBJECT>'), output_path='impact.html')  # neighbourhood

Impact before a change (impact_of)

Always tell the user: These checks are not exhaustive and can report false positives: have an expert review the findings. They support experts, they do not replace them. A finding is a lead to investigate, not a verdict. The study is read from the SQL and the catalogs: estimates are not measurements, and readers outside the store are not seen. The absence of a finding is not proof that nothing is affected. Repeat this when you present an impact study.

check_downstream_processes runs after the edit. To study the impact before it, use tdfs4ds.impact_of: read only (SELECT / HELP / SHOW / EXPLAIN and a prepare-only description of the proposed SQL; nothing is created, altered or run).

import tdfs4ds

# Who reads it? (process id, process view, dataset, plain view or source table; db.name accepted)
tdfs4ds.impact_of('MY_DB.MY_PROCESS_VIEW')

# What would this new SELECT break? Columns, types, logic, managers and source tables are compared with the current ones.
m = tdfs4ds.impact_of('MY_DB.MY_PROCESS_VIEW', new_sql="""SELECT ... FROM ...""")

# What would this dataset change break?
m = tdfs4ds.impact_of('MY_DB.MY_DATASET', dataset_change={'remove_features': ['<FEATURE>']})

m['verdicts']       # [{'object', 'kind', 'verdict', 'reason'}]: breaks / values_change / unaffected / not_verifiable
m['unverified']     # what could not be read, with the command that fixes it
for step in m['after']:
    print(step['n'], step['when'], step['call'])    # ordered follow-up calls, text only

Rules:

  • breaks: reads a removed column or feature, or the new SQL does not compile. values_change: reads a column whose type or computation changes, or the logic changed (a lost predicate, another grain). not_verifiable: no right, SQL unreadable, or no lineage. depends: no change was described.
  • An empty lineage graph, or an object missing from it, is reported under unverified with the rebuild_lineage_graph(...) command to run. It is never read as "nothing depends on it".
  • after lists the calls to make once the change is applied (lineage refresh and compile check, documentation, plan_type_change first when a type no longer fits, recompute from the first date when values change, sanity_check). Read it, then run what applies.
  • Readers outside the feature store are invisible unless their view is attached (attach_objects). Column-level reasoning exists only for columns that pass through by name.

The feature-level reading and the plan comparison come with the same call:

m = tdfs4ds.impact_of('MY_DB.MY_PROCESS_VIEW', new_sql="""SELECT ... FROM ...""")
m['features']      # one entry per edited feature: state, severity, evidence, readers, chain
m['dependents']    # one entry per reader: severity, narrowed, affected and unaffected features
m['efficiency']    # EXPLAIN comparison of the two SELECTs: faster / same / slower / not_comparable

features=False and efficiency=False leave one of these readings out. Severities are breaks, values_change, may_change and unaffected; a reader the reading cannot narrow is may_change at least. Nothing is run: the plans are EXPLAIN only. A measured comparison (both SELECTs computed on volatile tables, nothing stored, opt-in) is started by a person from the Impact study panel, or with run_study(..., measure=True) from tdfs4ds.impact_agent. write_impact_report(model, fmt='html') (in tdfs4ds.impact_report) writes the study as HTML, Markdown or CSV.

What each function does

Call Effect
rebuild_lineage_graph() Re-derive the whole graph from every process view + dataset (diff-based: no wipe, stale parents pruned).
rebuild_lineage_graph(objects=[...], check=True) Refresh only those objects' edges (no wipe) + run the downstream compile check.
check_downstream_processes([...]) EXPLAIN SELECT * on every registered process downstream → {checked, ok, broken:[{view,process_id,error}], not_verifiable:[...]}. A refusal for lack of a right ("does not have SELECT access to ...") goes to not_verifiable, never to broken (0.3.4.5): the view may be fine, this user cannot check it.
impact_of(objects, new_sql=, dataset_change=) Before the edit: readers by kind, a verdict per reader, the feature-level reading (features, dependents), the EXPLAIN comparison (efficiency), what could not be verified, and the ordered follow-up calls. Read only.
get_descendants(db, obj) / get_ancestors(db, obj) In-memory impact / upstream sets (one table read).
rebuild_documentation() / rebuild_documentation(objects=[...]) Document the whole store, or only the impact slice of edited objects (force-regenerated).
plot_lineage_pyvis(graph, output_path=...) Interactive HTML network (datasets chocolate, views steelblue, tables seagreen).

Rules

  • Edges are parent → child = parent depends on child. get_descendants is the impact direction (what breaks if this changes); get_ancestors is the sources direction.
  • Object names are normalised (quotes stripped, upper-cased, db.name split) and verified against the persisted graph then DBC.TablesV. An unrecognised name raises ValueError — never a silent no-op.
  • A view that must stay in the graph (for instance a user view joining a dataset with a source table, read by no process) is attached: tdfs4ds.attach_objects(['DB.VIEW']) (0.3.5.2). Its edges are recorded at once and every full rebuild_lineage_graph() seeds it. Prefer it to extra_views=, which a later full rebuild without that argument does not keep. An attached table read by no view has no edge. Removing a dataset or process an attached view reads is refused; the removal plan detaches the view and never drops it.
  • The graph is created when missing by setup() / connect(create_if_missing=True); run rebuild_lineage_graph() once to populate it on a pre-existing store.
  • SQL words recorded as objects before 0.3.6.13 (CAST, POSITION, APPLY, 1) are closed the next time the view reading them is recorded; rebuild_lineage_graph() does it for the whole store.
  • rebuild_documentation needs tdfs4ds.INSTRUCT_MODEL_PROVIDER + ..._MODEL set; lineage refresh and check_downstream_processes are deterministic and need no model.
  • tdstone2 TDS_* objects (scoring views, model/code repositories) are legitimate upstream nodes and appear in the graph — they are not feature-store internals.