Skip to content

tdfs4ds.process_usage

tdfs4ds.process_usage

Processes used from outside tdfs4ds: can run() and roll_out() still refresh them?

A process whose registered form no longer reproduces its data cannot be refreshed by run() / roll_out(): they refresh nothing, or refresh wrongly, with no error. The causes are always the same misuse:

  • closed_without_flag - entities whose every validity period is closed in the storage tables while the option close_absent_entities is off: something outside the process ended them (a DELETE, a hand-made UPDATE), and a run will not reproduce it. Needs a read of the storage tables (check closed_entities).
  • external_time_loop - one execution wrote several business dates for a process with no TimeManager: a loop around run() instead of roll_out().
  • external_segment_loop - one execution computed the same business date several times for a process with no FilterManager: a loop over segments instead of a FilterManager.
  • view_rewritten_between_runs - several stored SQL versions that differ only by literals, about one run each: the value changes through REPLACE VIEW; run() only repeats the last one.
  • recursive_query - WITH RECURSIVE / RECURSIVE VIEW in the SQL chain: a loop inside SQL when it only generates dates or a sequence.

A scheduled run (one date per run across days, FEATURE_STORE_TIME set) raises nothing: the loop detectors only look inside one execution (:func:tdfs4ds.process_store.process_followup.execution_run_ids).

Same layers as the rest of the workflow assessment: collect_* is the only I/O (a failed read is an unverifiable entry), *_findings and :func:refresh_verdict are pure. No language model: counts, hashes and token walks, fixed texts; nothing here runs a fix.

LOOP_MIN_DATES module-attribute

LOOP_MIN_DATES = 3

SEGMENT_LOOP_MIN_RUNS module-attribute

SEGMENT_LOOP_MIN_RUNS = 3

VERSION_LOOP_MIN_VERSIONS module-attribute

VERSION_LOOP_MIN_VERSIONS = 3

CLOSED_MIN_ENTITIES module-attribute

CLOSED_MIN_ENTITIES = 1

CLOSED_SAMPLE module-attribute

CLOSED_SAMPLE = 5

CLOSED_MAX_SECONDS module-attribute

CLOSED_MAX_SECONDS = 60

CLOSED_MAX_SPOOL_BYTES module-attribute

CLOSED_MAX_SPOOL_BYTES = 10 * 1024 ** 3

KIND_LABELS module-attribute

KIND_LABELS = {'closed_without_flag': 'Entities closed in storage while close_absent_entities is off', 'validity_gap_without_flag': "Gaps in entities' validity history while close_absent_entities is off", 'writes_outside_run': 'Feature tables written outside a run (query log)', 'external_time_loop': 'Several business dates written by one execution without a TimeManager', 'external_segment_loop': 'Same business date computed several times by one execution without a FilterManager', 'view_rewritten_between_runs': 'Process view rewritten between runs (versions differ only by literals)', 'recursive_query': 'Recursive query in the process SQL'}

USAGE_KINDS module-attribute

USAGE_KINDS = ('external_time_loop', 'external_segment_loop', 'view_rewritten_between_runs', 'recursive_query')

CLOSED_KINDS module-attribute

CLOSED_KINDS = ('closed_without_flag', 'validity_gap_without_flag', 'writes_outside_run')

REFRESH_KINDS module-attribute

REFRESH_KINDS = USAGE_KINDS + CLOSED_KINDS

_LIT_RE module-attribute

_LIT_RE = compile('\'(?:[^\']|\'\')*\'|"(?:[^"]|"")*"|(?<![\\w$#.])\\d+(?:\\.\\d+)?(?:[Ee][+-]?\\d+)?(?![\\w$#])')

_VALUE_RE module-attribute

_VALUE_RE = compile('\'(?:[^\']|\'\')*\'|(?<![\\w$#.\\"])\\d+(?:\\.\\d+)?(?:[Ee][+-]?\\d+)?(?![\\w$#])')

_WORD_RE module-attribute

_WORD_RE = compile('\'(?:[^\']|\'\')*\'|\\"(?:[^\\"]|\\"\\")*\\"|--[^\\n]*|/\\*.*?\\*/|[A-Za-z_][\\w$#]*|\\d+(?:\\.\\d+)?|\\S', DOTALL)

_FROM_END module-attribute

