Skip to content

tdfs4ds.impact

tdfs4ds.impact

What does a change break? Impact analysis before an edit (read only).

A data engineer is about to edit a process view, a plain view, a source table or a dataset. :func:impact_of answers, before anything is changed:

  • who reads the object - registered processes, datasets, attached views, plain views, TimeManager soft clones - from the persisted lineage graph AND from the dependency model (a dataset reads features by FEATURE_ID / FEATURE_VERSION, which lineage alone can miss);
  • what the change does to them - for a proposed new_sql the output columns are compared with the current ones without creating anything; for a dataset_change the columns that disappear are listed. Each dependent gets a verdict: breaks / values_change / unaffected / not_verifiable (and depends when no change was described);
  • what to run afterwards - an ordered list of calls (text, never executed).

Three layers, as in :mod:tdfs4ds.dependencies and the workflow assessment:

  • :func:collect_impact_inputs - the only I/O, fail-open: a failed read is an unverified entry, never "nothing depends on it";
  • :func:build_impact_model - pure;
  • :func:render_impact_text / :func:render_impact_html - pure.

READ ONLY. The module issues SELECT, HELP, SHOW and EXPLAIN, and prepares (never executes) the proposed SQL with the driver's prepare-only option. A source-level test forbids any statement that writes. No language model is involved.

BREAKS module-attribute

BREAKS = 'breaks'

VALUES_CHANGE module-attribute

VALUES_CHANGE = 'values_change'

UNAFFECTED module-attribute

UNAFFECTED = 'unaffected'

NOT_VERIFIABLE module-attribute

NOT_VERIFIABLE = 'not_verifiable'

DEPENDS module-attribute

DEPENDS = 'depends'

VERDICTS module-attribute

VERDICTS = (BREAKS, VALUES_CHANGE, UNAFFECTED, NOT_VERIFIABLE, DEPENDS)

_DATASET_CHANGE_KEYS module-attribute

_DATASET_CHANGE_KEYS = {'remove_features', 'add_features', 'join_type', 'time'}

LIMITS module-attribute

LIMITS = ['Lineage is object-level: who reads an object comes from the persisted lineage graph (tdfs4ds.rebuild_lineage_graph keeps it current) and from the dependency model.', "Column-level reasoning exists only for a column that passes through unchanged (matched by name in the reader's SQL); an expression is judged by the columns it names.", "A reader outside the feature store (a BI tool, a script, a user's own view) is invisible unless its view is attached (tdfs4ds.attach_objects).  DBQL readers are not listed.", 'The proposed SQL is prepared by the database, not executed: it is checked for compilation and its column list is read; its values and its performance are not measured.', "Text columns: the character set is not reported by the driver; lengths assume the session's byte width measured on a probe."]

_STAR_RE module-attribute

_STAR_RE = compile('(?is)\\bSELECT\\s+(?:DISTINCT\\s+)?(?:\\w+\\.)?\\*|,\\s*\\w+\\.\\*')

_VIEW_HEAD module-attribute

_VIEW_HEAD = compile('(?is)^\\s*(?:REPLACE|CREATE)\\s+VIEW\\s+[^\\s(]+\\s*(?:\\([^)]*\\))?\\s*AS\\s+')

_SELECT_START module-attribute

_SELECT_START = compile('(?is)^\\s*\\(?\\s*(SELECT|SEL|WITH|LOCKING|LOCK|CURRENT\\s+VALIDTIME|SEQUENCED\\s+VALIDTIME|NONSEQUENCED\\s+VALIDTIME|VALIDTIME|NONTEMPORAL)\\b')

_LOGIC_KINDS module-attribute

_LOGIC_KINDS = {'dropped_predicate', 'added_predicate', 'join_kind_changed', 'group_by_changed', 'partition_by_changed', 'dropped_distinct', 'dropped_qualify', 'set_op_changed', 'dropped_table', 'added_table'}

logger_safe

logger_safe(level, message, *args, **kwargs)

Wrapper around the global logger that only emits logs when tdfs4ds.DISPLAY_LOGS is True. level is a string like "info", "error", etc.

split_qualified

split_qualified(name)

Split db.obj into (database, object), both de-quoted.

Quote-aware, so a dot inside a quoted part does not split the name: split_qualified('"DEINF.CARLOSN"."FS_X"') == ('DEINF.CARLOSN', 'FS_X'). The naive rsplit('.', 1) this replaces returns ('"DEINF.CARLOSN"', '"FS_X"') only by luck and ('"DEINF', 'CARLOSN"."FS_X"') in the split('.') variant.

An unqualified name returns ('', name).

_u

_u(v) -> str

_clean

_clean(v) -> Optional[str]

_ascii

_ascii(text) -> str

_err

_err(exc) -> str

_node

_node(name) -> str

'DB.OBJECT' as the persisted lineage graph spells it.

_entity_list

_entity_list(entity) -> List[str]

_names

_names(csv) -> List[str]

_mentions

_mentions(text: str, name: str) -> bool

Whether the SQL text names the column name (word match, quotes ignored).

_selects_star

_selects_star(text: str) -> bool

select_of

select_of(sql: str) -> str

The SELECT of a proposed SQL: a REPLACE VIEW x AS header and a trailing ; are dropped. Raises ValueError for anything that is not one SELECT (this module never sends a statement that writes). Pure.

_py_type

