Skip to main content

Module case_literal

Module case_literal 

Source
Expand description

Rewrites chains of If(Eq(expr, literal), result, If(...)) into CallVariadic { func: CaseLiteral { lookup, return_type }, exprs } for O(log n) evaluation via BTreeMap lookup.

Uses the ReprRelationType analysis to obtain column types in O(n), avoiding repeated input.typ() calls. Each scalar is then visited bottom-up so inner CaseLiterals are created first, then outer If nodes fold into them.

Structs§

CaseLiteralTransform
Rewrites If-chains matching a single expression against literals into a CaseLiteral variadic function with BTreeMap lookup.

Functions§

collect_if_chain_arms 🔒
Walks an If-chain and collects (literal_row, result_expr) pairs.
has_at_least_two_arms 🔒
Returns true if the If-chain has at least 2 arms matching Eq(same_expr, literal). Bails early once 2 are found to avoid unnecessary traversal.
peek_eq_literal 🔒
Inspects an Eq(expr, literal) condition and returns references to the non-literal expression and the literal Row. Returns (non_literal_expr_ref, literal_row_ref).
try_create_case_literal 🔒
Chain-walk rule: if node is an If-chain with >= 2 consecutive arms matching Eq(same_expr, literal), create a new CaseLiteral.
try_fold_into_case_literal 🔒
Fold rule: if node is If(Eq(x, lit), res, CallVariadic(CaseLiteral{..}, [x, ...])) where the CaseLiteral’s input (exprs[0]) structurally equals x, insert (or overwrite) res into the existing CaseLiteral.