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()

CALENDAR_GAPS module-attribute

CALENDAR_GAPS = 'CALENDAR_GAPS'

CLOCK_BEHIND_STEPS module-attribute

CLOCK_BEHIND_STEPS = 1

DISPOSABLE module-attribute

DISPOSABLE = 'DISPOSABLE'

CatchUpRefused

Bases: ValueError

refresh_domain(until=...) found more missing business dates than max_catch_up and no catch_up= choice: nothing was written or run. .result is the refusal report.

result instance-attribute

result = result or {}

__init__

__init__(message, result=None)

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

delete_settings_sql

delete_settings_sql(data_domain: str, names=None, keep=(), purge: bool = False) -> str

Delete settings rows of data_domain (0.3.8.17, data domain removal): the names given, else every row except keep. purge=True deletes their history too (NONSEQUENCED), else only the current rows.

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.

_ts

_ts(x)

A tz-naive pandas Timestamp for a calendar / valid-time value, or None. Pure.

_day

_day(x) -> Optional[str]

read_gaps

read_gaps(data_domain=None) -> List[str]

The business dates a catch_up='latest' refresh skipped (setting CALENDAR_GAPS). Never raises.

gaps_sql

gaps_sql(data_domain, existing, new) -> Optional[str]

The statement recording new gaps beside the existing ones, or None when there is nothing new. Pure.

estimate_step_seconds

estimate_step_seconds(rows) -> Optional[float]

Seconds one business date costs the domain: for each process the median, over its dates, of the summed duration of its COMPLETED runs of that date; the medians added. rows: (PROCESS_ID, VALIDTIME_DATE, START_DATETIME, END_DATETIME). None without usable rows. Pure.

_read_estimate

_read_estimate(pids) -> Optional[float]

One batched read of the recent COMPLETED runs of pids; fail-open None.

_clocks_and_manager

_clocks_and_manager(data_domain)

refresh_domain

refresh_domain(data_domain=None, new_dates=None, *, until=None, max_catch_up: int = 3, catch_up=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, statuses} (statuses = what roll_out returned).

until (0.3.7.31) lets the clock's rule say which dates are due: 'now' or a date. The business dates that are due and not in the table are added (TimeManager.extend) and rolled out. Nothing due and nothing after the cursor: status='up to date', nothing runs. More than max_catch_up dates missing is refused unless catch_up='all' (add and roll out every one) or catch_up='latest' (add only the last, record the skipped dates in the setting CALENDAR_GAPS); a refusal raises :class:CatchUpRefused under on_failure='raise', the default in this mode. For the call, on_failure defaults to 'raise', check_upstream to True and tdfs4ds.TIME_MANAGER_CHECK is 'error'. Adds status, missing, next_due, estimate_seconds, gaps_recorded to the result.

change_domain_calendar

change_domain_calendar(data_domain, calendar, *, until='now', dry_run: bool = True, force: bool = False) -> Dict

Change the calendar of the clock of data_domain in place (0.3.7.31): monthly -> weekly without touching a process view. TimeManager.change_calendar on the clock, plus the domain checks: the recorded gaps (CALENDAR_GAPS) that are not dates of the new rule are dropped, and the processes of OTHER data domains reading the same table of dates are named (their dates change too). dry_run=True (default) plans and writes nothing; the replay is never run.

_domains_with_clock

_domains_with_clock() -> List[str]

Data domains that have a clock (one read of the settings table). Fail-open.

_refresh_until

_refresh_until(data_domain, until, max_catch_up, catch_up, dry_run, kw) -> Dict

build_domain_clock_status

build_domain_clock_status(data_domain, clock, rule, inferred, calendar, cursor, missing, next_due, gaps, processes, completed) -> Dict

The status dict from what :func:collect_domain_clock_status read. Pure.

calendar: [(time_id, date)]; processes: [(process_id, view)]; completed: {process_id: [dates]} (business dates with a successful run).

collect_domain_clock_status

collect_domain_clock_status(data_domain=None) -> Dict

The reads behind :func:domain_clock_status; fail-open, a read that fails is an empty part.

domain_clock_status

domain_clock_status(data_domain=None) -> Dict

Read-only state of a data domain's clock: its rule (and whether it was inferred), the dates held, the cursor, the dates due by now that are missing, the next due date, the gaps a catch_up='latest' refresh recorded, and per process the last business date computed and how many calendar dates it is behind. Never raises: a part that cannot be read is None / empty.

disposable_setting

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

{by, at} recorded when data_domain was declared disposable, or None (not disposable, no settings table, or unreadable). Never raises.

is_disposable

is_disposable(data_domain=None) -> bool

Whether data_domain was declared disposable (create_data_domain(..., disposable=True) or :func:set_data_domain_disposable). Never raises.

_db_user

_db_user() -> Optional[str]

disposable_value

disposable_value(user: Optional[str], at: Optional[str] = None) -> str

The JSON recorded for a disposable domain: who declared it and when (UTC). Pure.

set_data_domain_disposable

set_data_domain_disposable(data_domain, disposable: bool, *, dry_run: bool = False) -> Dict

Declare a data domain disposable (an experiment, removable in one call by :func:tdfs4ds.remove_data_domain), or not any more.

disposable=True records the setting DISPOSABLE (who, when) in FS_DATA_DOMAIN_SETTINGS; a domain that is already disposable keeps its first record. disposable=False deletes it: that is how an experiment is kept (its removal then goes through plan_removal and apply_removal like any real domain). The domain may already hold processes: this is the deliberate way to declare such a domain disposable. Returns {data_domain, disposable, sql, written}.