MCPcopy Create free account
hub / github.com/MaterializeInc/materialize / plan_case

Function plan_case

src/sql/src/plan/query.rs:5744–5781  ·  view source on GitHub ↗
(
    ecx: &ExprContext,
    operand: &'a Option<Box<Expr<Aug>>>,
    conditions: &'a [Expr<Aug>],
    results: &'a [Expr<Aug>],
    else_result: &'a Option<Box<Expr<Aug>>>,
)

Source from the content-addressed store, hash-verified

5742}
5743
5744fn plan_case<'a>(
5745 ecx: &ExprContext,
5746 operand: &'a Option<Box<Expr<Aug>>>,
5747 conditions: &'a [Expr<Aug>],
5748 results: &'a [Expr<Aug>],
5749 else_result: &'a Option<Box<Expr<Aug>>>,
5750) -> Result<HirScalarExpr, PlanError> {
5751 let mut cond_exprs = Vec::new();
5752 let mut result_exprs = Vec::new();
5753 for (c, r) in conditions.iter().zip_eq(results) {
5754 let c = match operand {
5755 Some(operand) => operand.clone().equals(c.clone()),
5756 None => c.clone(),
5757 };
5758 let cexpr = plan_expr(ecx, &c)?.type_as(ecx, &SqlScalarType::Bool)?;
5759 cond_exprs.push(cexpr);
5760 result_exprs.push(r);
5761 }
5762 result_exprs.push(match else_result {
5763 Some(else_result) => else_result,
5764 None => &Expr::Value(Value::Null),
5765 });
5766 let mut result_exprs = coerce_homogeneous_exprs(
5767 &ecx.with_name("CASE"),
5768 plan_exprs(ecx, &result_exprs)?,
5769 None,
5770 )?;
5771 let mut expr = result_exprs.pop().unwrap();
5772 assert_eq!(cond_exprs.len(), result_exprs.len());
5773 for (cexpr, rexpr) in cond_exprs
5774 .into_iter()
5775 .rev()
5776 .zip_eq(result_exprs.into_iter().rev())
5777 {
5778 expr = HirScalarExpr::if_then_else(cexpr, rexpr, expr);
5779 }
5780 Ok(expr)
5781}
5782
5783fn plan_literal<'a>(l: &'a Value) -> Result<CoercibleScalarExpr, PlanError> {
5784 let (datum, scalar_type) = match l {

Callers 1

plan_expr_innerFunction · 0.85

Calls 14

plan_exprFunction · 0.85
coerce_homogeneous_exprsFunction · 0.85
plan_exprsFunction · 0.85
if_then_elseFunction · 0.85
equalsMethod · 0.80
type_asMethod · 0.80
unwrapMethod · 0.80
ValueInterface · 0.50
iterMethod · 0.45
cloneMethod · 0.45
pushMethod · 0.45
with_nameMethod · 0.45

Tested by

no test coverage detected