tdfs4ds.migration.planner¶
tdfs4ds.migration.planner
¶
Cross-store migration planner (v0.3.1.150) — the read-only phase.
plan_migration(seeds, source) resolves a mixed list of process / dataset /
feature names in a distant (lab) store, expands the upstream process
closure (the self-contained migration unit — the same closure the parallel
scheduler computes), inventories every object the closure touches (process views,
datasets, intermediate views, raw source tables), classifies them, detects
name conflicts against the primary (production) store, runs the replace
downstream-safety gate, and inventories the filter/time managers — returning
a JSON-serialisable manifest that requires approval before anything is written.
This phase never writes. It reuses the pure graph core of
:mod:tdfs4ds.scheduling.parallel_plan (_resolve_seeds / _build_nodeid_to_pid
/ _process_dependency_edges / _build_process_dag / _upstream_closure /
_compute_waves) — only the catalog reads are re-scoped to the source store.
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.
build_placement_map
¶
build_placement_map(objects, source_desc, primary_schema, primary_view_schema, renames=None, database_map=None) -> Dict[Tuple[str, str], Tuple[str, str]]
Build the source→primary placement map for a list of classified objects.
Parameters¶
objects : iterable of dict
Each {'database','object','object_type'} where object_type is one
of 'table' | 'view' | 'dataset' | 'process_view' | 'intermediate_view'
| 'source_table' (anything containing 'table' lands in the table
schema, everything else in the view schema).
source_desc : dict
The read-only descriptor {'schema','schema_view',...} of the source
store (used only as the default source DB when an object's DB is blank).
primary_schema : str
Primary table database.
primary_view_schema : str
Primary view database (view_schema()).
renames : dict, optional
{(SRC_DB_UP, SRC_OBJ_UP): NEW_OBJ_NAME} for objects renamed to avoid a
conflict. The destination DB is still chosen by object type.
database_map : dict, optional
Output of :func:normalise_database_map: the target database per kind
(and source database), over the defaults above.
Returns¶
dict
{(SRC_DB_UP, SRC_OBJ_UP): (DST_DB, DST_OBJ)}.
_read_source_df
¶
A source store's public view as a pandas frame (fail-open to empty).
_read_primary_df
¶
A PRIMARY store public view (NOT federated) — used for conflict checks.
_is_storage_object
¶
True for a feature-store storage object (FS_T_* values, FS_R_* refresh rows,
FS_V_* value views): never part of a migration plan. Pure.
_classify_objects
¶
Walk every closure process view's DDL and inventory + classify all objects it
reaches: process_view / dataset / intermediate_view / source_table.
build_teradata_dependency_graph already skips FS-internal technical tables
and stops at dataset / process-view level, so the remaining tables are raw
sources and the remaining views are intermediate.
_dbc_object_kinds
¶
{(DB_UP, OBJ_UP): TableKind} from ONE DBC.TablesV read for keys. None
when the dictionary cannot be read (fail-open: the graph's types are kept). An object
the dictionary does not list (no right on it, or gone) is absent from the result.
_source_attached
¶
{(DB_UP, OBJ_UP): 'V' | 'T'} of the objects attached in the SOURCE store (its
business-dictionary ATTACHED markers). Read from the sections TABLE of the store's table
database: the public sections view leaves the reserved sections out, so it never returned a
marker and attached views were migrated as plain views (0.3.8.15). Fail-open: {}.
_apply_real_kinds
¶
Set the real kind of every inventoried object (object_type + kind_source):
DBC.TablesV first, else what SHOW VIEW / SHOW TABLE gave, else unverified with
the error kept in error. kinds None = the dictionary was not readable.
downstream_views
¶
downstream_views(G, start, process_nodes, dataset_nodes, plan_nodes, skip_nodes=(), exclude_dbs=(), kinds=None, attached=None, domains_of=None) -> List[Dict[str, Any]]
The plain views that read, directly or through other views, the plan's process views
and datasets (start). Pure over the lineage graph G (edges reader -> read object, so
the readers of a node are its nx.ancestors).
Process views and datasets are never downstream views (process_nodes, dataset_nodes),
nor objects already in the plan (plan_nodes), managers / tables of dates (skip_nodes,
*_HIDDEN) or objects of exclude_dbs. kinds (DBC.TablesV): a view is kept only
when the dictionary lists it as a view (None = not readable: the lineage, which only
records readers that are views, types it). Each entry: {database, object, reads,
data_domains, attached, blocked, missing, kind_source}; blocked when what it reads
reaches a process view or dataset that is not in the plan (missing). domains_of
{node: [data domains]} of the plan's process views and datasets.
_order_by_reads
¶
entries (each with database, object, reads) with what an entry reads
first, among the entries themselves. Pure; a cycle keeps the remaining order.
_dataset_time_managers
¶
Set time_manager ({'database','view'}, source names) on each dataset
object that follows a TimeManager, and an empty reads on every dataset: a
dataset view reads the store's tables, which the access plan adds itself.
Read from the source dataset view's own DDL; fail-open (no manager recorded).
_primary_object_keys
¶
(DB_UP, OBJ_UP) of objects already present in the primary schema/view schema
and in the target databases of the plan (extra_dbs, from database_map).
_reuse_mapped_source_tables
¶
Mark mapped source tables found at their target data_choice='reuse' and
drop their object conflict. Kept as a conflict (with a reuse_refused note)
when the target lacks a source column: the migrated views would not compile.
_table_structures
¶
{(DB_UP, OBJ_UP): table_structure} of keys from two DBC reads (columns, primary
index). Read-only; fail-open to {} (a structure not read is never judged identical).
_mark_identical
¶
_mark_identical(objects, obj_conf, proc_by_pid, primary_proc_by_key, closure, feat_df, primary_feat_df, target_data_domain, domain_clocks=None) -> Tuple[list, Dict[str, str], Set[str]]
Mark the objects that already exist at their destination with the same definition
(action='identical', kept) and drop their conflict; the others stay conflicts.
Returns (conflicts kept, {source pid: target pid} of the processes already registered in
the target, {source pids whose features are already the target's own}): the processes kept as
they are, and the processes the target registers with the same features whose view differs (a
replace of their view keeps the target id and its features; the object conflict governs). Read-only: SHOW VIEW of both sides for the
views in conflict, one DBC read for the tables in conflict, nothing for an object that is not
there. Fail-open: an object that cannot be compared stays a conflict.
_build_downstream_gate
¶
_build_downstream_gate(dst_db, dst_obj, otype, incoming_names, primary_graph, primary_proc_by_key, primary_ds_features_by_node) -> Dict[str, Any]
Compute the downstream feature-loss verdict for replacing a primary object.
_source_domain_clocks
¶
{data_domain: clock} read from the SOURCE store's FS_DATA_DOMAIN_SETTINGS
(explicit schema, read-only), with the clock's current cursor. Fail-open: a store
without the table (before 0.3.6.0) or a domain without a clock gives nothing.
clock_target_state
¶
(state, current clock) of a source domain clock in the target. Pure.
current: the target domain's declared clock ({'database','view',...} or None),
view_exists: whether view_schema.<clock view> exists in the target.
'exists': the target domain already has this clock (kept as it is);
'replace': the target domain has another clock, which the migration replaces;
'create': no clock yet.
_clock_target_states
¶
Set target_domain, target_state and target_current on each source clock
(clock_target_state), read in the target. Fail-open: unread = 'create'.
_source_glossary
¶
Glossary terms of the source (store-wide ones and those of the migrated domains) against the
primary's: {'new': [...], 'same': [...], 'differing': [...]}, or {} when the source has
none. Read-only, fail-open. A domain term is re-keyed to target_domain when one is given.
plan_migration
¶
plan_migration(seeds=None, source=None, *, all_domains: bool = True, target_data_domain: Optional[str] = None, data_strategy: str = 'recompute', attach: bool = True, database_map: Optional[Dict[str, Any]] = None, run_user: Optional[str] = None, dataset_readers=None, sanity='cheap', outside_objects: str = 'move', data_domains=None, include_downstream: bool = False) -> Dict[str, Any]
_plan_migration
¶
_plan_migration(seeds=None, source=None, *, all_domains: bool = True, target_data_domain: Optional[str] = None, data_strategy: str = 'recompute', attach: bool = True, database_map: Optional[Dict[str, Any]] = None, run_user: Optional[str] = None, dataset_readers=None, sanity='cheap', outside_objects: str = 'move', data_domains=None, include_downstream: bool = False) -> Dict[str, Any]
Plan a cross-store migration (READ-ONLY — nothing is written).
Parameters¶
seeds : list[str] | None
Mixed process (id/view) / dataset / feature names in the source store.
None = the whole source store.
source : str | dict
The source store (a schema string or a {'schema','schema_view',...}
descriptor). Attached read-only for the duration when attach=True.
all_domains : bool
Consider all source data domains (default).
target_data_domain : str | dict | None
Re-route every migrated feature under this DATA_DOMAIN in the primary
(avoids feature-name collisions with existing production domains). None
keeps each feature's source domain. A dict {source_domain: target_domain}
gives each source domain its own target ('*' = any other domain; a domain
it does not name keeps its name); the resolved map is plan['domain_map'].
Two source domains whose clocks read different tables of dates cannot land in
one target domain: ValueError (nothing is written).
data_strategy : 'recompute' | 'copy' | 'none'
Default per-process data strategy (recompute recreates + re-runs, at
the business date of the process's TimeManager when it has one;
copy (same Teradata system) copies the process's stored values with
their whole history (FEATURE_ID and FEATURE_VERSION remapped, the target
rows of those features deleted first, other processes' rows untouched)
and its completed follow-up rows, so a later roll_out does not
recompute those dates; none registers the processes
without computing, for a primary that replays its history itself with
roll_out - a value computed first cannot be preceded by earlier
valid times afterwards). Per-process overrides can be applied at
execution.
attach : bool
Attach source read-only if not already attached (default True).
database_map : dict | None
Where the migrated objects go, per kind: source_table,
intermediate_view, process_view, dataset. A value is a
database name, or {source_db: target_db} ('*' = any other).
Default: tables to the primary's table database, views to its view
database. A source table mapped to a database that already holds it
(same name, every source column present) is reused there: nothing is
copied and the migrated views read it. The feature store's own tables
and views are not migrated and cannot be mapped.
run_user : str | None
The user that will run the processes in the target store (run /
roll_out). None = the session user, stated in the plan. Sets the
Run user group of plan['access'].
dataset_readers : str | list[str] | None
Users or roles that will read the datasets. Not given = a marked
<dataset readers> placeholder, and that group is flagged not runnable.
sanity : 'cheap' | 'full' | False
Run the workflow assessment on the SOURCE store, scoped to the closure,
before anything else, and keep it in plan['sanity']. 'cheap' runs
the checks of workflow_assessment.CHEAP_CHECKS, 'full' all of
CHECKS (adds the storage scans), False skips it and says so.
outside_objects : 'move' | 'keep'
Objects (tables and views) whose database is neither the source store's
table database nor its view database. 'move' (default) migrates them
like the others. 'keep' reads them where they are: they keep their
name (action='reference', exists_in_target), are not copied,
recreated, rewritten nor reported as conflicts, unless database_map
names their database for their kind. In both modes the run order follows
dependencies between processes that pass through such objects.
data_domains : list[str] | None
Source data domains to migrate whole: every process of those domains is a
seed (added to seeds; with seeds=None only these domains are taken).
An unknown domain raises ValueError naming the available ones.
include_downstream : bool
Also migrate the plain views (and attached views) of the source store that
read the plan's process views and datasets (object_type='downstream_view',
listed in plan['downstream']). One that also reads a process view or
dataset left out of the plan is blocked and not migrated.
An object that already exists at its destination with the same definition
(a view with the same SQL after the migration's rewrite, a dataset reading
the same features of the same processes, a table with the same columns and
primary index) is action='identical': kept, not a conflict, listed in
plan['identical']. A process whose view is identical and which the target
already registers with the same features is kept_identical: neither
registered, run nor copied (target_process_id is the id it keeps). Any
other existing object is a conflict (differs says why).
Returns¶
dict
The migration manifest (see module docstring). Pass it to
:func:tdfs4ds.migrate_objects with an approval map.