Managing time with the domain clock¶
Every value a process writes has a valid time. A run decides it once, and all the values of the run carry it. This page covers who decides that time, which call to use for which job, and how a data domain with one business calendar keeps its processes on the same date. The manager itself (loading dates, cursors, cloning) is in TimeManager & roll_out.
Best practice
Drive processes with a TimeManager, or set FEATURE_STORE_TIME. It is the only way
several processes share one valid time, and the only way values computed for a
business date carry that date. Real time is a fallback.
Which valid time a run uses¶
Every value a run writes gets one valid start, decided once per run:
| Order | Source | When |
|---|---|---|
| 1 | tdfs4ds.FEATURE_STORE_TIME |
it is set (each roll_out step sets it) |
| 2 | run(..., time_manager=tm) |
the manager's current business date |
| 3 | the TimeManager recorded for the process | recorded by upload_features(time_manager=), roll_out or a previous time_manager= |
| 4 | real time | none of the above: the database time, read once for the whole run |
Drive processes with a TimeManager, or set FEATURE_STORE_TIME. It is the
only way several processes share the same valid time, and the only way values
computed for a business date are stamped with that date. Real time is a
fallback. Since 0.3.1.227, every feature and every FilterManager partition of
a real-time run shares one valid start; earlier versions stamped each feature
separately, about a second apart. A real-time run's follow-up row keeps
VALIDTIME_DATE NULL.
Which call computes what¶
| Call | What it computes | Valid time of the values | Cursor moved? |
|---|---|---|---|
roll_out(process_list, time_manager=tm) |
every date of the calendar, in order | each calendar date | yes, step by step |
roll_out(data_domain='SALES') |
every process of the domain, every date, in dependency order | each calendar date | yes: the clock drives and every clone follows |
run(data_domain='SALES'), run([pid_1, pid_2]) |
the processes at one time | at= if given, else tdfs4ds.FEATURE_STORE_TIME if set, else the database time (read once) |
no: the time is injected into every manager view the processes read, then the cursors are put back |
run(pid, at='2024-03-31') |
one process at that time | at |
no |
run(pid) |
one process | FEATURE_STORE_TIME if set, else the current date of the TimeManager recorded for the process, else real time |
no |
run(pid, time_manager=tm) |
one process at the manager's date | the manager's current date | no (a soft clone of that manager is set to the date for the run) |
at= and time_manager= cannot be passed together, and run takes a process
(or a list) or data_domain=, not both.
run(pid) after a roll-out recomputes the last historical date
After roll_out the cursor stands on the last date of the calendar, and the
follow-up already holds a COMPLETED row for it. run(pid) alone computes that
date again, finds it done and skips it. To refresh "now", use
run(data_domain=...) (database time) or run(pid, at=...).
The production pattern¶
-
Build the history once, from the first date of the calendar to today:
-
Refresh on a schedule. The scheduler calls one
runper tick:tdfs4ds.run(data_domain='SALES') # every process, one "now" tdfs4ds.run(data_domain='SALES', at='2024-04-01') # or a business date you chooseNothing moves, so the next
roll_outstep is unchanged. -
Keep future dates out of the calendar. A date in the calendar is a date the next
roll_outwill compute. Add a date when it becomes current (load_time_steps), not before.
Not run(pid) alone
Without at=, run(pid) uses the recorded manager's cursor, the last historical date.
That date is already COMPLETED, so the run is skipped: it returns None and writes no
follow-up row. Schedule run(data_domain=...), run([...]) or run(pid, at='now').
Verified on Vantage 20 (tdfs4ds 0.3.6.18), with a calendar of past dates only:
- run(data_domain=...) computed at the database clock, including today's source rows.
- Each clone was back on its cursor afterwards.
- run(pid) was skipped.
- A valid_time_column process stored today's rows at their own event times. See
From prototype to production.
To run many processes in parallel, see the execution plan.
Declare one clock per data domain (0.3.6.0)¶
An alternative to attaching a TimeManager to each process, for the common case where the
processes of a data domain follow one business calendar. Attaching a manager per process
(time_manager=, the sections above) stays fully supported and gives more control: a
calendar of its own for a process, a hand-made clone, a manager shared on purpose. Declare
the domain's calendar once:
clock = TimeManager('SALES_CLOCK', 'MY_DB')
clock.load_time_steps(dates_df, 'BUSINESS_DATE') # once; dates_df: a teradataml DataFrame
tdfs4ds.set_domain_time_manager(clock) # for tdfs4ds.DATA_DOMAIN
From then on:
upload_featuresneeds notime_manager=. It walks the source view's lineage (through intermediate views) and finds the manager the view reads. When that is the domain clock, the process gets its own soft clone of it (<process view>_TM, next to the view: same dates, own cursor) and its view is rewritten to read the clone, with a log line. Write the process SQL against the clock itself:WHERE A.EVENT_DATE <= (SELECT BUSINESS_DATE FROM MY_DB.SALES_CLOCK). Atime_manager=passed explicitly is paired as before 0.3.6.0, even when it is the clock: no clone, sotm.update(i); run(pid)keeps following it.soft_clone=Trueasks for the clone anyway;soft_clone=Falserefuses it for a detected clock.roll_out(data_domain='SALES')(orroll_out()fortdfs4ds.DATA_DOMAIN) builds the history of every process of the domain. The clock drives, and at each date every clone is moved to the same date. The processes of a date run in dependency order.run(data_domain='SALES')computes every process of the domain at one time. That time is the database clock, read once, unless you passat='2024-03-31'. Each clone is swapped for that literal date for the duration of the computation, then put back on its cursor. Nothing moves, so after a roll-out you can refresh "now" and the next roll-out step is unchanged.run([pid_1, pid_2], at=...)does the same for a list.
tdfs4ds.roll_out(data_domain='SALES') # history, date by date
tdfs4ds.run(data_domain='SALES') # everything at one "now"
tdfs4ds.run([pid_7], at='2024-03-31', force_compute=True) # one process, a past date
run over a list returns {process_id: 'COMPLETED' | 'FAILED: ...' | 'SKIPPED: ...'}:
- Order: the processes run one after the other, in dependency order from the lineage
graph.
order='given'keeps yours. - Failures: a failure skips the processes downstream of it.
on_failure='raise'raisesFeatureIngestionErrorafter the list,'stop'stops at the first failure. - Processes reading no TimeManager are computed on the current source data and stored at the same time, with a warning.
- A manager read outside the run: when a manager is also read by a process outside the list, that process is named. While the run lasts, that process would read the literal date.
| Function | What it does |
|---|---|
set_domain_time_manager(tm, data_domain=None) |
declares the clock (stored in the optional table FS_DATA_DOMAIN_SETTINGS) |
get_domain_time_manager(data_domain=None) |
the clock, or None |
detach_domain_time_manager(data_domain=None) |
removes it; processes keep their clones |
align_domain_time_managers(data_domain=None, dry_run=True) |
gives processes registered before the clock their own clone |
clone_shared_view_time_manager(view, dry_run=True) |
one clone for the processes reading the clock through a shared view (0.3.6.8) |
domain_processes(data_domain=None) |
the processes of a domain (primary store) |
get_process_info(pid)['DOMAIN_TIME_MANAGER'] |
the clock of the process's domain |
Processes that read the clock through a shared view. When a view of yours filters a
source with the clock (WHERE d <= (SELECT BUSINESS_DATE FROM <clock>)) and several
processes read that view, none of them can get its own clone: rewriting the view for one
process would rewrite it for all. They keep the clock and share its cursor. Their values
are right, but a run of some of them at another date is seen by the others while it
lasts. upload_features says so, naming the view and its other readers, and the Overview
and the workflow assessment (processes_share_time_filtered_view) list them. Three ways
out:
- A cursor per process (your SQL): remove the date filter from the view, expose the date column and filter in each process view; each process then gets its own clone at registration. Or give each process its own copy of the view.
- One cursor for the view's readers:
tdfs4ds.clone_shared_view_time_manager('<db>.<view>', dry_run=True)shows the plan;dry_run=Falsemakes one soft clone<view>_TM, rewrites only the clock reference inside the view (it is never copied), and records the clone for every process reading it. They stay together, apart from the clock and from the other processes, androll_out(data_domain=...)keeps the clone in step. A process registered later on the view is recorded on that clone.
An object that already has the clone's name is reused only when it is a soft clone over
the same dates; a table, another view, or a clone of another calendar is refused and left
unchanged (pass clone_name=). The same check guards the clone upload_features makes
for each process.
What can interrupt the swap. A literal date is a REPLACE VIEW of the clone that
changes only the selected value: the view still reads FROM <table> WHERE TIME_ID = n.
Lineage to the table of dates holds during the run, and if the run is killed the next
run / roll_out (or TimeManager('<clone>', '<db>').restore_cursor()) puts it back.
run(pid, time_manager=clock) for a process reading a clone of that clock sets the
clone to the clock's date for the run (it used to warn and stamp a date the view did not
compute at), like roll_out moves clones with the manager it drives.
Documentation. A clone means what its clock means: the documentation pipeline copies
the clock's documentation onto it (PROPAGATED), with no LLM call per clone. Document the
clock once (set_object_documentation); a clock without documentation leaves its clones
to the usual path.
In the admin app. The feature catalog's process card shows the clock of the process's domain and how the process stands with it (reads the clock, its own clone, no TimeManager, or another calendar); the dataset builder lists the domain clocks first among the TimeManagers a dataset can follow; the Overview's Time drivers lists each clock with the processes on and off it.
Migration. plan_migration / migrate_objects carry the domain clock: the clones and
their table of dates come with the processes, the clock view is recreated over that table
at its cursor and declared for the target domain.
When the clone cannot be made. A process view that reads the clock only through an intermediate view keeps the clock (that view may be shared by other processes). It is still rolled out and run with the domain, but its cursor is the clock's own.
Nothing changes for a domain without a clock:
| Usage | Behaviour |
|---|---|
run(pid), roll_out(pids, tm) |
unchanged (the calls they make are compared with 0.3.5.19 in the tests) |
upload_features(...) without time_manager= and no domain clock |
the manager the view reads is recorded (new; tdfs4ds.TIME_MANAGER_DETECT = False turns it off) |
roll_out with several processes |
sorted by dependency (stable: a list in a valid order is unchanged; order='given' keeps it) |
| soft clone in another database than its table | now found and moved correctly (it used to look for the table in the view's database) |
A cursor of its own¶
Processes on one manager view share one cursor. A process that must move at its own pace (a backfill, a faster cadence) gets a clone and a rewritten view:
tdfs4ds.split_time_manager([pid], 'SALES_CLOCK', clone_mode='soft', dry_run=True) # the statements
tdfs4ds.split_time_manager([pid], 'SALES_CLOCK', dry_run=False)
tdfs4ds.align_domain_time_managers('SALES', dry_run=True) # processes registered before the clock
A soft clone keeps the same dates (it reads the clock's table); a hard clone copies
them. A process that reads the manager only through an intermediate view is reported
not_direct and left alone. See
Giving processes their own cursor.
Processes that share a time-filtered view¶
When one view filters a source with the clock and several processes read it, none of them can get its own clone: they share one cursor. To give them one clone together:
tdfs4ds.clone_shared_view_time_manager('MY_DB.SHARED_VIEW', dry_run=True) # the plan
tdfs4ds.clone_shared_view_time_manager('MY_DB.SHARED_VIEW', dry_run=False)
Or move the date filter out of the shared view and into each process view; each process then gets its own clone at registration.
A dataset that follows the clock¶
upload_features(..., dataset_view_name='db.ds', dataset_time_manager=True) builds the
dataset on the process's TimeManager. The setting is recorded for the process, so every
later run() and roll_out() keeps it; change it with
tdfs4ds.set_process_options(pid, dataset_time_manager=True). A dataset already built at
the current valid time is left as it is, with a warning that names rebuild_dataset.
After a roll-out, moving the manager returns the values of that date with no re-run. See
A dataset that follows the TimeManager.
With a FilterManager¶
A process segmented by a FilterManager computes every segment of the date it runs at.
roll_out(..., filtermanager=fm) updates the filter at each date, and run goes through
the segments of the one date. There is nothing to write around them. See
Combining with FilterManager.
Common mistakes¶
| Mistake | What happens | What to do |
|---|---|---|
| Computing dates out of order, or an earlier date after a later one | A run at date t writes from t onward and rewrites the later periods of the entities it produces | Replay from the first date: roll_out(..., time_id_start=1, force_compute=True) |
| First run of a process at the last date, then a roll-out over earlier dates | A history is built forward only; roll_out refuses with a ValueError naming the processes |
rebuild_history=True, or time_id_start= at the first stored date. Register with run_now=False to avoid it |
| A TimeManager the process view does not read | The values would carry a date they were not computed at | tdfs4ds.TIME_MANAGER_CHECK: 'warn' (default: runs, records no pairing), 'error' (refuses), 'off'. Check with tdfs4ds.time_manager_dependency(pid) |
| A process registered before the clock existed | It reads the clock directly and shares its cursor | tdfs4ds.align_domain_time_managers(domain, dry_run=False) |
| A calendar that holds future dates | The next roll_out computes them |
Load dates as they become current |
FEATURE_STORE_TIME left set in the session |
It wins over the recorded manager: run(pid) is stamped with it |
Unset it, or pass at= |
| A manager also read by a process outside the list | While a run over the list lasts, that process would read the run's date |
run names it in a warning; give each process its own clone |
The Overview's Time drivers section and the workflow assessment
(process_not_on_domain_clock, processes_share_time_filtered_view) list what is off the
clock; see Assess workflow health.
What a run returns¶
run over a list or a domain returns {process_id: 'COMPLETED' | 'FAILED: ...' |
'SKIPPED: ...' | 'REFUSED: ...'}. The follow-up row of each process records the date in
VALIDTIME_DATE (NULL for a real-time run). Failure policies are in
Operate in production.