Skip to content

Commit

Permalink
chore: Remove some calls to unwrap when calling create_expr in planne…
Browse files Browse the repository at this point in the history
…r.rs (#269)

* Remove some unwraps when calling create_expr

* simplify code
  • Loading branch information
andygrove authored Apr 16, 2024
1 parent 6fceda4 commit 77d580e
Showing 1 changed file with 14 additions and 9 deletions.
23 changes: 14 additions & 9 deletions core/src/execution/datafusion/planner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -489,14 +489,19 @@ impl PhysicalPlanner {
let when_then_pairs = case_when
.when
.iter()
.map(|x| self.create_expr(x, input_schema.clone()).unwrap())
.map(|x| self.create_expr(x, input_schema.clone()))
.zip(
case_when
.then
.iter()
.map(|then| self.create_expr(then, input_schema.clone()).unwrap()),
.map(|then| self.create_expr(then, input_schema.clone())),
)
.collect::<Vec<_>>();
.try_fold(Vec::new(), |mut acc, (a, b)| {
acc.push((a?, b?));
Ok::<Vec<(Arc<dyn PhysicalExpr>, Arc<dyn PhysicalExpr>)>, ExecutionError>(
acc,
)
})?;

let else_phy_expr = match &case_when.else_expr {
None => None,
Expand All @@ -516,8 +521,8 @@ impl PhysicalPlanner {
let list = expr
.lists
.iter()
.map(|x| self.create_expr(x, input_schema.clone()).unwrap())
.collect::<Vec<_>>();
.map(|x| self.create_expr(x, input_schema.clone()))
.collect::<Result<Vec<_>, _>>()?;

// if schema contains any dictionary type, we should use InListExpr instead of
// in_list as it doesn't handle value being dictionary type correctly
Expand Down Expand Up @@ -1221,14 +1226,14 @@ impl PhysicalPlanner {
let args = expr
.args
.iter()
.map(|x| self.create_expr(x, input_schema.clone()).unwrap())
.collect::<Vec<_>>();
.map(|x| self.create_expr(x, input_schema.clone()))
.collect::<Result<Vec<_>, _>>()?;

let fun_name = &expr.func;
let input_expr_types = args
.iter()
.map(|x| x.data_type(input_schema.as_ref()).unwrap())
.collect::<Vec<_>>();
.map(|x| x.data_type(input_schema.as_ref()))
.collect::<Result<Vec<_>, _>>()?;
let data_type = match expr.return_type.as_ref().map(to_arrow_datatype) {
Some(t) => t,
None => {
Expand Down

0 comments on commit 77d580e

Please sign in to comment.