(
ecx: &ExprContext,
operand: &'a Option<Box<Expr<Aug>>>,
conditions: &'a [Expr<Aug>],
results: &'a [Expr<Aug>],
else_result: &'a Option<Box<Expr<Aug>>>,
)
| 5742 | } |
| 5743 | |
| 5744 | fn 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 | |
| 5783 | fn plan_literal<'a>(l: &'a Value) -> Result<CoercibleScalarExpr, PlanError> { |
| 5784 | let (datum, scalar_type) = match l { |
no test coverage detected