Skip to content

tdfs4ds.process_store.followup_grid

tdfs4ds.process_store.followup_grid

The skip decision of a whole roll_out, read before its first step (0.3.8.1).

roll_out used to ask, at every (process, date), whether the pair is already final: at least one statement per pair, so a domain already COMPLETED at every date still cost round trips per step (about 3 s per skipped step from a remote client). The grid below answers the same question for every pair of the call with a handful of statements. It only ever says "done" (the pair is then skipped exactly as the per-step decision would skip it); every other pair goes through the historical per-step statements, unchanged, and so does every pair when the grid cannot be trusted.

A pair counts as done under the rules of nothing_to_compute / final_runs_at (same counts, same segment matching, same upstream rule):

  • a COMPLETED row at that valid time (with a FilterManager: every segment holds one);
  • or, with no COMPLETED row, a COMPLETED,0 rows row that no upstream process followed (with a FilterManager: every segment without a COMPLETED row holds such an empty row).

The second kind depends on what upstream processes write at the SAME valid time, which a step of this very call can change: those pairs are flagged volatile and trusted only while no step of that valid time has computed anything (:func:mark_date_dirty). A step of this call only ever adds COMPLETED rows, so the first kind never needs to be asked again. A row written or deleted by another session while the call runs is a race the per-step statements had as well (they read at the moment of the step; the grid at the start), and a decision "todo" is never taken from the grid.

Layers: the SQL builders and the decisions are pure; :func:build_call_grid is the only reader and never raises.

EMPTY_INGESTION_STATUS module-attribute

EMPTY_INGESTION_STATUS = 'COMPLETED,0 rows'

GRID_KEY module-attribute

GRID_KEY = 'skip_grid'

_CHUNK_DATES module-attribute

_CHUNK_DATES = 60

_CHUNK_LEGS module-attribute

_CHUNK_LEGS = 20

logger_safe

logger_safe(level, message, *args, **kwargs)

Wrapper around the global logger that only emits logs when tdfs4ds.DISPLAY_LOGS is True. level is a string like "info", "error", etc.

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.

_call_memo

_call_memo()

_followup_source

_followup_source() -> Optional[str]

The run history of every attached store that offers one, as a derived table (FS_V_FOLLOW_UP of each, tagged FEATURE_STORE), or None with a single store -- then the primary's table is read exactly as before.

Run rows are keyed by PROCESS_ID, a UUID, so a row always belongs to the process of the store it came from.

_resolved_upstream

_resolved_upstream(process_id, resolve_upstream)

Sorted upstream process ids (the process itself left out), or None when unknown.

final_empty_sql

final_empty_sql(process_id: str, valid_time, upstream, filtermanager: Optional[object] = None) -> str

SELECT COUNT(*) of the COMPLETED,0 rows rows of process_id at valid_time (current segment with filtermanager) that no run of an upstream process followed: no upstream row COMPLETED at the same valid time started after the empty row ended. With no upstream, every empty row counts. Pure.

missing_final_segments_sql

missing_final_segments_sql(process_id: str, valid_time, filtermanager, upstream) -> str

:func:missing_segments_sql for a segment counting as done when it has a COMPLETED row OR a COMPLETED,0 rows row that no run of an upstream process followed (see :func:final_empty_sql).

_literal_list

_literal_list(values) -> str

_date_case

_date_case(valid_times, col: str) -> str

CASE WHEN col = 'vt' THEN k ...: the position of the valid time in valid_times, compared with the very = the per-step statements use (the literal converted to the column's type).

grid_plain_sql

grid_plain_sql(process_ids, valid_times) -> str

One statement for every process without a FilterManager and every valid time: (PROCESS_ID, k, n COMPLETED, n COMPLETED,0 rows) where k is the position of the valid time. The rows completed_state_sql counts, for all the pairs at once. Pure.

grid_segments_sql

grid_segments_sql(process_id: str, valid_times, filtermanager) -> str

followup_grid_sql for every valid time at once: (filter_id, k, n COMPLETED, n COMPLETED,0 rows), only for the segments that have such a row (the caller counts the others as zero). Pure.

decide_plain

decide_plain(counts, upstream)

The skip decision of a process with no FilterManager from its counts (n_completed, n_empty), as final_runs_at takes it. ("done", volatile), ("todo", None), or ("ask", None): done when the empty run is still the last word, which needs the upstream statement. upstream: sorted upstream process ids, or None when unknown (then an empty run is recomputed). Pure.

decide_segments

decide_segments(per_segment, nb_filters, upstream)

The skip decision of a process with a FilterManager from {filter_id: (n_completed, n_empty)} over ALL its segments, as nothing_to_compute takes it. Same return as :func:decide_plain. Pure.

_needs_upstream_plain

_needs_upstream_plain(c) -> bool

_needs_upstream_segments

_needs_upstream_segments(per) -> bool

_leg

_leg(sql: str, key: str) -> str

sql (a SELECT COUNT(*) FROM ...) with the key of the pair in front of its count, to be stacked with UNION ALL (a table-less SELECT is not allowed in a union).

build_call_grid

build_call_grid(entries, valid_times, run_sql=None, resolve_upstream=None)

The pairs (process_id, valid time) of a roll_out that are already final, from a few statements.

entries: [(process_id, filtermanager or None)]; valid_times: the valid-time text of each step (what run sees as FEATURE_STORE_TIME). Returns {(process_id, valid_time text): volatile} holding only the pairs the per-step decision would skip, or None when the grid cannot be trusted (read-only stores attached, any read failing): the caller then keeps the per-step statements. Never raises.

install_call_grid

install_call_grid(grid) -> None

Keep grid (from :func:build_call_grid) for the running call. No call memo, or None: nothing.

grid_says_done

grid_says_done(process_id, valid_time) -> bool

True when the call's grid already knows (process_id, valid_time) is final, and nothing since could have changed it. Never reads the database.

mark_date_dirty

mark_date_dirty(valid_time) -> None

A step of this valid time computed something: decisions resting on what upstream processes wrote at the same valid time are asked again, with the per-step statements.

date_is_done

date_is_done(process_ids, valid_time) -> bool

True when :func:grid_says_done holds for every process of process_ids at valid_time.