tdfs4ds.utils.calendar_change¶
tdfs4ds.utils.calendar_change
¶
Change the calendar of a TimeManager in place (0.3.7.31).
TimeManager.change_calendar(calendar) replaces the dates of a table of dates by those of another
rule (monthly -> weekly) WITHOUT touching a process view, keeping the table, its name and its type.
The planning is pure (:func:plan_steps, :func:map_views, :func:data_request); the reads are
small fail-open functions of this module.
Write order (Teradata refuses DDL in a multi-statement request that holds DML, Error 3576; a
DELETE plus several INSERT in one request is one transaction):
- the PENDING record (setting
CALENDAR_CHANGEof the table: new rule, count, first and last date, and for each view its old date and new TIME_ID) is stored; - ONE data request:
DELETE FROM <table>; INSERT ... VALUES (1, d1); ...(all or nothing); - each cursor view is repointed in its own statement (
REPLACE VIEW ... WHERE TIME_ID = n); - the new rule is stored (setting
CALENDAR) and the pending record is deleted.
An interruption is recovered by calling change_calendar again with the same calendar: if the
pending record is there and the table already holds the dates it announced, the data request is
skipped and the views are repointed from the RECORDED old dates (they cannot be read from the new
table); otherwise everything is recomputed from the stored dates. Until the end the stored rule is
the old one, so calendar_off_rule_dates of the sanity check flags a half-finished change.
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.
_norm
¶
A comparable key: wall date for DATE, UTC naive instant for zoned values, naive as written.
plan_steps
¶
The dates of calendar from first_date to until ('now' = the database clock now),
limited to the steps already due. Pure; tz-aware in the rule's zone.
check_type
¶
Literals of steps in the table's type, or ValueError (a time of day on DATE, a type that cannot
hold the dates). Pure.
data_request
¶
The ONE data request: DELETE then one INSERT ... VALUES per step, TIME_ID 1..N.
map_views
¶
For each cursor view {view, database, time_id, literal}: its old date (the date of its TIME_ID in
old_rows), the new TIME_ID (the largest new step whose date is <= the old date, else 1) and its new
date. Pure.
data_already_written
¶
Whether a pending record says the data request of THIS change already ran: same rule and the table holds the announced first / last date and count. Pure.
cursor_views
¶
(cursor views, literal views, notes) among the views reading the table of tm: the managers
(managers, the registry's) plus the lineage predecessors of the table. A previous-date view is
computed and skipped; a view holding a literal date (an interrupted run(at=)) is returned apart;
another reader without cursor is noted.
processes_on
¶
[{process_id, view, time_view}] of the processes whose recorded TimeManager is one of managers.
Fail-open ([]).
running_processes
¶
The processes of pids with a RUNNING follow-up row; None when unreadable.
hard_copies
¶
Time managers elsewhere holding the same dates in ANOTHER table (they would not follow). Fail-open.
process_windows
¶
process_windows(processes: List[dict], managers: List[str], rule_step=None, rule_text=None) -> Tuple[List[dict], List[str]]
Classify the window of each process (window_shape.classify_chain over its live SQL chain).
Returns (rows for window_findings, unverifiable notes). Fail-open per process.
change_calendar
¶
change_calendar(tm, calendar, *, until='now', dry_run: bool = True, force: bool = False, gap_domains=()) -> Dict[str, Any]
See :meth:TimeManager.change_calendar. Returns {old_rule, new_rule, old_count, new_count,
first_date, last_date, views, gaps_dropped, review, agnostic, refused, estimate_seconds, replay,
statements, written, notes}; raises ValueError for a calendar the table cannot hold, and (when
not a dry run) when a guard refuses and force is False. The replay is never run.
_does_not_exist
¶
Teradata's "does not exist" refusal (Error 3807), matched on the phrase, never on a bare number.
missing_table_state
¶
The state of a TimeManager whose table of dates is gone (0.3.7.34, field report), or None when exc is another failure (then it stays a "not verified" note). Pure.
Nothing reads it (no process records one of its views, none is a domain clock): a leftover in the
manager registry, registry_orphan (info) with the call that removes the registry row. Something
reads it: calendar_table_missing (error), since those processes fail on their next run.
collect_calendar_states
¶
(states, window_rows, notes).
states: one dict per TABLE of dates of the store (managers of the registry, the process catalog and
the domain clocks, soft clones grouped by table, so each table is read once): {view, database,
table, views, state: calendar_state(...)}. window_rows: one per process with a recorded TimeManager,
ready for :func:tdfs4ds.lineage.window_shape.window_findings (the process's window classified against
the step of its manager's rule, stored or inferred). notes: what could not be read (unverifiable).