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_sqlthe output columns are compared with the current ones without creating anything; for adataset_changethe columns that disappear are listed. Each dependent gets a verdict:breaks/values_change/unaffected/not_verifiable(anddependswhen 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 anunverifiedentry, 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.
_DATASET_CHANGE_KEYS
module-attribute
¶
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
¶
_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
¶
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 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).
_mentions
¶
Whether the SQL text names the column name (word match, quotes ignored).
select_of
¶
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.
derive_type
¶
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.
probe_columns
¶
{"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
¶
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.
_lineage_nodes_for
¶
Lineage node ids that match db.obj (db may be None: unique bare match, the store's
own databases first).
resolve_targets
¶
(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.
downstream_of
¶
(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.
analyse_sql_change
¶
The change a proposed SELECT makes to a process view or a plain view. Pure.
_ddl_select
¶
The SELECT of a stored view text (SHOW VIEW returns a REPLACE VIEW).
analyse_dataset_change
¶
The change asked of a dataset. Pure. Raises ValueError for an unknown key or a
feature the dataset does not have.
_dependent_columns
¶
The target's output columns that disappear / change, upper-cased.
_global_effect
¶
A reason every reader's values may change, or None.
_verdicts
¶
Fill verdict / reason on every item (in place), nearest readers first.
build_impact_model
¶
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.
render_impact_html
¶
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.