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§
- Case
Literal Transform - Rewrites If-chains matching a single expression against literals
into a
CaseLiteralvariadic function withBTreeMaplookup.
Functions§
- collect_
if_ 🔒chain_ arms - Walks an If-chain and collects
(literal_row, result_expr)pairs. - has_
at_ 🔒least_ two_ arms - Returns
trueif the If-chain has at least 2 arms matchingEq(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 literalRow. 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 equalsx, insert (or overwrite)resinto the existing CaseLiteral.