Skip to content

tdfs4ds.scheduling.changed

tdfs4ds.scheduling.changed

Which (process, business date) pairs were computed with SQL that has changed since (0.3.8.15).

roll_out(..., force_compute='changed') and run(..., force_compute='changed') recompute only those pairs; :func:changed_processes lists them without running anything.

What is seen. A process version is the SQL beneath the process view (the view and the views it reads, managers set aside: process_sql). A run belongs to the version in force when it STARTED (process_sql.version_in_periods, the rule of value_version). A business date is stale for a process when its latest successful run at that date (COMPLETED or COMPLETED,0 rows, per FilterManager segment) was made under another version than the current one. The current version is the LIVE chain (read from the view definitions, nothing written), so a REPLACE VIEW made since the last capture is seen.

From t onward. A run at date d rewrites every later period of the values it writes (the MERGE's rule), so a process stale from d is recomputed at every completed date >= d, in date order. Every process transitively downstream of it in the same data domain (lineage graph; reference processes DOMAIN_ROLL_OUT = N left out, as run_order.with_downstream does) is stale from d too, for the dates it has completed runs at.

What is not seen (use force_compute=True): corrected source data, a changed function, model or table operator, changed manager contents (calendar, filter values), PROCESS_SQL_VERSIONING off, processes reading their valid time from a column (valid_time_column), dates computed before SQL versioning existed for the process. Those processes are reported not_decided and treated as unchanged.

Layers: :func:stale_runs (pure), :func:collect_changed_inputs (only reads, fail-open per input), :func:changed_plan / :func:changed_processes (both). Nothing here writes to the database.

SQL_CHANGED module-attribute

SQL_CHANGED = 'sql_changed'

UPSTREAM_CHANGED module-attribute

UPSTREAM_CHANGED = 'upstream_changed'

NEVER_RUN module-attribute

NEVER_RUN = 'never_run'

NOT_DECIDED module-attribute

NOT_DECIDED = 'not_decided'

REASONS module-attribute

REASONS = (SQL_CHANGED, UPSTREAM_CHANGED, NEVER_RUN, NOT_DECIDED)

FORCING_REASONS module-attribute

FORCING_REASONS = (SQL_CHANGED, UPSTREAM_CHANGED)

COLUMNS module-attribute

COLUMNS = ['PROCESS_ID', 'VIEW_NAME', 'DATA_DOMAIN', 'REASON', 'DETAIL', 'FIRST_DATE', 'N_DATES']

FORCE_TRUE_ADVICE module-attribute

FORCE_TRUE_ADVICE = 'force_compute=True'

to_utc

to_utc(x)

A UTC pandas.Timestamp of x, or None (missing, unreadable, or an open end in year 9000+).

to_wall

to_wall(x)

The wall-clock time of x (its own offset dropped), naive, or None. A naive valid time (a FEATURE_STORE_TIME without offset) is stored in the session's time zone and read back with that zone: it compares with this wall-clock time, not with UTC.

_version_number

_version_number(v)

_periods

_periods(rows) -> list

Stored versions as version_in_periods periods; tuples (version, valid_from, valid_to, chain_hash) or dicts with those names (PROCESS_VERSION/VALID_FROM/VALID_TO/CHAIN_HASH or VALIDSTART/VALIDEND).

_current_of

_current_of(cur) -> dict

{"version", "hash", "error"} from an int, a dict, or None.

_label

_label(v) -> str

_run_parts

_run_parts(r)

(pid, validtime_date, start, status, applied_filter) from a tuple or a dict row.

_segment

_segment(f) -> str

stale_runs

stale_runs(processes: dict, versions: dict, runs: Iterable, edges: Iterable, domains=None, *, current: Optional[dict] = None) -> dict

{process_id: record} of the processes to recompute (or that cannot be judged). Pure.

  • processes: {pid: {"view", "data_domain", "valid_time_column": bool, "versioning": bool, "reference": bool, "error": str | None}} (reference = DOMAIN_ROLL_OUT = N; error = an input that could not be read for this process).
  • versions: {pid: [(version, valid_from, valid_to, chain_hash), ...]} (FS_PROCESS_SQL).
  • current: {pid: {"version", "hash", "error"}} the live chain (version None and hash set = a change not captured yet); an int is read as the version.
  • runs: follow-up rows (pid, validtime_date, start_datetime, status, applied_filter).
  • edges: process-level (upstream, dependent) pairs.
  • domains: when given, only processes of these data domains are reported.

A record: {"process_id", "view", "data_domain", "reason" (sql_changed | upstream_changed | never_run | not_decided), "detail", "first_date", "dates" (sorted UTC timestamps, every completed date >= first_date), "realtime" (None, or {"detail"} when real-time runs were made under an older version: they are not replayable per date, the next real-time run recomputes them)}. Unchanged processes are not in the result.

forced_records

forced_records(stale: dict) -> dict

The records whose dates are recomputed (sql_changed / upstream_changed with a first date).

_after_first

_after_first(rec: dict, valid_time)

(valid_time >= first stale date, valid_time > first stale date) of a record, or None when valid_time cannot be read. A valid time without offset compares with the stored dates' wall-clock time (followup_open writes such a literal in the session's zone and it is read back with that zone); one with an offset compares in UTC.

