Skip to content

tdfs4ds.dataset.catalog_columns

tdfs4ds.dataset.catalog_columns

The dataset catalog holds everything needed to rebuild a dataset view (0.3.7.35). Pure: no database.

The view's text is what Teradata executes, but a lost view (DROP VIEW, a store restored without its views) could not be recreated from the catalog: FS_<name>_FEATURES knows a feature's id, type and storage, not the process version that produced it, the column alias, the join columns of a coarser feature nor the order of the columns. They live in an optional table FS_<name>_COLUMNS (one row per output column of the view: the entity columns and the feature columns, in the view's order), written by add_dataset next to the build table (strategy, join type, temporal mode), the window table (history) and the offsets table (lags and leads).

column_rows turns the specs the builders hold into those rows; spec_from_catalog reads them back into a DatasetSpec that render_dataset_ddl renders to the same text as the view (byte for byte). A dataset registered before 0.3.7.35 has no such rows: CatalogIncomplete says what is missing and how to fill it (restore_dataset_catalog(dry_run=False) while the view still exists).

MULTIJOIN module-attribute

MULTIJOIN = 'MULTIJOIN'

GROUPED module-attribute

GROUPED = 'GROUPED'

CURRENT module-attribute

CURRENT = 'CURRENT'

AS_OF module-attribute

AS_OF = 'AS_OF'

TIME_MANAGER module-attribute

TIME_MANAGER = 'TIME_MANAGER'

HISTORY module-attribute

HISTORY = 'HISTORY'

ENTITY module-attribute

ENTITY = 'ENTITY'

FEATURE module-attribute

FEATURE = 'FEATURE'

COLUMN_FIELDS module-attribute

COLUMN_FIELDS = ('COLUMN_ORDER', 'COLUMN_KIND', 'COLUMN_NAME', 'FEATURE_NAME', 'FEATURE_ID', 'FEATURE_VERSION', 'FEATURE_TABLE', 'DATA_DOMAIN', 'ENTITY_KEY', 'LEVEL_COLUMNS', 'STORAGE_ENTITY', 'LEFT_OUT', 'VERSION_LIST')

DERIVABLE_FIELDS module-attribute

DERIVABLE_FIELDS = ('COLUMN_ORDER', 'COLUMN_KIND', 'COLUMN_NAME', 'FEATURE_ID', 'FEATURE_VERSION', 'FEATURE_TABLE', 'LEVEL_COLUMNS')

_LITERAL_RE module-attribute

_LITERAL_RE = re.compile('\\d{4}-\\d{2}-\\d{2} \\d{2}:\\d{2}:\\d{2}(?:\\.\\d+)?(?:[+-]\\d{2}:\\d{2})?')

_FIX module-attribute

_FIX = 'restore_dataset_catalog(dry_run=False) records it while the view still exists; a dataset whose view is already gone and was registered before 0.3.7.35 must be rebuilt with build_dataset'

DatasetSpec

Everything needed to (re)generate a dataset view.

entity instance-attribute

entity = list(entity)

partial instance-attribute

partial = partial

features instance-attribute

features = list(features)

join_type instance-attribute

join_type = join_type

strategy instance-attribute

strategy = strategy

time instance-attribute

time = time if time is not None else DatasetTime(CURRENT)

schema_name instance-attribute

schema_name = schema_name

view_name instance-attribute

view_name = view_name

offset_strategy instance-attribute

offset_strategy = offset_strategy or PIVOT

grouped property

grouped

has_offsets property

has_offsets

__init__

__init__(entity, features, join_type='INNER', strategy=MULTIJOIN, time=None, schema_name=None, view_name=None, offset_strategy=None, partial=False)

__repr__

__repr__()

FeatureSpec

One feature column of a dataset view.

__slots__ class-attribute instance-attribute

__slots__ = ('table', 'feature_id', 'version', 'alias', 'from_version_list', 'offset', 'base_name', 'storage_entity', 'left_out', 'grain_checked', 'level')

table instance-attribute

table = table

feature_id instance-attribute

feature_id = int(feature_id)

version instance-attribute

version = version

alias instance-attribute

alias = alias

from_version_list instance-attribute

from_version_list = from_version_list

offset instance-attribute

offset = offset

base_name instance-attribute

base_name = base_name

storage_entity instance-attribute

storage_entity = storage_entity

left_out instance-attribute

left_out = list(left_out or ())

grain_checked instance-attribute

grain_checked = False

level instance-attribute

level = list(level) if level else None

__init__

__init__(table, feature_id, version, alias, from_version_list=False, offset=None, base_name=None, storage_entity=None, left_out=(), level=None)

key

key()

__eq__

__eq__(other)

__repr__

__repr__()

DatasetTime

The resolved temporal mode of one dataset view.

Holds what the SQL needs (outer_qualifier, sub_qualifier) and what the catalog records (mode, as_of, the TimeManager's location).

mode instance-attribute

mode = mode

as_of instance-attribute

as_of = as_of

tm_database instance-attribute

tm_database = tm_database

tm_view instance-attribute

tm_view = tm_view

tm_table instance-attribute

tm_table = tm_table

window instance-attribute

window = window

tm_view_sql property

tm_view_sql

outer_qualifier property

outer_qualifier: str

sub_qualifier property

sub_qualifier: str

business_date_sql property

business_date_sql: str

The manager's business date as a scalar sub-query (TIME_MANAGER only).

period_predicate property

period_predicate: str

Leading WHERE conjuncts selecting the valid instant, or ''.

Only the TIME_MANAGER mode needs one (see the module docstring for why it is not an AS OF sub-query); for the other modes the qualifier alone selects the instant, and the SQL is byte-identical to before.

__init__

__init__(mode=CURRENT, as_of=None, tm_database=None, tm_view=None, tm_table=None, window=None)

__repr__

__repr__()

__eq__

__eq__(other)

instant_sql

instant_sql(offset=None) -> str

The dataset's valid instant moved by offset, as a constant expression.

CURRENT: the query time; AS_OF: the literal; TIME_MANAGER: the manager's business date, the shift inside the scalar sub-query so that it stays one single-row read resolved once. Shifting the constant (never the ValidStart / ValidEnd columns) keeps partition elimination: the arithmetic is folded into a literal in the plan (verified on Vantage 20).

catalog_validtime

catalog_validtime() -> str

The value written to DATASET_VALIDTIME (VARCHAR(255)).

CURRENT VALIDTIME or VALIDTIME AS OF TIMESTAMP '...' — the qualifier the view carries — or TIME_MANAGER <db>.<view> for a dataset following a TimeManager. A very long quoted manager name could overflow the column, so it then degrades to the mode name; the build table holds the full location anyway.

describe

describe() -> str

CatalogIncomplete

Bases: ValueError

The catalog does not hold enough to rebuild the view. missing lists what, fix says how.

missing instance-attribute

missing = list(missing)

fix instance-attribute

fix = fix

__init__

__init__(message, missing=(), fix='')

_join

_join(cols)

_val

_val(row, key)

row[key] with NULL in every spelling (None, NaN from pandas, '') as None.

_split

_split(text)

_norm

_norm(value)

column_rows

column_rows(entity, features, data_domain=None)

Rows of the columns table for a dataset: entity columns first, then the features, in the view's order.

features are FeatureSpec; their base_name (catalog name), level, storage_entity and left_out are recorded when known. ENTITY_KEY is the key the feature is stored at: its storage entity (primary-index grain), else its join columns (coarser feature), else the dataset's entity.

column_rows_from_spec

column_rows_from_spec(spec, data_domain=None, previous=None)

column_rows of a parsed DatasetSpec (the backfill of restore_dataset_catalog).

A parsed view says nothing about the catalog name of a feature, its domain, nor its storage entity: previous (the rows already recorded) provides them for a column of the same name, so a repair never erases what the builder knew. What the view's text determines (DERIVABLE_FIELDS) comes from the spec.

derivable_view

derivable_view(rows)

What the view's text determines, comparable: [(field values...)] ordered by column order.

window_from_row

window_from_row(row)

The HistoryWindow of a window-table row, with its fixed bounds spelled as they were written.

The table stores the bounds as TIMESTAMP(0) WITH TIME ZONE (read back in the session zone); the literal the view was built with is in WINDOW_TEXT, so it is read from there.

time_from_build

time_from_build(build, window_row=None)

spec_from_catalog

spec_from_catalog(build, columns, offsets=None, window=None, schema_name=None, view_name=None)

The DatasetSpec the catalog describes. Raises CatalogIncomplete when it cannot.

build: the dataset's row of the build table (dict); columns: its rows of the columns table; offsets: its rows of the offsets table; window: its row of the window table (history).