tdfs4ds.impact_features¶
tdfs4ds.impact_features
¶
Feature-level impact of a change: which features of which readers, and the chain.
:func:tdfs4ds.impact.impact_of judges each downstream object as a whole. This module adds,
to the same model, the reading at feature level:
features- one entry per feature (or column) of the edited object, with itsstate(unchanged / logic_changed / type_changed / removed / added / unknown), itsseverity(breaks > values_change > may_change > unaffected) and itsreaders: for each object that reads it, which of the reader's own features or columns are affected and which are not;feature_edges- the feature-to-feature chain (a feature, then the dataset column or the reader feature computed from it, then the next reader...), each edge with its reason;severity_counts- the distinct features and columns of the study, by severity;schema_version= 2.
How a reader is narrowed:
- a dataset reads features by FEATURE_ID: exactly the columns of the features concerned are affected, with the consequence of its join (INNER: rows lost, FULL OUTER: the column becomes NULL);
- a process, a view or an attached view: its SQL is split into output items; only the items whose
expression names a changed column (or pass it through, :func:
sql_context.column_lineage) are affected.SELECT *, a changed column named in its FROM / WHERE / JOIN, or a select list that cannot be split is CONSERVATIVE (narrowed=False, severity at leastmay_change); - an affected feature of a reader process seeds the next round, up to
max_depth(default 6), with a cycle guard.
PURE: no database read, no write, no language model. Everything comes from the inputs that
:func:tdfs4ds.impact.collect_impact_inputs already read (lineage graph, view texts, catalogs).
STATES
module-attribute
¶
TYPE_NOTE
module-attribute
¶
TYPE_NOTE = 'type changed: values identical, readers that cast or compare this column should be checked'
PARSE_LIMIT_NOTE
module-attribute
¶
_BUILTINS
module-attribute
¶
_BUILTINS = frozenset({'cast', 'trim', 'extract', 'substr', 'substring', 'coalesce', 'nullif', 'case', 'count', 'sum', 'min', 'max', 'avg', 'over', 'in', 'exists', 'values', 'using', 'on', 'as'})
_KEYWORD_BEFORE_NAME
module-attribute
¶
_KEYWORD_BEFORE_NAME = re.compile('(?is)\\b(?:FROM|JOIN|INTO|TABLE|UPDATE|VIEW|TO|REFERENCES|ON)\\s*$')
_NAME_CALL
module-attribute
¶
_SIMPLE_CONSTRUCTS
module-attribute
¶
_SIMPLE_CONSTRUCTS = (('table operator call (EXECUTE FUNCTION)', re.compile('(?i)\\bEXECUTE\\s+FUNCTION\\b')), ('table operator TABLE(...)', re.compile('(?i)(?<![\\w$#.])TABLE\\s*\\(')), ('table operator input (HASH BY / DIMENSION)', re.compile('(?is)\\bON\\b.*\\b(?:HASH\\s+BY|DIMENSION)\\b')), ('SCRIPT(...)', re.compile('(?i)(?<![\\w$#.])SCRIPT\\s*\\(')), ('APPLY(...)', re.compile('(?i)(?<![\\w$#.])APPLY\\s*\\(')), ('PIVOT / UNPIVOT', re.compile('(?i)\\b(?:UN)?PIVOT\\s*\\(')), ('JSON_TABLE', re.compile('(?i)\\bJSON_TABLE\\b')), ('JSON function (shredding)', re.compile('(?i)(?<![\\w$#.])JSON_(?!TABLE\\b)[A-Z_]+\\s*\\(')), ('XML function', re.compile('(?i)\\b(?:XMLTABLE|XMLQUERY|XMLEXTRACT|XMLPUBLISH|XMLAGG|XMLELEMENT|EXTRACTVALUE)\\b')), ('WITH RECURSIVE', re.compile('(?i)\\bWITH\\s+RECURSIVE\\b')), ('dynamic SQL', re.compile('(?i)\\bEXECUTE\\s+IMMEDIATE\\b|\\bSYSEXECSQL\\b|\\bDBC\\.SYSEXECSQL\\b')), ('macro or procedure call', re.compile('(?i)^\\s*(?:CALL|EXEC|EXECUTE)\\s+(?!FUNCTION\\b|IMMEDIATE\\b)[A-Za-z_\\"]|(?<=;)\\s*(?:CALL|EXEC)\\s+[A-Za-z_\\"]')), ('TD_ analytic function', re.compile('(?i)(?<![\\w$#.])TD_[A-Z0-9_]+\\s*\\(')))
_feature_nodes_of
¶
{NAME: attrs} of the features process pid produces (dependency graph).
_declared
¶
The declared checks of a feature, as short texts (empty when none).
_seeds
¶
The feature entries of every target, with the node and column they start from.
_judge
¶
(record, {item: info}) for reader r and the feature origin, or None when r does
not read anything coming from that feature.
add_feature_impact
¶
add_feature_impact(model: dict, inputs: dict, *, H=None, max_depth: int = DEFAULT_MAX_DEPTH) -> dict
Add schema_version, features, feature_edges and severity_counts to an
:func:tdfs4ds.impact.build_impact_model model (in place; the model is returned). No
existing key is changed, except that unverified gains the entries of the feature chain
(where it stops, and why). Pure.
_severity_counts
¶
The distinct items of the study by severity: the edited features and every reader feature or column reached. Pure.
_edited_phrase
¶
How an edited feature changes, as the end of 'X reads E, which ...'.
explain_dependent_feature
¶
explain_dependent_feature(name: str, sev: str, because: List[dict], unaffected: List[str], narrowed: bool = True, kind: Optional[str] = None) -> str
One plain-English sentence, written by code: why the feature name of a dependent is affected,
and which of the dependent's features are not. because: [{edited_feature, phrase,
measured}]. Pure.
by_dependent
¶
One entry per object depending on the edited object: which of its features may be affected, by
which edited feature, and which are not. Built from features / feature_edges. Pure.
Each entry: {object, kind, label, process_id | dataset_id, severity, narrowed, features: [{name,
severity, evidence, because: [{edited_feature, process_id, via, why}], explanation}],
unaffected_features}, the most severe first.
apply_measurement
¶
Apply a :func:tdfs4ds.impact_measure.measure result to an impact model (in place; the model
is returned). The measurement is kept as measure. When it ran (state done), every edited
feature it compared gets evidence: 'measured': a feature whose values differ keeps its severity
(raised to values_change when the SQL reading said less); a feature whose values are identical
goes from values_change / may_change to unaffected, and so do its readers and the edges
of its chain (the chain stops there). A feature measured identical whose state is type_changed
keeps that verdict for its values but gets type_note (:data:TYPE_NOTE): a reader that casts or
compares the column may still depend on its type; the dependents reading it list it in type_notes.
severity_counts and dependents are recomputed. The other features keep evidence:
'semantic'. Pure.
feature_readers
¶
The readers of one feature of a model built with features (pure).
feature_chain
¶
The edges of the chain that starts at one feature (pure).
_mask
¶
sql with comments and the content of string literals blanked (same length).
_enclosing_open
¶
Index of the unmatched ( before pos (-1 when at depth 0).
complex_constructs
¶
The constructs of sql that resist the parser, as short labels (empty when none). Pure.
Table operators and EXECUTE FUNCTION, TD_* analytic functions, table-operator inputs
(ON ... PARTITION BY / HASH BY / DIMENSION, TABLE(), SCRIPT( / APPLY(,
PIVOT / UNPIVOT, JSON and XML shredding, WITH RECURSIVE, dynamic SQL, macro and
procedure calls, QUALIFY over a derived column, and user-defined functions (a qualified
schema.name( call). Keywords inside string literals and comments are ignored.
study_texts
¶
Every SQL text of the study as (name, sql, kind, node): the current SQL of the edited objects
(kind target), the proposed SQL (proposed) and the SQL of every reader reached (reader). Pure.
parse_limits
¶
[{object, constructs, note}] for every SQL text of the study that holds constructs the
parser cannot follow: the proposed SQL, the edited objects and every reader reached. Pure.
add_parse_limits
¶
Set model["parse_limits"] (in place, never raises). Pure.