From prototype to production¶
At the start you use upload_features alone, to check the results and the workflow. Then you
operationalise: attach the clock, build the history once, and schedule run. Each step ends
with what to check before you move on.
1. Validate with upload_features alone¶
upload_features registers the process and runs it once. If the view reads a TimeManager, the
run is at the manager's current date; otherwise it is in real time.
import tdfs4ds
pid = tdfs4ds.upload_features(
'MY_DB.VW_CUSTOMER_SPEND',
entity_id=['CUSTOMER_ID'],
feature_names=['spend_30d', 'nb_orders_30d'],
return_process_id=True,
)
Iterate: change the view, register again, look at the values. run_now=False declares the
process without running it; the source is EXPLAINed first and nothing is registered if it fails.
Before moving on, check
- The values are right for a few entities you know.
- The follow-up row says
COMPLETED(tdfs4ds.follow_up_report()). tdfs4ds.sanity_check('check.html')(scope'cheap', the default) shows no error: key columns, filters, partitioning, lineage.- Datasets built from the features return the rows you expect.
2. Attach the clock¶
Declare one TimeManager for the data domain. Write the process SQL against the clock.
import teradataml as tdml
from tdfs4ds.utils.time_management import TimeManager
dates_df = tdml.DataFrame.from_query( # a teradataml DataFrame, not pandas
"SELECT DISTINCT CAST(ORDER_TS AS DATE) AS BUSINESS_DATE FROM MY_DB.ORDERS "
"WHERE CAST(ORDER_TS AS DATE) < CURRENT_DATE")
clock = TimeManager('SALES_CLOCK', 'MY_DB')
clock.load_time_steps(dates_df, 'BUSINESS_DATE') # once: the past dates only
tdfs4ds.set_domain_time_manager(clock)
A process registered after this runs once at the clock's first date: its clone is created
at the clock's cursor, which load_time_steps sets to step 1.
From then on upload_features walks the view's lineage and records the manager it reads. When
that is the clock, the process gets its own soft clone (<view>_TM, same dates, own cursor)
and its view is rewritten to read the clone. For processes registered before the clock, use
tdfs4ds.align_domain_time_managers(dry_run=True).
What changes
The valid time of a run moves from real time to the manager's date. The values of a run are stamped with the business date, and the follow-up row records that date. Details: Which valid time a run uses.
Before moving on, check
tdfs4ds.get_process_info(pid)['DOMAIN_TIME_MANAGER']names the clock.- The process view reads its clone (
SHOW VIEW), and the sanity check reports noprocess_not_on_domain_clock.
3. Build the history once¶
The clock drives. At each date every clone moves to the same date, and the processes of that date run in dependency order.
- Forward only. Each run writes from its date onward. Start at the first date, on features that have no value yet.
- Rebuild. After a logic change:
tdfs4ds.roll_out(data_domain='SALES', time_id_start=1, force_compute=True). Withoutforce_compute, dates alreadyCOMPLETEDare skipped. roll_outwarns before it skips a date alreadyCOMPLETEDwhile it computes an earlier one.- For a source that holds its own history, use
valid_time_columninstead: one run writes it.
Before moving on, check
- Every date of the calendar is
COMPLETEDin the follow-up. - A dataset read
as_ofan early date returns the values of that date. tdfs4ds.sanity_check(...)reports noahead_of_upstreamorupstream_missing_at_date.
4. Run regularly¶
The production pattern, in the author's words:
We do not need to put a date in the future in the time manager, because we then use
run, which automatically uses the current time in the time manager view, and uses the valid time column. The roll-out is run once for the history, and then the run is scheduled.
In practice:
- The calendar holds only past dates. Do not add future dates.
roll_out(data_domain=...)runs once, for the history.-
Schedule
run, in one of these forms:tdfs4ds.run(data_domain='SALES') # every process of the domain tdfs4ds.run([pid_1, pid_2]) # a list tdfs4ds.run(pid_1, at='now') # one process, at the database timerunreads the database time once. For the duration of the run it puts that time into every manager view the processes read (only the selected value changes), so each process reads its source as of now. Afterwards it puts each view back on its cursor. The follow-up row records that time. No cursor moves, so the nextroll_outis unchanged. 4. Withvalid_time_column, the stored values take their valid time from the data column. The manager date (here, now) only bounds the source rows the view returns. 5. Extend the calendar only to runroll_outover new dates, for instance to backfill.
run(pid) alone is not the scheduled form
Without at=, run(pid) uses the manager recorded for the process, at its cursor: the last
historical date, already COMPLETED. The run is skipped: it returns None, writes no
follow-up row, and logs Skipping computation for process_id=... (already exists,
force_compute=False). Schedule the domain form, the list form or at='now'.
Verified on Vantage 20 (tdfs4ds 0.3.6.18)
Measured with a calendar of four past dates and two processes, one of them with
valid_time_column:
run(data_domain=...)logged one time, the database clock, and set each clone to it for the run. The values included today's source rows. The follow-upVALIDTIME_DATEand the newValidStartwere that time. Afterwards each clone was back on its cursor.run(pid)alone used the cursor date and was skipped.- For the
valid_time_columnprocess, today's rows were stored at their own event times, not at the run time. - A second run with unchanged values writes a follow-up row and leaves the stored periods as they are.
run(data_domain=...)returns{process_id: status}.
Orchestrator settings:
| Need | Use |
|---|---|
| Do not compute on an upstream that failed | check_upstream=True |
| The orchestrator must see a failure | on_failure='raise': a FeatureIngestionError after all segments or processes are attempted |
| Run independent processes together | tdfs4ds.analyze_parallel_plan(...), then tdfs4ds.generate_execution_script(plan, max_workers=4, wave_on_failure='skip_descendants') |
The generated script runs waves in order and the units of a wave in separate processes. See Parallel execution plan and Failure handling.
Before moving on, check
- A scheduled
run(data_domain=...)writes a new follow-up row per process at the current time, and the values change where the source changed. - The next
roll_outover a new date range still starts where the cursor was. tdfs4ds.sanity_check(...)is scheduled as well; see Workflow health.
5. Promote lab to production¶
Plan first. The plan is read only and lists every object, manager and conflict.
plan = tdfs4ds.plan_migration(
['<process, dataset or feature>'],
source='LAB_DATABASE',
)
print(tdfs4ds.render_migration_report(plan))
result = tdfs4ds.migrate_objects(plan, approvals={}, dry_run=True)
Approve each conflict (skip or replace) in approvals, then run migrate_objects without
dry_run. The domain clock and the clones come with the processes. Then rebuild the production
history with step 3 and schedule step 4. With the default data_strategy='recompute', the values
are recomputed in production. See also Before a migration.
What is kept and what is a conflict¶
An object already at its destination with the same definition is identical (kept). It is not a conflict and it is not replaced.
- Views: the same SQL after the migration's own database rewrite. Whitespace, comments, letter case and manager names are ignored.
- Datasets: the same columns, features, producing processes, offsets, entity, join and time mode.
- Source tables: the same column names, types, lengths, character sets and primary index.
A process whose view is identical and that is already registered in the target keeps its target process
id. It is not registered again and it is not run. The report lists these under kept_identical and
kept_processes; replaced lists what a replace changed.
Only changed objects are conflicts (skip or replace). After a replace, refresh the branch below it:
The report returns this advice under refresh. One gap: a real-time process (no business date) that the
migration itself recomputed does not make force_compute='changed' flag the identical processes that read
it. Run tdfs4ds.run('<PROCESS_ID>', downstream=True) to cover them.
Source tables¶
- Absent in the target: created with
CREATE TABLE ... AS <table> WITH DATA. The primary index and the partitioning are kept. - Present with the same structure: kept. The rows are not touched.
- Present with another structure: a conflict. A
replacedrops the table, then copies it. - Found in the target only at copy time: the copy fails and says to plan again. A table is never reused silently.
Feature values: data_strategy¶
| Value | What it does |
|---|---|
'recompute' (default) |
Runs each process in the target. |
'none' |
Registers only. Rebuild a history with roll_out. |
'copy' |
Copies the stored values. Same system only. |
With 'copy', after a process is registered, the migration does this for each of its storage tables:
- It deletes the target's rows of exactly this process's
(FEATURE_ID, FEATURE_VERSION)pairs. - It runs a
NONSEQUENCED INSERT ... SELECTof the source rows. The valid periods are kept and the feature ids are remapped. - It compares the row counts.
- It copies the completed follow-up rows with
PROCESS_IDremapped. Their run time is the copy time, so they belong to the target's SQL version. Aroll_outon the target does not recompute those dates. Dates the source computed under an older SQL version are not marked done.
The target storage table may hold the features of other processes. Only this process's rows are touched.
Attached views keep their attached marker after a migration.
The steps in the app (Migration panel)¶
The Migration panel follows the same path, in six steps:
- Direction: into this store from another store on this system, or a deployment bundle for another system (see Deploy definitions with CI/CD).
- What to migrate: the whole store, some data domains, or chosen processes and datasets.
- Where it goes: the data domain map and the databases. The plan prefills the databases (see below).
- Options: feature values (computed again, or not now), manager contents in the bundle (structure only, or with their dates and segments), the user that will run the processes, the users or roles reading the datasets, and the sanity check (cheap, full or skipped).
- Plan: builds the read-only plan, with the diagram, the conflicts and the sanity section.
- Approve: stages the plan. Then run the migration, or get the deployment bundle (.zip).
The report can be exported as HTML with Export the report.
The panel links to this page and to Deploy definitions with CI/CD (the Guide links under its title open them in the app's Help panel).
Whole data domains, downstream views, data domain map¶
plan = tdfs4ds.plan_migration(
source='LAB_DATABASE',
data_domains=['SALES'], # whole data domains of the source
include_downstream=True, # also the views that read the migrated objects
target_data_domain={'SALES': 'SALES_PROD'}, # source domain -> production domain
outside_objects='keep', # objects of other databases stay where they are
)
print(plan['domain_map']) # the resolved map
A domain the dict does not name keeps its name; the key '*' sets the target of any other domain.
target_data_domain also takes one string, which puts every migrated feature under that domain. Two source
domains whose clocks read different tables of dates cannot land in one target domain: nothing is written.
outside_objects='move' (the default of plan_migration) migrates objects of other databases too;
'keep' leaves them in place and lists them in the report. In both modes the run order follows the
dependencies between processes, including those that pass through such objects, and each dataset is built
right after the wave of its last producing process, before any process that reads it. Feature storage
tables (FS_T_*) are never part of a plan: they are recreated empty by registration.
Database mapping defaults¶
tdfs4ds.migration.suggest_database_map(plan) proposes where each source database goes, one row per
kind and source database:
from tdfs4ds.migration import suggest_database_map
rows = suggest_database_map(plan) # {kind, source_database, target_database, inside_store, reason, n_objects[, data_choice]}
The rules: a source table goes to the production table database, and a view to the production view
database, when its database is one of the source store's. Any other database stays where it is (read in
place). A table already in production with every source column is reused (data_choice='reuse'), not
copied. Edit the rows into a database_map= argument and plan again.
Objects the catalog could not verify¶
The plan reads each object's real kind from the database catalog. An object it cannot verify is listed apart as not verified, and it is not migrated. Fix the access (a right on the object) and plan again.
Diagram and report file¶
from tdfs4ds.migration import render_migration_diagram, write_migration_report
write_migration_report(plan, 'migration_plan.html', fmt='html') # the approval report as a file
render_migration_diagram(plan) returns the same diagram as an inline SVG: the source store on the left,
the target on the right, one lane per kind, the target split by action.
Approve, then run or bundle¶
After the reviewer approves the plan, run it, or hand it over as a bundle:
- Run it:
migrate_objects(plan, approvals=approvals)(the only writer), then step 3. - Bundle it:
tdfs4ds.export_definitions(...)and deploy the files withdeploy.py(see Deploy definitions with CI/CD). The generated migration script is pure ASCII and starts withtdfs4ds.require(<version>), so it refuses to run on an older package.
Before moving on, check
- The migration report's sanity section shows the processes
refreshable. - After the roll-out, production values equal the lab's for a few entities and dates.
- Views of the process chains that name a table without
LOCKING ROW FOR ACCESSare listed by thesource_accesscheck. Read them before you promote them.