Skip to main content

Module match_recognize

Module match_recognize 

Source

StructsΒ§

BoundMatchRecognize
BoundMeasure
A bound MEASURES item: an expression over the per-match synthetic row, its navigation slots, and the output name.
BoundSymbolDefinition
A bound DEFINE item: a pattern variable, the predicate over its DefineSlots, and the slots.
DefineSlot
One input a DEFINE predicate reads. A predicate is lowered to an expression over a synthetic row whose i-th column is produced by slots[i]; the executor materializes that row for each candidate row from the sorted partition and the in-progress match’s labels.
DefineSlotRewriter πŸ”’
Maps each InputRef in a bound DEFINE predicate to a DefineSlot: navigation placeholders (index >= nav_base) to their pre-resolved slot; variable-qualified columns to a self slot (the defined variable, or an unqualified/raw-input reference) or a running slot (another variable).
InputRefBlockCheck πŸ”’
Checks that every measure InputRef is pattern-variable-qualified (alias block >= 1). A reference into block 0 is the raw input β€” an unqualified or table-qualified column with no pattern-variable navigation meaning.
MeasureSlot
One navigation input that a measure expression reads. A measure is lowered to an expression over a synthetic row whose i-th column is produced by slots[i]; the executor materializes that row per match (the column values are only knowable once the match and its per-row labels are found) and then evaluates the expression.
NavExtractor πŸ”’
Extracts row-pattern navigation functions (PREV/NEXT/FIRST/LAST) from a DEFINE predicate AST, replacing each with a synthetic placeholder column and recording the corresponding DefineSlot. Functions are handled because they do not bind as ordinary scalar functions; plain variable-qualified columns are left to bind normally and are mapped later.
SlotLoweringRewriter πŸ”’
Rewrites each pattern-variable-qualified InputRef in a measure expression to an InputRef into the synthetic per-match row, recording a deduplicated LAST(var.col) slot for it.
VarResolver πŸ”’
Decodes a measure InputRef back to the pattern variable(s) and input column it references. Pattern variables and SUBSET names are each registered as an alias block of width input_col_num after the input columns, in alias_names order; so block 0 is the raw input (an unqualified reference, unsupported) and block k + 1 is alias_names[k]. A SUBSET name resolves to its member variables; a plain variable resolves to itself.

EnumsΒ§

DefineSlotKind
How a DefineSlot resolves against the row being tested for membership in a pattern variable. The wire enum, used directly (documented in stream_plan.proto); see MeasureSlotKind for why there is no parallel binder-side enum.
MeasureSlotKind
How a MeasureSlot resolves against the rows of a match. This is the wire enum used directly (the variants are documented in stream_plan.proto): a parallel binder-side enum would only add a conversion layer for the plan node to keep in lockstep.

ConstantsΒ§

MAX_NAV_OFFSET πŸ”’
Operational cap on a physical PREV offset in DEFINE.
MAX_PATTERN_NFA_STATES πŸ”’
Largest estimated NFA state count accepted for a whole pattern.
MAX_PERMUTE_VARS πŸ”’
Largest number of variables accepted in PERMUTE(...).
MAX_QUANTIFIER_BOUND πŸ”’
Largest bound accepted in a {n} / {n,} / {n,m} / {,m} range quantifier.
NAV_TABLE πŸ”’
Name of the synthetic relation that backs a DEFINE’s navigation placeholders.

FunctionsΒ§

check_pattern_bounds πŸ”’
Per-node bound checks: PERMUTE arity, min <= max, and each bound within MAX_QUANTIFIER_BOUND.
collect_from_pattern πŸ”’
collect_pattern_variables πŸ”’
Collect the distinct pattern-variable names appearing in a pattern, unioned with the DEFINE symbols. The union is defensive: bind_match_recognize rejects any DEFINE symbol absent from the pattern before this runs, so the two sets are equal there.
estimate_nfa_states πŸ”’
Upper bound on the number of NFA states Nfa::compile will allocate for pattern.
lower_within πŸ”’
Lower a WITHIN bound into the two expressions the executor consumes: the span predicate over a synthetic [last_order_key, first_order_key] row, and the per-row deadline over a synthetic [first_order_key] row.
min_start_distances πŸ”’
Per pattern variable: the minimum number of rows a match has necessarily consumed before a row can be labeled with that variable β€” its minimum distance from the match start.
reject_func_modifiers πŸ”’
Rejects function-call modifiers on the specially-lowered MATCH_RECOGNIZE functions: the MEASURES aggregates and FIRST/LAST/CLASSIFIER, and the DEFINE navigation functions PREV/NEXT/FIRST/LAST. Both lowerings match these by name and read only the argument list, so a modifier would be dropped and the plain call evaluated, silently producing wrong results. clause names the clause for the error message (MEASURES or DEFINE).
reject_oversized_permute πŸ”’
Rejects a PERMUTE with too many variables. This is the only enforcement point: the pattern lowering in optimizer::plan_node::stream_match_recognize no longer repeats the check, since every pattern that reaches it has passed validate_pattern.
validate_pattern πŸ”’
Validates that a pattern can be expanded into an NFA, at bind time.