is_forced

is_forced(stale: dict, process_id, valid_time) -> bool

True when (process_id, valid_time) must be recomputed: valid_time is at or after the process's first stale date (from t onward). A date that cannot be read is forced (safe side).

starts_before

starts_before(stale: dict, process_id, valid_time) -> bool

True when the process is stale from a date strictly before valid_time (a roll-out starting at valid_time would leave earlier stale dates).

stale_frame

stale_frame(stale: dict)

The records as the :func:changed_processes frame (pure).

log_lines

log_lines(stale: dict, where: str) -> list

[(level, text)] announcing what force_compute='changed' does (pure).

_clean_row

_clean_row(row: dict) -> dict

_domains_of

_domains_of(data_domain) -> Optional[List[str]]

_execute

_execute(sql: str)

_versions_sql

_versions_sql(pids) -> str

collect_changed_inputs

collect_changed_inputs(data_domain=None, processes=None, *, graph=None, proc_df=None) -> dict

The inputs of :func:stale_runs for processes (ids), or the processes of data_domain (a name, a list, True = tdfs4ds.DATA_DOMAIN), or every process of the primary store; plus their upstream processes of the same data domain (an upstream change makes them stale).

Reads: the process catalog (or proc_df), the lineage graph (or graph), the settings (valid_time_column, DOMAIN_ROLL_OUT) in one statement, the stored SQL versions in one statement, the live chain of each process (SHOW VIEW of its views, the read capture makes, without its write), the follow-up rows in one statement. Fail-open per input: a failed read makes the processes it concerns not_decided with the error, never changed or unchanged silently.

Returns {"requested", "processes", "versions", "current", "runs", "edges", "lineage_ok", "errors"}.

changed_plan

changed_plan(data_domain=None, processes=None, *, graph=None, proc_df=None) -> dict

:func:collect_changed_inputs then :func:stale_runs, restricted to the requested processes.

Without a readable lineage graph, a process that is not sql_changed itself cannot be said unchanged (an upstream change is not seen): it is not_decided. Returns {"stale", "edges", "errors", "lineage_ok"}.

changed_processes

changed_processes(data_domain=None, processes=None, display=True)

The processes whose stored values were computed with SQL that changed since (read-only).

Lists what roll_out(..., force_compute='changed') / run(..., force_compute='changed') would recompute, and why: one row per process with PROCESS_ID, VIEW_NAME, DATA_DOMAIN, REASON, DETAIL, FIRST_DATE, N_DATES. REASON is sql_changed (the SQL beneath the process view differs from the SQL its runs used: DETAIL 'v2 -> v3'), upstream_changed (an upstream process of the same data domain changed: recomputed from that upstream's first stale date), never_run or not_decided (cannot be judged, treated as unchanged). Unchanged processes are not listed.

data_domain: a name, a list, or True (tdfs4ds.DATA_DOMAIN); processes: process ids; neither = every process of the primary store.

Only a change of the SQL chain (the process view and the views beneath it) is seen. Corrected source data, a changed function or model, changed manager contents (calendar, filter values), PROCESS_SQL_VERSIONING off, processes reading their valid time from a column and dates computed before SQL versioning are not: recompute those with force_compute=True.