Skip to content

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 unknown with the reason, never done.
  • A dry run writes nothing. The detect_* functions only read; the apply_* functions are the only writers and upgrade_store calls them solely with dry_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().

id instance-attribute

id: str

since instance-attribute

since: str

why instance-attribute

why: str

call instance-attribute

call: str

detect instance-attribute

detect: Callable[[dict], dict]

apply instance-attribute

apply: Callable[[dict], str]

quick class-attribute instance-attribute

quick: Optional[Callable[[], str]] = None

__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

qualified(database, object_name, force=False)

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

sql_literal(value)

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

_rows(sql: str) -> list

The rows of a SELECT (raw execute_sql: no teradataml DataFrame, so no metadata reads).

_err

_err(exc) -> str

_catalog_names

_catalog_names()

(catalog view, columns view, process view, lineage view) of the primary store, qualified.

_norm

_norm(x) -> str

_result

_result(state: str, evidence=None, detail: str = '', items=None) -> dict

detect_dataset_columns

detect_dataset_columns(ctx: dict) -> dict

Datasets whose view still exists but that have no FS_<name>_COLUMNS row (read: 3 statements).

detect_lineage_graph

detect_lineage_graph(ctx: dict) -> dict

Processes are registered but the persisted lineage graph is empty (read: 2 statements).

_statistics_frame

_statistics_frame(ctx: dict)

The storage statistics review, read once per call (flags off: the data dictionary is only read).

_statistics_tables

_statistics_tables(frame, statuses) -> List[str]

detect_statistics_options

detect_statistics_options(ctx: dict) -> dict

Storage tables whose statistics carry options older than ingestion's (read: 4 DBC reads).

detect_statistics_missing

detect_statistics_missing(ctx: dict) -> dict

Storage tables with expected statistics not defined (shares the read of statistics_options).

detect_follow_up_primary_index

detect_follow_up_primary_index(ctx: dict) -> dict

The follow-up table's primary index is not exactly PROCESS_ID (DBC reads only). Applied on opt-in only.

apply_dataset_columns

apply_dataset_columns(found: dict) -> str

apply_lineage_graph

apply_lineage_graph(found: dict) -> str

apply_statistics_options

apply_statistics_options(found: dict) -> str

apply_statistics_missing

apply_statistics_missing(found: dict) -> str

apply_follow_up_primary_index

apply_follow_up_primary_index(found: dict) -> str

_quick_dataset_columns

_quick_dataset_columns() -> str

_quick_lineage_graph

_quick_lineage_graph() -> str

_select

_select(steps) -> List[UpgradeStep]

upgrade_store

upgrade_store(dry_run: bool = True, *, steps=None, display: bool = True) -> dict

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).

_print

_print(out: dict) -> None

quick_pending

quick_pending() -> Optional[List[str]]

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

connect_note() -> Optional[List[str]]

What connect() calls: at most one INFO line, one statement, never raises.