_py_type(c: dict) -> str

derive_type

derive_type(col: dict, text_factor: int = 3) -> str

A SQL type text from a driver description entry {pytype, size, precision, scale}. Lossy by construction (a CHAR is a VARCHAR, the character set is unknown). Pure.

_signature

_signature(col: dict) -> tuple

probe_columns

probe_columns(sql: str, *, execute=None) -> dict

{"ok", "columns": [{name, pytype, size, precision, scale}], "error"} for a SELECT, without executing it: the driver's prepare-only option ({fn teradata_rpo(S)}) asks the database to parse and describe the statement. Never raises.

text_width_factor

text_width_factor(*, execute=None) -> int

Bytes the driver reports per character of a VARCHAR on this session (1 or 3, measured on a prepare-only probe). Defaults to 3 when it cannot be measured.

_candidates

_candidates(H, G, inputs) -> List[str]

_lineage_nodes_for

_lineage_nodes_for(G, existing, db, obj) -> List[str]

Lineage node ids that match db.obj (db may be None: unique bare match, the store's own databases first).

resolve_targets

resolve_targets(inputs: dict, H, objects) -> Tuple[List[dict], List[dict]]

(targets, unresolved). Each target is a dict with kind (process / dataset / view / table / attached view / attached table / manager / object), node (lineage node id) and, for a process, pid, view, domain, features, entity, row. Pure.

_maps

_maps(H) -> Tuple[Dict[str, str], Dict[str, str]]

downstream_of

downstream_of(inputs: dict, H, targets: List[dict]) -> Tuple[Dict[str, dict], List[dict]]

(items, unverified): every object that reads the targets, keyed by an identity (P:<pid> / D:<id> / A:<node> / the lineage node). Each item: kind (process / dataset / attached view / view / manager / table), label, node, distance, via (lineage / dependency model), reads (targets it reads). Pure.

_empty_change

_empty_change(mode: str) -> dict

_manager_names

_manager_names(inputs) -> Dict[str, str]

_managers_in

_managers_in(text: str, names: Dict[str, str]) -> Dict[str, str]

_columns_by_name

_columns_by_name(cols: List[dict]) -> Dict[str, dict]

analyse_sql_change

analyse_sql_change(target: dict, inputs: dict, new_sql: str) -> dict

The change a proposed SELECT makes to a process view or a plain view. Pure.

_ddl_select

_ddl_select(ddl: str) -> str

The SELECT of a stored view text (SHOW VIEW returns a REPLACE VIEW).

analyse_dataset_change

analyse_dataset_change(target: dict, inputs: dict, H, change: dict) -> dict

The change asked of a dataset. Pure. Raises ValueError for an unknown key or a feature the dataset does not have.

_dependent_columns

_dependent_columns(target: dict, change: dict) -> Dict[str, set]

The target's output columns that disappear / change, upper-cased.

_global_effect

_global_effect(change: dict) -> Optional[str]

A reason every reader's values may change, or None.

_verdicts

_verdicts(inputs: dict, H, targets, items, change, eff_cols, glob) -> None

Fill verdict / reason on every item (in place), nearest readers first.

_process_features

_process_features(inputs, pid) -> List[str]

_after

_after(targets, items, change, target_verdict, inputs) -> List[dict]

_row

_row(inputs, pid) -> dict

build_impact_model

build_impact_model(inputs: dict) -> dict

The impact model from :func:collect_impact_inputs. Pure. Raises ValueError for an object name that resolves to nothing (with the close matches) and for bad arguments.

collect_impact_inputs

collect_impact_inputs(objects, *, new_sql=None, dataset_change=None, as_of=None, max_ddl: int = 150, emit=None) -> dict

Everything the pure layer needs. The only I/O: SELECT / HELP / SHOW / EXPLAIN and the driver's prepare-only option. Fail-open: a failed read is an unverified entry.

_manager_index

_manager_index()

_explain

_explain(sql: str) -> dict

render_impact_text

render_impact_text(model: dict) -> str

The model as plain ASCII text.

render_impact_html

render_impact_html(model: dict) -> str

The model as a self-contained HTML fragment (escaped, no script).

impact_of

impact_of(objects, *, new_sql: Optional[str] = None, dataset_change: Optional[dict] = None, display: bool = True, as_of=None) -> dict

Study the impact of a change on a process, a view, a source table or a dataset, before making it.

Read only: SELECT / HELP / SHOW / EXPLAIN and a prepare-only description of new_sql; nothing is created, altered or run.

Parameters

objects : str | list of str A PROCESS_ID, a process view, a dataset, a plain view or a source table; db.name accepted. new_sql : str, optional The proposed SELECT of ONE process view or view (REPLACE VIEW x AS header allowed). The output columns are compared with the current ones and every reader gets a verdict. dataset_change : dict, optional The change of ONE dataset: {"remove_features": [names or columns], "add_features": [names], "join_type": "INNER" | "FULL OUTER", "time": "current" | <anything else>}. as_of : optional Read the catalogs and the lineage graph at that valid time (the SQL read is today's).

Returns

dict targets, change, target_verdict, downstream (grouped by kind), verdicts (breaks / values_change / unaffected / not_verifiable, depends when no change was described), counts, after (ordered calls, text only), unverified, limits.

Raises ValueError for a name that resolves to nothing (with the close matches) and for bad arguments.