Skip to content

tdfs4ds.dataset.history_versions

tdfs4ds.dataset.history_versions

Which process versions computed the values of a history (0.3.3.12).

A feature's stored values all carry its process's PROCESS_ID, whatever SQL computed them. The SQL beneath a process changes over time: its process version, kept in FS_PROCESS_SQL. Since 0.3.7.34 versions are stamped in REAL time (the database's clock at the write), while values carry business time. The link goes through the run record in FS_FOLLOW_UP:

  • a value stored from a business date d: the latest COMPLETED run of the process with VALIDTIME_DATE = d; the version in force at that run's START_DATETIME computed it;
  • a real-time value (no dated run): the version in force at its ValidStart;
  • a store written before 0.3.7.34 (versions stamped at business dates): when no run matches, the version in force at ValidStart is used, which was the old rule;
  • a valid_time_column process records no per-load start date: its version is reported as None ("not determined"), never guessed.

An unchanged value is not rewritten by the MERGE, so a later run with new SQL that gives the same value leaves the older period: the rule names the latest run covering that date.

  • :func:version_segments (pure): version periods -> [{version, from, to}] over a window, with the time before the first version as None ("before versioning", never a guessed version).
  • :func:value_segments (pure): the same over business time, through the run record.
  • :func:history_versions: per feature of a dataset (or for process ids), the versions inside a window.
  • :func:history_with_versions: a companion view <view>_PV = the history plus a <feature>_PROCESS_VERSION column per feature. The dataset view itself is never changed (backward compatibility).

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

quote_ident

quote_ident(name, force=False)

Return name as a Teradata identifier, quoting it only if required.

Idempotent: an already-quoted name is returned unchanged rather than being wrapped a second time. Embedded quotes are escaped as "".

Parameters

name : str The raw object/database name. force : bool, default False Quote even when the name does not need it. Use only at the few sites that have always emitted unconditional quotes and whose exact output is already baked into persisted DDL (see feature_store/feature_query_retrieval.py) — elsewhere forcing would change the SQL of existing stores for no reason.

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.

_execute

_execute(sql)

version_periods_sql

version_periods_sql(process_ids) -> str

The valid-time periods of every version of the processes (one row each).

version_segments

version_segments(periods: list, start=None, end=None) -> list

[{"version", "from", "to"}] along valid time, for one process.

periods: dicts PROCESS_VERSION, VALIDSTART, VALIDEND. Adjacent periods of one version merge; the time before the first period is None (before versioning). Clipped to [start, end); from None = from the beginning, to None = still open.

_before

_before(a, b, inclusive: bool = False) -> bool

a < b (a <= b with inclusive) as UTC instants; None = unbounded, False.

value_segments

value_segments(periods: list, runs: list, start=None, end=None) -> list

[{"version", "from", "to"}] along business (value) time for one process. Pure.

periods: version periods (dicts PROCESS_VERSION, VALIDSTART, VALIDEND, real time); runs: follow-up rows {"VALIDTIME_DATE", "START_DATETIME", "STATUS"}. Each business date with a COMPLETED run starts a segment whose version is the one in force at that run's start; it lasts until the next dated run. Before the first dated run, and for a process with no dated run, the version periods are used as they are (real-time values, and stores written before 0.3.7.34). Clipped to [start, end).

_followup_runs

_followup_runs(process_ids) -> dict

{process_id: [{"VALIDTIME_DATE", "START_DATETIME", "STATUS"}]} from the primary store's follow-up table (one read). Fail-open: {} when unreadable.

_valid_time_column_processes

_valid_time_column_processes(process_ids) -> set

The processes that load with valid_time_column (their version is not determined). Fail-open: an unreadable setting counts as none.

_window_bounds

_window_bounds(window) -> tuple

(start, end) of a HistoryWindow, evaluated in the database now.

_dataset_spec

_dataset_spec(dataset: str)

history_versions

history_versions(dataset: Optional[str] = None, *, process_ids=None, start=None, end=None) -> dict

The process versions behind a history, per feature (or per process).

Parameters:

Name Type Description Default
dataset Optional[str]

a historical dataset view ('db.view'); its features and its window are read from its DDL.

None
process_ids

instead of a dataset, {label: process_id} or a list.

None
start, end

the window (default: the dataset's, else everything).

required

Returns {label: {"process_id", "segments": [{"version", "from", "to"}], "versions": [...], "note"}} over business time, through the run record (see the module docstring); a version None is "before versioning" (or "not determined" for a valid_time_column process, with a note).

describe_versions

describe_versions(versions: dict, fr: bool = False) -> list

One line per feature whose history spans several process versions.

history_with_versions

history_with_versions(dataset: str, view_name: Optional[str] = None, *, replace: bool = False, return_query: bool = False)

Create <view>_PV: the history plus <feature>_PROCESS_VERSION per feature.

Each period gets the version that computed it, derived in SQL like :func:~tdfs4ds.process_store.process_sql.value_version: the latest COMPLETED run of the process with VALIDTIME_DATE = the period's ValidStart gives a real start time, else the ValidStart itself (real-time values, and stores written before 0.3.7.34); the version in force at that instant is joined from FS_PROCESS_SQL (NULL before versioning). A valid_time_column process gets a NULL column (not determined), decided when the view is created. The follow-up is a plain table, so no temporal qualifier appears in the sub-queries. The dataset view is read as is and never changed.