Skip to content

tdfs4ds.data_domain_settings

tdfs4ds.data_domain_settings

One clock per data domain: FS_DATA_DOMAIN_SETTINGS (0.3.6.0).

A data domain may declare a domain clock: a TimeManager whose dates every process of the domain follows. Each process then reads its own soft clone of it (same table of dates, own cursor), made by upload_features:

  • roll_out(data_domain=...) moves the clock and every clone date by date;
  • run([...]) / run(data_domain=...) computes every process at one fixed time, swapping each clone for that date during the computation (see utils.time_management.literal_time_managers);
  • a partial run never moves another process's cursor.

Storage: a key/value valid-time table, PRIMARY INDEX (DATA_DOMAIN), the FS_PROCESS_SETTINGS pattern (whose key is a PROCESS_ID, too short for a domain name). It is optional: created at setup() and by connect() when missing, a failed CREATE is one warning, remembered and not retried. Without the table (or without a row) a domain has no clock and everything behaves as before 0.3.6.0. Every INSERT names its columns, so a later setting is a new SETTING_NAME, never a new column.

TIME_MANAGER module-attribute

TIME_MANAGER = 'TIME_MANAGER'

SETTING_NAME_LEN module-attribute

SETTING_NAME_LEN = 100

SETTING_VALUE_LEN module-attribute

SETTING_VALUE_LEN = 1000

_STATE module-attribute

_STATE: dict = {}

_WARNED module-attribute

_WARNED: set = set()

sql_literal

sql_literal(value)

Escape value for use inside a single-quoted SQL string literal.

For the DBC probes and catalog predicates that compare a name as data (WHERE DatabaseName = '…'). The caller supplies the surrounding quotes.

_table_name

_table_name() -> str

_qualified_table

_qualified_table() -> str

_key

_key() -> Optional[str]

reset_state

reset_state() -> None

Forget what was learnt about the table (tests, setup(), connect()).

_warn_once

_warn_once(key: str, message: str, *args) -> None

_execute

_execute(sql: str)

_domain

_domain(data_domain=None) -> str

data_domain_settings_ddl

data_domain_settings_ddl() -> str

data_domain_settings_creation

data_domain_settings_creation(existing: Optional[Iterable[str]] = None) -> bool

Create FS_DATA_DOMAIN_SETTINGS when missing. Never raises.

existing is the lower-cased object set connect() read from DBC: a table found there costs no CREATE. Returns whether the table is usable.

available

available() -> bool

Whether FS_DATA_DOMAIN_SETTINGS exists in the primary store (checked once per store).

read_settings_sql

read_settings_sql(data_domain: str) -> str

upsert_setting_sql

upsert_setting_sql(data_domain: str, name: str, value: str) -> str

Record (or change) one setting. Every column is named.

delete_setting_sql

delete_setting_sql(data_domain: str, name: str) -> str

clock_value

clock_value(tm) -> str

The JSON recorded for a TimeManager: where its view and its table of dates are.

parse_clock

parse_clock(value) -> Optional[Dict[str, str]]

The dict recorded by :func:clock_value, or None for a missing / unreadable value.

read_settings

read_settings(data_domain: str) -> Dict[str, str]

{SETTING_NAME: SETTING_VALUE} of data_domain. Fail-open: no table, no row or an unreadable table is an empty dict.

domain_clock

domain_clock(data_domain=None) -> Optional[Dict[str, str]]

{database, view, table_database, table} of the domain clock, or None. Never raises.

get_domain_time_manager

get_domain_time_manager(data_domain=None)

The TimeManager of the domain clock (rebuilt read-only), or None when the domain has none. data_domain=None = tdfs4ds.DATA_DOMAIN.

set_domain_time_manager

set_domain_time_manager(time_manager, data_domain=None, *, dry_run: bool = False) -> Dict

Declare time_manager the clock of a data domain.

