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.
_PREV_SHAPE
module-attribute
¶
_PREV_SHAPE = re.compile('COALESCE\\s*\\(\\s*MAX\\s*\\(\\s*h\\.BUSINESS_DATE\\s*\\)', re.IGNORECASE)
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).
base_name
¶
The manager view a previous view belongs to (DB.X_PREVIOUS -> DB.X), or None.
The case and qualification of name are kept.
unbounded_literal
¶
The smallest value of the calendar's type as a SQL literal.
date_literal
¶
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
¶
The REPLACE VIEW of <view>_PREVIOUS (pure; first_literal is a SQL literal).
is_previous_ddl
¶
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.
parse_setting
¶
{enabled, first_previous} from a stored PREVIOUS setting, or None.