_FROM_END = {'WHERE', 'GROUP', 'ORDER', 'HAVING', 'QUALIFY', 'UNION', 'INTERSECT', 'EXCEPT', 'MINUS', 'SAMPLE'}

_u

_u(v) -> str

_clean

_clean(v) -> Optional[str]

_short

_short(view) -> str

_label

_label(pid, names) -> str

_finding

_finding(*a, **k)

_day

_day(t) -> str

_dates

_dates(keys, limit=5) -> str

mask_literals

mask_literals(text: str) -> str

text normalised (comments out, spaces collapsed, case folded outside literals) with every string and number replaced by a placeholder, and a list of placeholders collapsed to one. Two SQL texts that differ only by their literals are equal after it.

literal_differences

literal_differences(a: str, b: str, limit: int = 3) -> List[tuple]

[(literal in a, literal in b)] at the positions where the literals of two texts that :func:mask_literals makes equal differ (at most limit).

_tokens

_tokens(sql: str) -> List[tuple]

[(kind, text, depth)] without spaces and comments; kind w word, s string, q quoted identifier, n number, p punctuation. depth counts the open parentheses.

_bare

_bare(tok) -> str

_close

_close(toks, i) -> int

Index of the ) closing the ( at i (the end of the list when it never closes).

_name_at

_name_at(toks, i) -> tuple

(name, next index): a possibly qualified name starting at i.

_relations

_relations(member) -> List[str]

The relations a SELECT member reads (names after FROM / JOIN / a comma of the FROM list).

_split_union

_split_union(body) -> List[list]

The members of a recursive body: split at the top-level UNION [ALL].

recursions

recursions(sql: str) -> List[dict]

The recursive queries in sql: [{"name", "kind", "reads"}].

WITH RECURSIVE cte AS (seed UNION ALL step) and RECURSIVE VIEW v AS (...) whose step reads its own name. kind is generator when the step reads nothing but its own name (it generates dates or a sequence: a loop inside SQL) and walk when it joins a table (a hierarchy or a graph walk); reads are those tables. Pure.

reads_database_clock

reads_database_clock(text: str) -> bool

Whether the SQL names the database clock (CURRENT_DATE / CURRENT_TIMESTAMP).

has_managers

has_managers(row: Optional[dict], chain: Optional[dict], driver: Optional[str] = None) -> tuple

(time, filter): whether the process has a TimeManager / FilterManager, declared in the catalog row or read by its live chain. A manager of unknown kind (a view reading one *_HIDDEN table) counts for both, so a doubt never becomes a finding.

executions

executions(fu: DataFrame) -> pd.DataFrame

The prepared follow-up (workflow_assessment.prepare_followup) with an execution column: the run each row belongs to (one call, execution_run_ids). Pure.

_completed

_completed(fu: DataFrame) -> pd.DataFrame

external_time_loops

external_time_loops(fu: DataFrame, no_time_manager: Iterable[str]) -> Dict[str, dict]

{pid: {"dates", "n", "start"}} for the processes with no TimeManager whose one execution wrote at least :data:LOOP_MIN_DATES business dates (the largest execution).

external_segment_loops

external_segment_loops(fu: DataFrame, no_filter_manager: Iterable[str]) -> Dict[str, dict]

{pid: {"date", "n"}} for the processes with no FilterManager that computed one business date at least :data:SEGMENT_LOOP_MIN_RUNS times in one execution. A real-time run has no business date to share, so it is never counted.

version_texts

version_texts(rows: list) -> Dict[int, str]

{version: text} of a process from its stored rows (steps in order, chunks joined, inputs left out).

literal_only_versions

literal_only_versions(texts: Dict[int, str]) -> Optional[dict]

The largest set of versions that differ only by literals: {"versions", "changes"} or None. texts: {version: text}. Needs at least :data:VERSION_LOOP_MIN_VERSIONS versions with distinct text and the same masked text.

version_loop_findings

version_loop_findings(versions: Dict[str, list], texts: Dict[str, Dict[int, str]], fu: DataFrame, names=None) -> List[dict]

view_rewritten_between_runs. versions: {pid: [{"PROCESS_VERSION", "VALID_FROM", "VALID_TO"}]}, texts: {pid: {version: text}}. The set must hold at least :data:VERSION_LOOP_MIN_VERSIONS versions that each ran, mostly once.

usage_findings

usage_findings(inputs: dict, fu: DataFrame, names=None, drivers: Optional[dict] = None) -> List[dict]

The findings of the usage check (everything but the storage read).

inputs: {"processes": frame, "chains": {pid: {"row", "chain"}}, "versions", "version_texts"}; fu: the prepared follow-up; drivers: {pid: TimeManager} read by the time-driver model. A process whose chain was not read keeps its catalog managers only. Pure.

closed_entities_findings

closed_entities_findings(data: dict, names=None) -> List[dict]

closed_without_flag from :func:collect_closed_inputs. Pure.

refresh_verdict

refresh_verdict(findings: Iterable[dict], checked: bool = True) -> dict

Can run() / roll_out() refresh this process? From its findings (those of the kinds in :data:REFRESH_KINDS): not refreshable (an error), at risk (a warning), refreshable (nothing, or information only), not checked when checked is False. {"verdict", "reasons"}. Pure.

verdicts

verdicts(findings: List[dict], pids: Iterable[str], checked: bool = True, storage_checked: bool = True) -> Dict[str, dict]

:func:refresh_verdict for every process in pids. Pure.

_rows

_rows(sql) -> list

_err

_err(exc) -> str

read_version_texts

read_version_texts(versions: Dict[str, list], min_versions: int = VERSION_LOOP_MIN_VERSIONS) -> tuple

({pid: {version: text}}, unverifiable): the stored SQL of every version of the processes with at least min_versions versions (one read).

collect_usage_inputs

collect_usage_inputs(proc: DataFrame, chains: Optional[dict], versions: Optional[dict]) -> tuple

(inputs, unverifiable) for :func:usage_findings, from what the assessment already read (catalog frame, live chains, stored versions) plus the stored texts of the versions.

closed_entities_sql

closed_entities_sql(database, table, entity_cols, feature_ids, process_id, sample: bool = False) -> str

The storage read of closed_without_flag: the entities of the process whose every period is closed for at least one of its features (MAX(ValidEnd) not after now), as a count or the first :data:CLOSED_SAMPLE. The temporal qualifier sits inside the derived table: outside, it is Error 9330. Pure.

validity_gaps_sql

validity_gaps_sql(database, table, entity_cols, feature_ids, process_id, sample: bool = False) -> str

The storage read of validity_gap_without_flag: entities of the process with a period starting after every earlier period of the same feature has ended, as a count or the first :data:CLOSED_SAMPLE (with the end and the start around the gap). Pure.

_gap_sample

_gap_sample(row, entity_cols) -> str

external_write_rows

external_write_rows(rows, tables_by_pid: Dict[str, Iterable[str]]) -> List[dict]

Query-log rows (type, time, user, text) per storage table of the processes given, matched on the whole table name (_ is a LIKE wildcard: the read also returns FS_TIME_MANAGER). [{table, pids, statements, last, user, text}]. Pure.

collect_external_writes

collect_external_writes(proc: DataFrame, features: DataFrame, days: int = 90) -> dict

Deletes, updates and inserts on the processes' storage tables with no TDFS4DS query band, from DBC.QryLogV. MERGE is left out: it is what older clients' runs issue. A log that cannot be read is unverifiable; an empty one only says nothing was logged. {"rows", "unverifiable"}.

process_feature_tables

process_feature_tables(proc_row: dict, features: DataFrame) -> Dict[tuple, dict]

{(DB, TABLE): {"database", "table", "entity", "ids"}}: where a process writes, from the feature catalog rows of its (data domain, entity, feature) triplets. Pure.

collect_closed_inputs

collect_closed_inputs(proc: DataFrame, features: DataFrame, emit=None, read_flag=None) -> dict

The storage level of closed_without_flag: per process whose option is off and per storage table it writes, the entities with no open period (count and sample). One EXPLAIN then one read each; above the limits of :mod:tdfs4ds.utils.explain_cost the table is not read and is listed as not verified. {"rows", "unverifiable", "checked"}.

process_usage_for

process_usage_for(process_id: str, closed: bool = False, days: int = 90) -> dict

The refresh check of one process, from its follow-up and stored versions only: {"verdict", "reasons", "findings", "checked", "unverifiable"}. closed adds the storage read of closed_without_flag (the card offers it as a button). Never raises.