Expand description
Shared utility functions for the executor module.
This module provides common utilities used across the executor:
- Token creation for internal AST construction
- Value-to-Expression conversion
- Row combination for JOIN operations
- Value hashing and comparison
- Column index map building
Structs§
- Join
Projection Indices - Result of computing join projection indices. Contains the column sources in SELECT order to satisfy the SELECT expressions.
Functions§
- add_
table_ qualifier - Add table qualifier to an expression, converting simple identifiers to qualified ones. Used when applying filters post-join that were originally stripped for pushdown.
- build_
column_ index_ map - Build a column name to index map for fast column lookups. Column names are lowercased for case-insensitive matching. Also adds unqualified base names as fallbacks for qualified columns (e.g., “t.val” also registers “val”) when the base name is unambiguous.
- collect_
table_ qualifiers - Extract all table qualifiers (aliases) referenced in an expression. Returns a set of lowercase table names/aliases.
- combine_
predicates_ with_ and - Combine predicates with AND operator. Returns None if the input is empty.
- combine_
rows - Combine two rows into one for join output.
- combine_
rows_ with_ nulls - Combine a row with NULLs for the other side (used in OUTER JOINs).
- compare_
values - Compare two Values for ordering.
- compute_
join_ projection - Compute projection indices for a join operator.
- dummy_
token - Helper to create a dummy token for internal AST construction.
Use
dummy_token_clone()when literal doesn’t matter to avoid allocation. - dummy_
token_ clone - Clone the static dummy token (single String allocation for empty string).
- dummy_
token_ ref - Get a reference to a pre-allocated dummy token (zero allocation).
- expression_
contains_ aggregate - Check if an expression contains an aggregate function. Used for detecting nested aggregates and determining query structure.
- expression_
has_ parameters - Check if an expression contains any Parameter nodes ($1, $2, etc.) Parameterized queries cannot be semantically cached because the cache stores results tied to specific parameter values, but the AST only contains parameter indices, not values.
- expression_
to_ string - Convert expression to string representation. Used for expression alias matching and display purposes.
- expressions_
equivalent - Check if two expressions are structurally equivalent. Used for semantic matching and predicate comparison.
- extract_
and_ conditions - Extract all AND-ed conditions from an expression as references. Similar to flatten_and_predicates but returns references.
- extract_
base_ column_ name - Extract the base (unqualified) column name from a potentially qualified column name. For “table.column” returns “column”, for “column” returns “column”. The result is always lowercase for case-insensitive comparisons.
- extract_
column_ name - Extract the column name from an Identifier or QualifiedIdentifier expression. Returns the column name without table qualifier.
- extract_
column_ name_ with_ qualifier - Extract column name from identifier expression with optional qualifier. Returns (qualifier, column_name) where qualifier is Some for qualified identifiers. Column names are returned in lowercase for case-insensitive matching.
- extract_
join_ keys_ and_ residual - Extract equality join keys and residual conditions from a join condition.
- extract_
literal_ value - Extract a literal value from an expression. Converts AST literal expressions to runtime Values. Note: double-quoted identifiers are NOT treated as literals here. They may refer to actual column names, so pushdown should not assume they are string constants. The VM/compiler handles them correctly via column-resolution-first-then-string-fallback.
- filter_
references_ column - Check if a filter expression references a specific column (the join key). Returns true if the filter’s main column matches the target column name. Handles IN, comparison, BETWEEN, LIKE, function calls, and nested expressions.
- find_
column_ index - Find column index in column list, handling qualified names. Supports exact match and qualified match (table.column).
- flatten_
and_ predicates - Flatten AND predicates into a list of individual predicates.
E.g.,
a AND b AND cbecomes[a, b, c]. - flip_
operator - Flip a comparison operator for when column and value are swapped.
E.g.,
5 > colbecomescol < 5. - get_
table_ alias_ from_ expr - Get table alias from a table expression. Returns the alias if specified, otherwise the table name.
- hash_
composite_ key - Hash multiple key columns into a single hash value. Used heavily in hash joins - called on every row during build and probe phases. Uses FxHasher which is optimized for trusted keys in embedded database context.
- hash_
row - Hash all values in a row into a single hash value. Used for DISTINCT operations and set operations (UNION, INTERSECT, EXCEPT). Uses FxHasher which is optimized for trusted keys in embedded database context.
- hash_
value_ into - Hash a single value into an existing hasher.
- infix_
to_ operator - Convert AST InfixOperator to core Operator. Returns None for operators that don’t map to comparison operators.
- is_
aggregate_ function - Check if a function name is an aggregate function. Uses the function registry to determine this.
- is_
sorted_ on_ keys - Check if rows are sorted in ascending order on the specified key indices.
- parse_
vector_ dimension - Parse vector dimension from a type string like “VECTOR(768)”. Returns 0 if no dimension is specified.
- rows_
equal - Compare two rows for equality. Returns true if both rows have the same length and all values are equal.
- string_
to_ datatype - Convert type string to DataType. Handles common SQL type names like INTEGER, VARCHAR, BOOLEAN, etc.
- strip_
table_ qualifier - Strip table qualifier from an expression, replacing qualified identifiers with unqualified ones. Used when pushing filters to individual table scans.
- substitute_
filter_ column - Substitute a column reference in a filter expression with a new column name.
This is used for join key equivalence: when filter
o.user_id IN (1,2,3)can be transformed tou.id IN (1,2,3)based on join conditionu.id = o.user_id. - substitute_
outer_ references - Substitute outer references in an expression with their actual values.
- value_
to_ expression - Convert a Value to an Expression for use in subquery result replacement and other internal AST manipulation.
- values_
equal - Compare two Values for equality.
- verify_
composite_ key_ equality - Verify that all composite key columns match (handles hash collisions).