From 61d3ed05f5c36810efbd0df46645a82f8ddfa28f Mon Sep 17 00:00:00 2001 From: Michael Xu Date: Tue, 30 Jan 2024 16:33:24 -0500 Subject: [PATCH] add eval_fallback --- src/expr/impl/src/scalar/case.rs | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/src/expr/impl/src/scalar/case.rs b/src/expr/impl/src/scalar/case.rs index 227dd114cab11..25870c37d2585 100644 --- a/src/expr/impl/src/scalar/case.rs +++ b/src/expr/impl/src/scalar/case.rs @@ -134,9 +134,24 @@ impl ConstantLookupExpression { } } + /// Evaluate the fallback arm with the given input + async fn eval_fallback(&self, input: &OwnedRow) -> Result { + let Some(ref fallback) = self.fallback else { + return Ok(None); + }; + let Ok(res) = fallback.eval_row(&input).await else { + bail!("failed to evaluate the input for fallback arm"); + }; + Ok(res) + } + /// The actual lookup & evaluation logic /// used in both `eval_row` & `eval` async fn lookup(&self, datum: Datum, input: &OwnedRow) -> Result { + if datum.is_none() { + return self.eval_fallback(input).await; + } + if let Some(expr) = self.arms.get(datum.as_ref().unwrap()) { let Ok(res) = expr.eval_row(&input).await else { bail!("failed to evaluate the input for normal arm"); @@ -144,13 +159,7 @@ impl ConstantLookupExpression { Ok(res) } else { // Fallback arm goes here - let Some(ref fallback) = self.fallback else { - return Ok(None); - }; - let Ok(res) = fallback.eval_row(&input).await else { - bail!("failed to evaluate the input for fallback arm"); - }; - Ok(res) + self.eval_fallback(input).await } } }