From then on upload_features gives each process of the domain that reads this manager its own soft clone of it (same dates, own cursor), roll_out(data_domain=...) moves the clock and every clone date by date, and run([...]) / run(data_domain=...) computes every process at one time.

The clock must own its table of dates (a manager, not a soft clone of another one). Processes registered before keep their manager; align_domain_time_managers shows what an adoption would change. data_domain=None = tdfs4ds.DATA_DOMAIN; dry_run=True returns the statement without writing it. Returns {data_domain, clock, sql, written}.

detach_domain_time_manager

detach_domain_time_manager(data_domain=None, *, dry_run: bool = False) -> Dict

Remove the clock of a data domain (data_domain=None = tdfs4ds.DATA_DOMAIN). The processes keep their soft clones (each one is an ordinary TimeManager); only the automatic cloning and the domain-wide roll-out stop. dry_run=True returns the statement without executing it.

is_clock

is_clock(time_manager, clock: Optional[Dict[str, str]]) -> bool

Whether time_manager is the clock itself (its view), compared without case or quotes.

on_calendar

on_calendar(time_manager, clock: Optional[Dict[str, str]]) -> bool

Whether time_manager reads the clock's table of dates (the clock or one of its clones).

domain_processes

domain_processes(data_domain=None, proc_df=None) -> List[str]

Process ids registered in data_domain in the primary store (read-only stores are never run). data_domain=None or True = tdfs4ds.DATA_DOMAIN. proc_df: an already read process catalog (PROCESS_ID, DATA_DOMAIN), else it is read.

without_reference_processes

without_reference_processes(pids, where: str = 'roll_out') -> List[str]

Drop from pids the reference processes (setting DOMAIN_ROLL_OUT = N, 0.3.7.23) and log one info line naming them. One read of the setting for all processes; without the setting (or without its table) pids is returned unchanged and nothing is logged.

clone_name

clone_name(view_name: str) -> str

Name of the soft clone a process gets: <process view>_TM (cut to 128 characters).

compare_calendars

compare_calendars(mine, clock) -> Dict

How a manager's dates stand with the clock's (0.3.7.22). Pure.

mine / clock: business dates in TIME_ID order (formatted alike). Returns {'relation': 'identical'|'subset'|'other'|'unknown', 'missing_steps': [...], 'foreign': [...]}: missing_steps = the clock's steps (1-based) whose date mine does not hold, foreign = dates of mine the clock does not have.

_calendar

_calendar(table_database, table) -> Optional[List[str]]

The dates of a table of dates in TIME_ID order (formatted as a run stamps them), or None.

_view_ddl

_view_ddl(database, view) -> str

_cursor

_cursor(database, view) -> Optional[int]

The TIME_ID a manager view points at (its DDL), or None.

_is_literal

_is_literal(node) -> bool

_calendar_plan

_calendar_plan(pid, view, manager, tables, clock, clock_cal, dom)

(action, detail, replay, extra) for a process on manager, another manager than the clock.

_apply_extended

_apply_extended(out, extras, clock, clock_step, dry_run)

Run (or preview) the RESTORE, ALIGN and REPOINT rows, in that order. Updates ACTION/DETAIL.

align_domain_time_managers

align_domain_time_managers(data_domain=None, process_ids=None, *, dry_run: bool = True, graph=None, proc_df=None, cursors: bool = False, calendars: bool = False, exclude=None)

Give the processes registered before the domain clock their own soft clone of it.

For each process of the domain (or of process_ids) whose view reads the clock itself, a soft clone <view>_TM is made and the process view is rewritten to read it (split_time_manager). Processes reading a clone already, or no manager, or a manager on other dates, are reported and left alone. Returns a pandas DataFrame (PROCESS_ID, VIEW_NAME, READS, ACTION, DETAIL); dry_run=False applies the CLONE rows. data_domain=None = tdfs4ds.DATA_DOMAIN; graph / proc_df: an already loaded lineage graph / process catalog (read when omitted).

