tdfs4ds.migration.executor¶
tdfs4ds.migration.executor
¶
Cross-store migration executor (v0.3.1.150) — the write phase.
migrate_objects(plan, approvals) takes an approved manifest from
:func:tdfs4ds.plan_migration and recreates the selected objects in the
primary store, wave by wave (upstream-first), bringing along:
- non-FS upstream objects (intermediate views recreated from DDL; raw source tables copied or referenced cross-DB per choice),
- the filter/time managers (recreate or unify onto an equivalent primary one),
- the processes (re-registered with fresh primary ids; a source→primary id map is threaded everywhere),
- the feature-value data (default: recompute via
run(); fallback: copy theFS_T_*rows remapping the store-localFEATURE_ID), - the datasets (view recreated with
FEATURE_VERSIONrefs remapped), - the business dictionary (rows re-homed under the primary
DATABASE_NAME), - the lineage graph (re-derived from the primary DDL — primary-scoped), and
- the Teradata vector index (rebuilt so the migrated docs are searchable).
The executor refuses to run unless every conflict is approved and no approved
replace is still blocking (the lab→prod downstream-safety gate). Every
auxiliary step (BD / lineage / vector) is fail-open — a doc/index failure never
corrupts an otherwise-migrated feature (same discipline as upload_features).
_PROCESS_DOC_TABLES
module-attribute
¶
_PERIOD_COLUMNS
module-attribute
¶
logger_safe
¶
Wrapper around the global logger that only emits logs when
tdfs4ds.DISPLAY_LOGS is True. level is a string like "info", "error", etc.
norm_name
¶
Uppercase, de-quoted, stripped — the canonical comparison form.
split_qualified
¶
Split 'db.obj' / '"db"."obj"' / 'obj' into (db, obj) (raw,
de-quoted but original case preserved). db is '' when unqualified.
_decisions
¶
Return (skip_keys, replace_keys) from the approval map.
_effective_placement
¶
Source→primary placement for reference rewriting.
- copied tables / recreated views → their primary placement (rewrite refs),
reference-mode source tables → identity (keep the cross-DB source ref),skip(already-present) objects → their primary placement (refs point at the existing primary object).
_rewrite_and_replace_view
¶
Recreate a view in the primary: SHOW VIEW → rewrite refs + remap pids → REPLACE VIEW.
table_copy_statements
¶
The statements copying a source table into the target. Pure. CREATE TABLE ... AS <table>
WITH DATA keeps the table's definition (primary index, partitioning), so a later plan finds
the copy identical in structure; replace drops the target first (an approved replace of a
table whose structure differs).
_copy_or_reference_table
¶
Copy a raw source table into the primary (WITH DATA) or leave it cross-DB.
A target table that is there with the same structure was found by the plan
(data_choice='reuse', action='identical'): its rows are not touched. A table found
at copy time that the plan did not see is NOT taken as reused (its structure was never
compared): the copy fails and says so. replace (an approved replace): drop it, then
copy.
_recreated_upstream
¶
The upstream non-FS objects Phase A handles: source tables (copied, reused or read in
place) and intermediate views, never a view read where it is (action='reference')
nor an object whose kind is not verified. Pure.
_order_upstream
¶
Upstream non-FS objects (tables + intermediate views), dependencies first.
_build_entity_id_dict
¶
Entity columns -> {col: 'BIGINT'} (types are placeholders; run() recomputes the real SQL types from the live view — registration only uses the keys).
_register_process
¶
_register_process(m, dst_db, dst_obj, filtermanager, target_domain, progress, force_domain_change=None) -> Optional[str]
Re-register a migrated process view in the primary; return the primary PID.
_copy_process_options
¶
Carry the source process's execution options over: FS_PROCESS_OPTIONS
(close_absent_entities) and FS_PROCESS_SETTINGS (track_entity_refresh).
Read from the source store by explicit schema (never through federation).
Fail-open: a source without the table, or a refused write, only loses the
option, said in the progress stream. The FS_R_* refresh tables are not copied
(a recompute regenerates them).
_migrate_feature_properties
¶
_migrate_feature_properties(plan, pid_map, registered, src, target_domain, progress, report) -> None
Carry the declared properties (range, allowed values, NULL meaning, sensitivity) of the migrated features over. Read from the source store by explicit schema; fail-open (a source without the properties objects, or a feature not registered yet, only loses them, said in the progress stream).
_record_migrated_time_manager
¶
Record, for a migrated process, the TimeManager it reads in the primary.
The association drives run(): without it the recompute below ran in real
time, wrote today's value, and a later roll_out over past dates could no
longer insert anything before it (its merges only update the overlap). The
manager's primary location is the placement of the source manager's view.
Fail-open: a failure only loses the association, logged.
_object_known_missing
¶
True only when DBC answers that db.obj does not exist; a failed read is not an answer.
_migrate_domain_clocks
¶
_migrate_domain_clocks(plan, placement, target_domain, report, progress) -> Dict[str, Tuple[str, str]]
Recreate the clock of each migrated data domain in the primary and declare it (0.3.6.0).
The processes' soft clones are migrated as views over the clock's table of dates, which
Phase A copies (it is a source table of every clone); the clock view and the domain's
FS_DATA_DOMAIN_SETTINGS row were not, so the domain lost its clock. The clock view
is made over the placed table (or the table is copied first, as a hard clone, when no
clone brought it), at the source clock's cursor, and declared for the target domain.
Fail-open: a failure is reported, the processes keep their clones.
_migrate_manager
¶
Recreate or unify a process's filter manager; return a FilterManager for registration (or None). Time managers are metadata-only (recorded via roll_out) and repointed if unified.
_kept_objects
¶
{(DB_UP, OBJ_UP)} (source keys) of objects that already exist in the
target and are kept: skipped by approval, or a reused source table. Their
target documentation is never overwritten; the source's only fills gaps. An object kept
identical (0.3.8.15) counts too.
_target_documented_keys
¶
{source: {key tuple}} of the target's current business-dictionary rows for
names ({(DB_UP, OBJ_UP)}): what a kept object already has documented.
_migrate_business_dictionary
¶
Re-home the migrated objects' BD rows under their target DATABASE_NAME.
placement (_effective_placement): a source table left in its database
(reference) keeps its documentation there. keep_target: objects the
target already has (skipped, reused) -- their documentation there wins, the
source only fills parts the target lacks.
process_doc_copy_sql
¶
process_doc_copy_sql(src_db: str, dst_db: str, table: str, columns, pid_map: Dict[str, str]) -> List[str]
[DELETE, INSERT] copying the current rows of a process-documentation table
from the source store to the target, PROCESS_ID re-keyed. Pure. The DELETE ends
the target's current rows for those processes (a replace keeps its id).
_migrate_process_documentation
¶
Copy the business logic and EXPLAIN documentation of the processes this run
registered, then link their feature descriptions (needs the features in the
catalog: a process registered with data_strategy='none' gets them at its
first run, with tdfs4ds.link_feature_documentation(pid)).
migrate_objects
¶
migrate_objects(plan: Dict[str, Any], approvals: Optional[Dict[str, str]] = None, *, dry_run: bool = False, rebuild_vector_index: bool = True, progress: Optional[Callable[[str], None]] = None) -> Dict[str, Any]
Execute an approved migration manifest against the primary store.
Parameters¶
plan : dict
The manifest from :func:tdfs4ds.plan_migration.
approvals : dict[str, str] | None
{conflict_key: 'skip'|'replace'} for every conflict. Required whenever
the plan has conflicts; a replace that is still blocking (the
downstream-safety gate) is rejected.
dry_run : bool
Validate approvals and return the plan of record without writing.
rebuild_vector_index : bool
Rebuild the Teradata vector index after BD migration (default True; skipped
unless VECTOR_STORE_BACKEND == 'teradata').
progress : callable(str) | None
Per-step progress hook (for the SSE panel).
Returns¶
dict
Execution report: pid_map (source→primary), per-object outcomes,
skipped/replaced, and any post-migration downstream compile breakages.
history_next_steps
¶
What to run after the migration to build the history of the migrated processes on a clock (0.3.8.15). Pure.
'Computed again' runs each process once, at the current date: a roll_out from the
first date then finds a value stored at a later date and refuses (history guard), so the
history is rebuilt with rebuild_history=True; with 'not now' a plain roll_out does.
_migrate_glossary
¶
Copy the glossary terms the target lacks (IMPORTED, author 'migration'). A term the target declares with another meaning is reported, never overwritten. Fail-open.
_run_phases
¶
_run_phases(plan, src, target_domain, objects, placement, pid_map, report, skip_keys, _obj_skipped, rebuild_vector_index, progress, replace_keys=())
Execute the migration phases (primary-only; see migrate_objects).
_lineage_refresh_objects
¶
Objects whose lineage Phase F refreshes: only those this run created.
A dataset counts only when Phase D built it (ok=True): a deferred one
(data_strategy='none'), one whose processes did not migrate, or a
failed build does not exist in the primary, and naming it used to abort
the whole refresh. A view whose creation failed is left out the same way.
_resolve_primary_pid
¶
PROCESS_ID of a process view already registered in the primary (or None).
_read_source_dataset_entity
¶
{entity_col: type} for a source dataset (from its FS_V_*_ENTITY view).
_source_catalog_rows
¶
Rows of the source store's FS_V_<catalog>_<suffix> view for a dataset; [] when the optional
table does not exist or cannot be read (fail-open: the DDL path is the fallback).
_source_catalog_spec
¶
(DatasetSpec, column rows) the SOURCE dataset catalog describes, or (None, []).
Since 0.3.7.35 the catalog records the aliases, process versions and storage tables of a dataset next to its build details, so the specification no longer depends on the source view being readable (a dropped view) nor on parsing its text.
_catalog_base_names
¶
{FEATURE_ID: catalog feature name} recorded in the columns table (rows without a name are left out).
_dataset_build_options
¶
build_dataset keyword arguments reproducing the source view's build.
The strategy (grouped or not), the join type and the point in time are read
from the source view's own DDL. A plain build_dataset call would silently
turn a grouped, fixed-date or TimeManager dataset into a current multi-join
one in the target store.
A TimeManager dataset is re-pointed to the manager's migrated copy when the plan placed one; otherwise it keeps referencing the source store's manager (cross-database), and the second value returned says so for the report.
_dataset_offset_options
¶
{base feature: [offset ISO, ...]} of a parsed dataset, {} without offsets.
_offset_feature_map
¶
{column alias (upper): base feature (upper)} and {base: process id} of the offset columns.
selection_from_spec
¶
(selected_features, feature_offsets) rebuilding spec's columns under their names. Pure.
base_names {FEATURE_ID: catalog name} (source store), pid_map
{source PROCESS_ID: target PROCESS_ID}. A column named like its feature
stays a plain process id (the call of a dataset without alias is unchanged);
any other name travels as the version's alias. None when a feature
name is unknown or a process was not migrated (the caller falls back).
_source_feature_names
¶
{FEATURE_ID: FEATURE_NAME} of spec's features in the source store's catalog.
_rebuild_dataset
¶
Rebuild a migrated dataset in the primary via build_dataset — NOT a view
copy. The source dataset view refs the store-local FEATURE_ID /
FEATURE_VERSION of the source; build_dataset regenerates them against
the primary's freshly-registered features and registers the primary dataset
catalog rows. The source feature→process map (from the source DDL) has its
process ids remapped source→primary. The strategy, join type and point in
time are carried over from the source view (_dataset_build_options).
_source_stale_record
¶
(record, error): what force_compute='changed' says of source_pid in the SOURCE store
(scheduling.changed.changed_plan read with the source's names, nothing written). record
None = its stored values were computed with its current SQL.
_catalog_rows
¶
Current feature catalog rows of names in the store whose tables are in schema.
_copy_feature_values
¶
_copy_feature_values(m, source_pid, primary_pid, src, target_domain, progress, report, plan=None, dst=None)
data_strategy='copy' (0.3.8.15): copy a process's stored values and its completed
follow-up rows from the source store into the target, inside one Teradata system.
- The storage of the process is prepared in the target with the code its first run would
use (
execution._prepare_storage: entity, features,FS_T_*tables, FEATURE_IDs). - Per pair of storage tables, the target rows of exactly these (FEATURE_ID, FEATURE_VERSION)
pairs are deleted, then the source rows inserted
NONSEQUENCED(every period as stored), FEATURE_ID matched on the feature triplet and FEATURE_VERSION set to the target process id. A storage table shared with other processes keeps their rows; a second copy gives the same rows. - The completed follow-up rows are copied (PROCESS_ID re-keyed) so
run/roll_outfind those business dates done. A new process gets its SQL version recorded first, and the copied rows are stamped with the copy's time, so they belong to that version: a later change is then seen byforce_compute='changed'. Dates the source computed with older SQL than its current view (changed_planin the source) are not marked done: the nextroll_outcomputes them. A process replaced by this migration keeps its version unrecorded:roll_out(force_compute='changed')recomputes it and its branch.
Fails per process into report['errors'], never aborts the migration. Refused when the
source store cannot be read from this session (another system).
_dataset_target_domain
¶
The target domain a dataset is rebuilt under: target_domain unchanged unless it is a
{source: target} dict (0.3.8.15), then the target of its producing processes' domain
(the first one known; None = the session's).
_migrate_downstream_views
¶
_migrate_downstream_views(plan, placement, pid_map, report, skipped, target_domain, progress) -> None
Phase D2 (0.3.8.15): recreate the downstream views (include_downstream=True), each
after the views it reads, references rewritten; an attached one is attached again in the
target (no documentation pass, no index refresh: Phase E carries its documentation).
Fail-open: each outcome is in report['downstream'].