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 optionclose_absent_entitiesis 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 (checkclosed_entities).external_time_loop- one execution wrote several business dates for a process with no TimeManager: a loop aroundrun()instead ofroll_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 throughREPLACE VIEW;run()only repeats the last one.recursive_query-WITH RECURSIVE/RECURSIVE VIEWin 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.
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
¶
_LIT_RE
module-attribute
¶
_LIT_RE = re.compile('\'(?:[^\']|\'\')*\'|"(?:[^"]|"")*"|(?<![\\w$#.])\\d+(?:\\.\\d+)?(?:[Ee][+-]?\\d+)?(?![\\w$#])')
_VALUE_RE
module-attribute
¶
_VALUE_RE = re.compile('\'(?:[^\']|\'\')*\'|(?<![\\w$#.\\"])\\d+(?:\\.\\d+)?(?:[Ee][+-]?\\d+)?(?![\\w$#])')
_WORD_RE
module-attribute
¶
_WORD_RE = re.compile('\'(?:[^\']|\'\')*\'|\\"(?:[^\\"]|\\"\\")*\\"|--[^\\n]*|/\\*.*?\\*/|[A-Za-z_][\\w$#]*|\\d+(?:\\.\\d+)?|\\S', re.DOTALL)
_FROM_END
module-attribute
¶
_FROM_END = {'WHERE', 'GROUP', 'ORDER', 'HAVING', 'QUALIFY', 'UNION', 'INTERSECT', 'EXCEPT', 'MINUS', 'SAMPLE'}
mask_literals
¶
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 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
¶
[(kind, text, depth)] without spaces and comments; kind w word, s string,
q quoted identifier, n number, p punctuation. depth counts the open parentheses.
_close
¶
Index of the ) closing the ( at i (the end of the list when it never closes).
_relations
¶
The relations a SELECT member reads (names after FROM / JOIN / a comma of the FROM list).
_split_union
¶
The members of a recursive body: split at the top-level UNION [ALL].
recursions
¶
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
¶
Whether the SQL names the database clock (CURRENT_DATE / CURRENT_TIMESTAMP).
has_managers
¶
(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
¶
The prepared follow-up (workflow_assessment.prepare_followup) with an execution
column: the run each row belongs to (one call, execution_run_ids). Pure.
external_time_loops
¶
{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
¶
{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: text} of a process from its stored rows (steps in order, chunks joined,
inputs left out).
literal_only_versions
¶
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_without_flag from :func:collect_closed_inputs. Pure.
refresh_verdict
¶
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.
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
¶
(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.
external_write_rows
¶
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
¶
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
¶
{(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
¶
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
¶
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.