Opt-in (0.3.7.22). Without them the result is exactly the one above (five columns); with either one a REPLAY column is added:

  • cursors=True: a soft clone of the clock whose cursor is not at the clock's step is moved there (ALIGN). Nothing is recomputed; run(pid) then computes at the clock's date. A clone kept behind on purpose (split_time_manager) goes in exclude.
  • calendars=True: a process on another manager (OTHER) is compared date by date: the same dates -> REPOINT (a soft clone of the clock at the same date replaces that manager; the history is unchanged); a subset of the clock's dates -> REPOINT_REPLAY (the same, and REPLAY is the roll_out that computes the dates it never had); other dates -> KEEP_OWN_CALENDAR (never moved: it would change the valid times the next runs stamp; DETAIL names both ways forward). Several managers read -> SEVERAL.
  • either one: a manager view left on a literal date by an interrupted run(..., at=) gets a RESTORE row first (PROCESS_ID empty, VIEW_NAME = the manager).
  • exclude: process ids or manager views ('db.view') left alone (EXCLUDED).

It never drops a manager and never recomputes. A manager left with no reader shows in tdfs4ds.write_time_manager_report() as followed by nothing.

shared_views_of

shared_views_of(process_id: str, view_name: str, manager: Dict[str, str]) -> List[Dict]

The views between view_name and the TimeManager manager ({database, view}) that name the manager, each with the processes that read it (0.3.6.8): the reason a process reading the manager through them cannot get its own clone. The views come from the process view's own lineage (SHOW VIEW), the readers from FS_LINEAGE_GRAPH. Fail-open: [] when a lineage cannot be read.

shared_view_message

shared_view_message(process_id: str, view_name: str, manager: Dict[str, str], shared: List[Dict]) -> str

The warning for a process that reads a TimeManager through a view other processes share (0.3.6.8): what it means and the three ways out, none of them done automatically. One text, used at registration and by align_domain_time_managers.

clone_for_process

clone_for_process(process_id: str, view_name: str, clock: Dict[str, str], *, dry_run: bool = False, current: Optional[Dict[str, str]] = None, step: Optional[int] = None) -> Dict

Make the soft clone of the clock for one registered process and repoint its view.

The clone goes next to the process view (its database), named <view>_TM, at the clock's current step (clone_timer(clone_mode='soft', if_exists='skip'): an existing clone is reused). The process view is then rewritten to read the clone, its FS_TIME_MANAGER row records the clone and its lineage is refreshed (scheduling.unify._repoint_process_time_manager, what split_time_manager uses).

A process view that does not name the clock itself (it reads it through an intermediate view, which other processes may share) is not rewritten: it keeps the clock (not_direct; shared names the views and their readers, 0.3.6.8). An existing object named like the clone that is not a soft clone of the clock's dates is neither replaced nor used (refused). Never raises: {ok, clone, detail, not_direct, shared[, refused]}.

current (0.3.7.22): the manager the view names now ({database, view, table}), for a process moved onto the clock from another manager (align_domain_time_managers( calendars=True)); None = the clock itself. step: the clone's cursor (None = the clock's), so the process keeps computing at the same date.

refresh_domain

refresh_domain(data_domain=None, new_dates=None, *, dry_run: bool = False, **roll_out_kwargs) -> Dict

One call for the scheduled refresh (0.3.7.22): add the next business date(s) to the domain clock and roll them out.

new_dates are appended to the clock's table with TimeManager.add_time_steps (cursor and views untouched; every soft clone of the clock sees them, a hard copy does not); None adds nothing and rolls out the dates after the cursor. Then tdfs4ds.roll_out(data_domain=..., time_id_start=<first new TIME_ID or cursor + 1>, **roll_out_kwargs). data_domain may be a list: every clock must read the same table of dates, which gets the dates once. dry_run=True writes nothing and calls nothing; it returns the plan. Returns {data_domain, clock, added, skipped, time_id_start, rolled_out, dry_run, statements}.