Skip to content

tdfs4ds.migration.identical

tdfs4ds.migration.identical

Objects already in the target with the same definition, and the copy of stored values (0.3.8.15).

Two questions of a migration inside one Teradata system, answered by pure helpers (no database):

  • Is the object already there, the same? A view (process view, view read by the processes, downstream view) is compared on its SQL after the migration's own rewrite (the references the executor would rewrite, the process ids it would remap), both texts normalised the way the deployment fingerprints are (deploy.fingerprint.view_sql_fingerprint_text: comments, white space, case outside literals, manager references and a soft clone's cursor do not count) and with the quotes of plain identifiers removed ("PROD"."V" and PROD.V name one object). A text that is not a view definition is never judged the same. A dataset is compared on what it reads (dataset_signature: entity, join type, strategy, time, and per column the feature NAME, the producing process in the target and the offset), because its FEATURE_ID references are local to each store. A table is compared on its columns (name, type, length, digits, character set) and its primary index (table_structure).
  • Which statements copy a process's stored values? feature_copy_groups matches the source and target feature catalogs on the feature triplet, feature_copy_statements gives the NONSEQUENCED DELETE + INSERT per storage table pair, followup_copy_sql the INSERT of the completed follow-up rows.

_VIEW_HEAD module-attribute

_VIEW_HEAD = re.compile('^\\s*(?:CREATE|REPLACE)\\s+(?:RECURSIVE\\s+)?VIEW\\b', re.IGNORECASE)

_TOKEN module-attribute

_TOKEN = re.compile('\'(?:[^\']|\'\')*\'|\\"[^\\"]*\\"|[^\'\\"]+', re.DOTALL)

_PLAIN module-attribute

_PLAIN = re.compile('^[A-Za-z_][A-Za-z0-9_$#]*$')

_FOLLOWUP_TIME_COLUMNS module-attribute

_FOLLOWUP_TIME_COLUMNS = ('START_DATETIME', 'END_DATETIME')

REFRESH_ADVICE module-attribute

REFRESH_ADVICE = "tdfs4ds.roll_out(data_domain={domain!r}, force_compute='changed') refreshes what a replaced object changes: the processes whose SQL chain changed and the processes below them in the same data domain; the processes kept identical and not below a change are not recomputed."

_u

_u(x) -> str

_unquote_plain

_unquote_plain(text: str) -> str

text with "NAME" written NAME when NAME is a plain identifier (outside literals).

normal_view_ddl

normal_view_ddl(ddl: Optional[str], managers: Iterable[Tuple[str, str]] = ()) -> Optional[str]

The comparable form of a view definition, or None when ddl is not one. Pure.

views_identical

views_identical(source_rewritten: Optional[str], target_ddl: Optional[str], managers: Iterable[Tuple[str, str]] = ()) -> bool

True when the rewritten source definition and the target's are the same view. Pure.

rewrite_view_ddl

rewrite_view_ddl(ddl: Optional[str], placement, pid_map=None) -> Optional[str]

The source view DDL as the executor would execute it (references rewritten, process ids remapped, REPLACE VIEW). Pure.

table_structure

table_structure(columns: Sequence[Sequence[Any]], pi_columns: Sequence[Any]) -> Dict[str, Any]

{'columns': [(name, type, length, digits, fraction, chartype)], 'primary_index': [...]} from DBC.ColumnsV rows ((ColumnId, ColumnName, ColumnType, ColumnLength, DecimalTotalDigits, DecimalFractionalDigits, CharType), any order) and the primary-index column names in index order. Pure.

structures_equal

structures_equal(src: Optional[Dict[str, Any]], dst: Optional[Dict[str, Any]]) -> Tuple[bool, str]

(equal, why): equal only when both structures were read and their columns and primary index are the same. Pure.

dataset_signature

dataset_signature(spec, names_by_id: Dict[int, str], pid_map: Optional[Dict[str, str]] = None, placement=None) -> Optional[tuple]

What a dataset reads, independent of the store-local FEATURE_ID references, or None when a feature name is unknown. pid_map maps the source process ids to the target's, placement the source TimeManager location. Pure.

_names

_names(csv) -> set

registration_matches

registration_matches(source_meta: Dict[str, Any], target_row: Optional[Dict[str, Any]], target_domain: Optional[str]) -> Tuple[bool, str]

(same, why): the target catalog row registers the same features, entity and data domain as the source process (target_domain = the domain it lands in). Pure.

_entity_set

_entity_set(text) -> frozenset

feature_copy_groups

feature_copy_groups(src_rows, dst_rows, feature_names, entity, source_domain, target_domain)

(groups, missing). src_rows / dst_rows: feature catalog rows {FEATURE_ID, FEATURE_NAME, ENTITY_NAME, DATA_DOMAIN, FEATURE_DATABASE, FEATURE_TABLE} of the source and target stores. A feature is matched on its triplet (data domain - the target's - entity, name). groups: [{'source_table', 'target_table', 'ids': {source id: target id}, 'names': [...]}] per pair of storage tables; missing: the names not matched. Pure.

feature_copy_statements

feature_copy_statements(group: Dict[str, Any], source_pid: str, target_pid: str, entity_cols: Sequence[str]) -> List[str]

[DELETE, INSERT] copying the rows of one process from a source storage table to a target one, nonsequenced (every period as stored), FEATURE_ID and FEATURE_VERSION remapped. The DELETE removes the target rows of exactly these (FEATURE_ID, FEATURE_VERSION) pairs first, so a second copy gives the same rows; the other processes' rows of a shared table are not touched. Pure.

followup_copy_sql

followup_copy_sql(source_schema: str, target_schema: str, table: str, columns: Sequence[str], source_pid: str, target_pid: str, before: Optional[str] = None) -> str

INSERT ... SELECT of the completed follow-up rows of a source process into the target, PROCESS_ID re-keyed. Pure.

columns: the columns both tables have, in the target's order (FS_FOLLOW_UP is never altered: every column is named). START_DATETIME / END_DATETIME are the time of the copy: the copy is the target's run (a run belongs to the SQL version in force when it started, and the version of a copied process is recorded just before). A row already copied (same RUN_ID, business date, segment and status for the target process) is not copied again. before: a TIMESTAMP literal; only the business dates earlier than it are copied (the later ones were computed by the source with older SQL: the next roll_out computes them).

timestamp_literal

timestamp_literal(value) -> Optional[str]

TIMESTAMP 'YYYY-MM-DD HH:MI:SS+00:00' of a UTC timestamp, or None. Pure.