Skip to content

tdfs4ds.utils.previous_view

tdfs4ds.utils.previous_view

The previous-date view of a TimeManager (0.3.7.31). Pure: no database, no teradataml.

<manager>_PREVIOUS is an opt-in extra view returning the business date BEFORE the one the manager exposes, computed from the manager's own view, so it follows update(), roll_out, point_time_manager_view and the literal swap of run(at=) with no change to them::

REPLACE VIEW DB.X_PREVIOUS AS
SELECT COALESCE(MAX(h.BUSINESS_DATE), <first_previous>) AS BUSINESS_DATE
FROM DB.X_HIDDEN h
WHERE h.BUSINESS_DATE < (SELECT BUSINESS_DATE FROM DB.X)

A single-row aggregate without GROUP BY: it always returns one row. For the first step there is no earlier stored date, so first_previous (a literal in the table's own type) is returned. A process window is d > (SELECT BUSINESS_DATE FROM X_PREVIOUS) AND d <= (SELECT BUSINESS_DATE FROM X), i.e. (previous, current]. On a day-partitioned source the two scalars are parameters: the static EXPLAIN shows an all-rows scan (as with one scalar); DYNAMIC EXPLAIN with the query band DynamicPlan=SYSTEMX shows the partitions read.

VARCHAR calendars compare as text, which is right only for ISO text (YYYY-MM-DD); the literals written here are ISO.

SUFFIX module-attribute

SUFFIX = '_PREVIOUS'

UNBOUNDED module-attribute

UNBOUNDED = 'unbounded'

SETTING module-attribute

SETTING = 'PREVIOUS'

_PREV_SHAPE module-attribute

_PREV_SHAPE = compile('COALESCE\\s*\\(\\s*MAX\\s*\\(\\s*h\\.BUSINESS_DATE\\s*\\)', IGNORECASE)

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

previous_name

previous_name(view: str) -> str

Name of the previous view of manager view view.

is_previous_name

is_previous_name(name) -> bool

base_name

base_name(name) -> Optional[str]

The manager view a previous view belongs to (DB.X_PREVIOUS -> DB.X), or None. The case and qualification of name are kept.

_kind

_kind(type_text) -> str

_zoned

_zoned(type_text) -> bool

unbounded_literal

unbounded_literal(type_text) -> str

The smallest value of the calendar's type as a SQL literal.

date_literal

date_literal(value, type_text, offset: Optional[str] = None) -> str

value (date / datetime / Timestamp / ISO string) as a literal of the calendar's type.

DATE: the date part (a time of day is refused). Text: ISO YYYY-MM-DD (with HH:MM:SS when the value has a time). Timestamp: CAST(TIMESTAMP '...' AS type); on a WITH TIME ZONE type a value without a zone takes offset (the offset the calendar's dates share), else +00:00, never the session's zone.

previous_view_sql

previous_view_sql(view_db, view, table_db, table, first_literal: str) -> str

The REPLACE VIEW of <view>_PREVIOUS (pure; first_literal is a SQL literal).

is_previous_ddl

is_previous_ddl(ddl, view_db, view, table_db, table) -> bool

Whether ddl is the previous view of manager view_db.view over table_db.table (the shape above; reads exactly those two objects). Pure. Lets a re-run be idempotent.

setting_value

setting_value(first_previous: str) -> str

parse_setting

parse_setting(value) -> Optional[dict]

{enabled, first_previous} from a stored PREVIOUS setting, or None.