Skip to content

tdfs4ds.dataset.joined

tdfs4ds.dataset.joined

A registered dataset joined with a table or view outside the feature store (0.3.8.8).

create_joined_view builds an ordinary view::

REPLACE VIEW <db>.<name> AS
LOCKING ROW FOR ACCESS
SELECT B.*, O.<col> AS <alias>, ...
FROM <dataset view> B
LEFT JOIN <db>.<object> O
  ON B.<k1> = O.<k1> AND ...

It is not a feature-store dataset: nothing is written to the dataset catalog (no _BUILD / _COLUMNS rows), so restore, rebuild and migration have nothing to learn about it. The dataset drives (LEFT JOIN) and keeps its own valid time, versions and offsets; the outside object is read as it is now, whatever the dataset's valid time. A process can read the view like any view.

By default the view is attached to the feature store (attach_objects): lineage edges, pass-through column documentation, removal guards and the agent's view of it all come from that existing mechanism.

Whether the join columns are unique in the outside object is opt-in: by default nothing is read and a warning says rows may multiply when they are not unique; check_unique=True counts them (after an EXPLAIN gate) and duplicates refuse the build.

__all__ module-attribute

__all__ = ['create_joined_view', 'parse_joined_ddl', 'joined_view_sql', 'JoinedViewError']

TEMPORAL_COLUMNS module-attribute

TEMPORAL_COLUMNS = {'VALIDSTART', 'VALIDEND', 'VALIDPERIOD'}

NOW_NOTE module-attribute

NOW_NOTE = 'Joined view over a registered dataset and an outside object. The dataset keeps its own valid time; the outside object is read as it is now.'

_FROM module-attribute

_FROM = re.compile('\\bFROM\\s+(?P<ds>(?:\\"[^\\"]+\\"|[\\w$#@]+)(?:\\.(?:\\"[^\\"]+\\"|[\\w$#@]+))?)\\s+B\\b\\s+LEFT\\s+JOIN\\s+(?P<ob>(?:\\"[^\\"]+\\"|[\\w$#@]+)(?:\\.(?:\\"[^\\"]+\\"|[\\w$#@]+))?)\\s+O\\b\\s+ON\\s+(?P<on>.+?)\\s*;?\\s*$', re.I | re.S)

_ITEM module-attribute

_ITEM = re.compile(',\\s*O\\.(?P<c>\\"[^\\"]+\\"|[\\w$#@]+)\\s+AS\\s+(?P<a>\\"[^\\"]+\\"|[\\w$#@]+)', re.I)

_ON module-attribute

_ON = re.compile('B\\.(?P<k>\\"[^\\"]+\\"|[\\w$#@]+)\\s*=\\s*O\\.(?P=k)', re.I)

JoinedViewError

Bases: ValueError

The joined view cannot be built; the message says what to change.

logger_safe

logger_safe(level, message, *args, **kwargs)

Wrapper around the global logger that only emits logs when tdfs4ds.DISPLAY_LOGS is True. level is a string like "info", "error", etc.

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.

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

split_qualified

split_qualified(name)

Split db.obj into (database, object), both de-quoted.

Quote-aware, so a dot inside a quoted part does not split the name: split_qualified('"DEINF.CARLOSN"."FS_X"') == ('DEINF.CARLOSN', 'FS_X'). The naive rsplit('.', 1) this replaces returns ('"DEINF.CARLOSN"', '"FS_X"') only by luck and ('"DEINF', 'CARLOSN"."FS_X"') in the split('.') variant.

An unqualified name returns ('', name).

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.

_u

_u(v) -> str

_id

_id(c) -> str

joined_view_sql

joined_view_sql(view: str, dataset: str, obj: str, join_columns, added, *, select_only: bool = False) -> str

The REPLACE VIEW text. view, dataset and obj are 'db.name'; join_columns the key columns; added [(object column, output name)]. Pure; :func:parse_joined_ddl reads it back.

parse_joined_ddl

parse_joined_ddl(ddl: str) -> Optional[dict]

{"dataset", "object", "join_columns", "columns": [(object column, output name)]} of a view text made by :func:joined_view_sql, else None. Pure.

_view_columns

_view_columns(db: str, name: str) -> list

Column names of a view, in order (DBC).

_object_kind

_object_kind(db: str, name: str) -> Optional[str]

TableKind of an existing object ('V', 'T'...), else None.

_execute

_execute(sql: str)

_registered_names

_registered_names(inputs: dict) -> set

{(DB_U, NAME_U)} of the datasets and the process views (a joined view may not take their name).

create_joined_view

create_joined_view(dataset: str, join_object: str, view_name: str, *, columns=None, join_columns=None, aliases: Optional[dict] = None, schema_name: Optional[str] = None, check_unique: bool = False, force: bool = False, attach: bool = True, document: bool = True, return_query: bool = False, _inputs: Optional[dict] = None) -> dict

Join a registered dataset with a documented or attached table / view, as an ordinary view.

Parameters:

Name Type Description Default
dataset str

a registered dataset ('db.name' or 'name'); it drives (LEFT JOIN) and keeps its own valid time, versions and offsets.

required
join_object str

the table or view to join, documented in the business dictionary or attached (see :func:tdfs4ds.find_joinable_objects).

required
view_name str

the new view ('db.name', or a bare name in schema_name / the store's view database). Not the name of a dataset or of a process view.

required
columns

the object's columns to add (default: every column but the join columns).

None
join_columns

the key columns (default: the entity columns the object carries; a subset is allowed).

None
aliases Optional[dict]

{object column: output name}. A column that collides with a dataset column needs one.

None
check_unique bool

count the join columns' duplicates in the object before creating (after an EXPLAIN within the sample limits); duplicates refuse the build, an over-limit plan refuses it unless force. Off by default: nothing is read, and a warning says rows may multiply when the dictionary does not prove the columns unique.

False
attach bool

attach the view to the feature store (lineage, documentation, removal guards, agent).

True
document bool

with attach, let the model describe the view (when one is configured).

True
return_query bool

build nothing; return the SQL.

False

The outside object is read as it is now, whatever the dataset's valid time. The view is not a feature-store dataset: no dataset-catalog row is written. Returns {"view", "object", "dataset", "sql", "join_columns", "added", "uniqueness", "attached", "warnings", "created"}; raises :class:JoinedViewError with the fix.