Skip to content

Commit

Permalink
add eval_fallback
Browse files Browse the repository at this point in the history
  • Loading branch information
xzhseh committed Jan 30, 2024
1 parent b0f2ccd commit 61d3ed0
Showing 1 changed file with 16 additions and 7 deletions.
23 changes: 16 additions & 7 deletions src/expr/impl/src/scalar/case.rs
Original file line number Diff line number Diff line change
Expand Up @@ -134,23 +134,32 @@ impl ConstantLookupExpression {
}
}

/// Evaluate the fallback arm with the given input
async fn eval_fallback(&self, input: &OwnedRow) -> Result<Datum> {
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<Datum> {
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");
};
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
}
}
}
Expand Down

0 comments on commit 61d3ed0

Please sign in to comment.