Skip to content

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 no process_not_on_domain_clock.

3. Build the history once

tdfs4ds.roll_out(data_domain='SALES')

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). Without force_compute, dates already COMPLETED are skipped.
  • roll_out warns before it skips a date already COMPLETED while it computes an earlier one.
  • For a source that holds its own history, use valid_time_column instead: one run writes it.

Before moving on, check

  • Every date of the calendar is COMPLETED in the follow-up.
  • A dataset read as_of an early date returns the values of that date.
  • tdfs4ds.sanity_check(...) reports no ahead_of_upstream or upstream_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:

  1. The calendar holds only past dates. Do not add future dates.
  2. roll_out(data_domain=...) runs once, for the history.
  3. 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 time
    

    run reads 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 next roll_out is unchanged. 4. With valid_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 run roll_out over 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-up VALIDTIME_DATE and the new ValidStart were that time. Afterwards each clone was back on its cursor.
  • run(pid) alone used the cursor date and was skipped.
  • For the valid_time_column process, 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_out over 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.

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.

See also