From 77d580eb01e32039837e799634c4c5112554f4d7 Mon Sep 17 00:00:00 2001 From: Andy Grove Date: Mon, 15 Apr 2024 19:49:04 -0600 Subject: [PATCH] chore: Remove some calls to unwrap when calling create_expr in planner.rs (#269) * Remove some unwraps when calling create_expr * simplify code --- core/src/execution/datafusion/planner.rs | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/core/src/execution/datafusion/planner.rs b/core/src/execution/datafusion/planner.rs index e53ebe763..052ecc44d 100644 --- a/core/src/execution/datafusion/planner.rs +++ b/core/src/execution/datafusion/planner.rs @@ -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::>(); + .try_fold(Vec::new(), |mut acc, (a, b)| { + acc.push((a?, b?)); + Ok::, Arc)>, ExecutionError>( + acc, + ) + })?; let else_phy_expr = match &case_when.else_expr { None => None, @@ -516,8 +521,8 @@ impl PhysicalPlanner { let list = expr .lists .iter() - .map(|x| self.create_expr(x, input_schema.clone()).unwrap()) - .collect::>(); + .map(|x| self.create_expr(x, input_schema.clone())) + .collect::, _>>()?; // if schema contains any dictionary type, we should use InListExpr instead of // in_list as it doesn't handle value being dictionary type correctly @@ -1221,14 +1226,14 @@ impl PhysicalPlanner { let args = expr .args .iter() - .map(|x| self.create_expr(x, input_schema.clone()).unwrap()) - .collect::>(); + .map(|x| self.create_expr(x, input_schema.clone())) + .collect::, _>>()?; let fun_name = &expr.func; let input_expr_types = args .iter() - .map(|x| x.data_type(input_schema.as_ref()).unwrap()) - .collect::>(); + .map(|x| x.data_type(input_schema.as_ref())) + .collect::, _>>()?; let data_type = match expr.return_type.as_ref().map(to_arrow_datatype) { Some(t) => t, None => {