tdfs4ds.upgrade¶
tdfs4ds.upgrade
¶
tdfs4ds.upgrade_store(): the one-off steps a store owes after a release (0.3.7.37).
Some releases add something an existing store has to do ONCE: backfill the new dataset column rows (0.3.7.35), redefine statistics kept with old options (0.3.7.36). A user who skips a release does not know which steps are still owed. This module lists them, with the evidence, and applies them in order.
The module is not named like the function: a submodule called upgrade_store would be shadowed by it.
Two rules:
- Detection is cheap and honest. A few batched reads, never one per object. A check that cannot be
read is
unknownwith the reason, neverdone. - A dry run writes nothing. The
detect_*functions only read; theapply_*functions are the only writers andupgrade_storecalls them solely withdry_run=False. A source guard test checks it.
A release adds a step by adding ONE entry to :data:UPGRADE_STEPS.
UPGRADE_STEPS
module-attribute
¶
UPGRADE_STEPS = (UpgradeStep('dataset_columns', '0.3.7.35', 'datasets registered before 0.3.7.35 have no column rows (FS_<name>_COLUMNS), so their view cannot be rebuilt from the catalog', 'tdfs4ds.restore_dataset_catalog(dry_run=False)', detect_dataset_columns, apply_dataset_columns, _quick_dataset_columns), UpgradeStep('lineage_graph', '0.3.1.84', 'processes registered before the persisted lineage graph existed have no edge in FS_LINEAGE_GRAPH (impact studies and the upstream guard then rebuild it in memory on every call)', 'tdfs4ds.rebuild_lineage_graph()', detect_lineage_graph, apply_lineage_graph, _quick_lineage_graph), UpgradeStep('statistics_missing', '0.3.1.217', 'storage tables lack statistics ingestion expects (the optimizer estimates a lookup badly without them)', 'tdfs4ds.check_storage_statistics(add_missing=True)', detect_statistics_missing, apply_statistics_missing), UpgradeStep('statistics_options', '0.3.7.36', 'statistics defined by older releases keep their stored sample and threshold options until redefined', 'tdfs4ds.check_storage_statistics(fix_options=True)', detect_statistics_options, apply_statistics_options), UpgradeStep('follow_up_primary_index', '0.3.8.4', 'FS_FOLLOW_UP is created with PRIMARY INDEX (RUN_ID, PROCESS_ID) while every reader filters on PROCESS_ID (opt-in: tdfs4ds.UPGRADE_FOLLOW_UP_PRIMARY_INDEX = True; the old table stays as _OLD until a second call)', "tdfs4ds.upgrade_store(dry_run=False, steps='follow_up_primary_index')", detect_follow_up_primary_index, apply_follow_up_primary_index))
UpgradeStep
dataclass
¶
One one-off step. quick is an optional SQL expression returning a number (> 0 = pending): the
cheap test connect() batches into ONE statement; a step without it is only found by upgrade_store().
__init__
¶
__init__(id: str, since: str, why: str, call: str, detect: Callable[[dict], dict], apply: Callable[[dict], str], quick: Optional[Callable[[], str]] = None) -> None
qualified
¶
Build db.obj with each part quoted only as needed.
qualified('TDB', 'FS_X') == 'TDB.FS_X' (unchanged for ordinary names);
qualified('SVC@CORP', 'FS_X') == '"SVC@CORP".FS_X'. An empty/None
database yields the bare object name, so unqualified callers keep working.
force=True quotes both parts unconditionally — only for the sites that
have always emitted quotes and whose exact text is already persisted (dataset
view DDL, returned volatile-table names).
sql_literal
¶
Escape value for use inside a single-quoted SQL string literal.
For the DBC probes and catalog predicates that compare a name as data
(WHERE DatabaseName = '…'). The caller supplies the surrounding quotes.
_rows
¶
The rows of a SELECT (raw execute_sql: no teradataml DataFrame, so no metadata reads).
_catalog_names
¶
(catalog view, columns view, process view, lineage view) of the primary store, qualified.
detect_dataset_columns
¶
Datasets whose view still exists but that have no FS_<name>_COLUMNS row (read: 3 statements).
detect_lineage_graph
¶
Processes are registered but the persisted lineage graph is empty (read: 2 statements).
_statistics_frame
¶
The storage statistics review, read once per call (flags off: the data dictionary is only read).
detect_statistics_options
¶
Storage tables whose statistics carry options older than ingestion's (read: 4 DBC reads).
detect_statistics_missing
¶
Storage tables with expected statistics not defined (shares the read of statistics_options).
detect_follow_up_primary_index
¶
The follow-up table's primary index is not exactly PROCESS_ID (DBC reads only). Applied on opt-in only.
upgrade_store
¶
List, and optionally apply, the one-off upgrade steps the connected primary store still owes.
Parameters¶
dry_run : bool
True (default) only reads: each step is reported pending, done or unknown with the
evidence and the call that would run. False applies the pending steps in registry order.
steps : str or list of str, optional
Restrict to these step ids (see :data:UPGRADE_STEPS). Default: all.
display : bool
Print the report.
Returns¶
dict
{'dry_run', 'pending', 'steps': [{id, since, why, call, state, evidence, detail, items, outcome}]}.
state is pending / done / unknown; an unreadable check is unknown with the
reason in detail and is never applied. outcome is what the call did (would run on a dry
run, applied: ..., FAILED: ..., or why it was left).
quick_pending
¶
Ids of the steps found pending by ONE statement (the steps with a quick test); None when
it could not be read. Reads only.
connect_note
¶
What connect() calls: at most one INFO line, one statement, never raises.