This is an automated email from the ASF dual-hosted git repository.

jakevin pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/arrow-datafusion.git


The following commit(s) were added to refs/heads/main by this push:
     new 181e5ccf28 minor: replace unwrap() with Err (#6101)
181e5ccf28 is described below

commit 181e5ccf2816ccaa05d8aaef0b375d4b7bbceece
Author: jakevin <[email protected]>
AuthorDate: Mon Apr 24 12:21:41 2023 +0800

    minor: replace unwrap() with Err (#6101)
---
 datafusion/common/src/scalar.rs                    |  3 +-
 datafusion/core/src/execution/context.rs           |  3 +-
 .../src/physical_optimizer/sort_enforcement.rs     |  3 +-
 datafusion/expr/src/type_coercion/binary.rs        |  3 +-
 .../optimizer/src/analyzer/count_wildcard_rule.rs  | 53 ++++++++++------------
 .../optimizer/src/common_subexpr_eliminate.rs      |  3 +-
 .../physical-expr/src/expressions/datetime.rs      | 15 ++----
 datafusion/physical-expr/src/expressions/not.rs    |  3 +-
 .../src/intervals/interval_aritmetic.rs            |  3 +-
 datafusion/proto/src/physical_plan/mod.rs          |  3 +-
 10 files changed, 37 insertions(+), 55 deletions(-)

diff --git a/datafusion/common/src/scalar.rs b/datafusion/common/src/scalar.rs
index e56042b38e..4a6acdb4a0 100644
--- a/datafusion/common/src/scalar.rs
+++ b/datafusion/common/src/scalar.rs
@@ -5646,8 +5646,7 @@ mod tests {
             ];
             assert_eq!(
                 formatted, expected,
-                "Actual:\n{:#?}\n\nExpected:\n{:#?}",
-                formatted, expected
+                "Actual:\n{formatted:#?}\n\nExpected:\n{expected:#?}"
             );
         };
 
diff --git a/datafusion/core/src/execution/context.rs 
b/datafusion/core/src/execution/context.rs
index d25f96f649..38063b8fed 100644
--- a/datafusion/core/src/execution/context.rs
+++ b/datafusion/core/src/execution/context.rs
@@ -1924,8 +1924,7 @@ fn create_dialect_from_str(dialect_name: &str) -> 
Result<Box<dyn Dialect>> {
         "ansi" => Ok(Box::new(AnsiDialect {})),
         _ => {
             Err(DataFusionError::Internal(format!(
-                "Unsupported SQL dialect: {}. Available dialects: Generic, 
MySQL, PostgreSQL, Hive, SQLite, Snowflake, Redshift, MsSQL, ClickHouse, 
BigQuery, Ansi.",
-                dialect_name
+                "Unsupported SQL dialect: {dialect_name}. Available dialects: 
Generic, MySQL, PostgreSQL, Hive, SQLite, Snowflake, Redshift, MsSQL, 
ClickHouse, BigQuery, Ansi."
             )))
         }
     }
diff --git a/datafusion/core/src/physical_optimizer/sort_enforcement.rs 
b/datafusion/core/src/physical_optimizer/sort_enforcement.rs
index fcdb1e1d6a..20f67d7021 100644
--- a/datafusion/core/src/physical_optimizer/sort_enforcement.rs
+++ b/datafusion/core/src/physical_optimizer/sort_enforcement.rs
@@ -1132,8 +1132,7 @@ mod tests {
                 can_skip_sort(&partition_by_exprs, &order_by_exprs, 
&exec_unbounded)?;
             assert_eq!(
                 res, *expected,
-                "Unexpected result for in unbounded test case#: {:?}, case: 
{:?}",
-                case_idx, test_case
+                "Unexpected result for in unbounded test case#: {case_idx:?}, 
case: {test_case:?}"
             );
         }
 
diff --git a/datafusion/expr/src/type_coercion/binary.rs 
b/datafusion/expr/src/type_coercion/binary.rs
index 4983dd25d2..b3d3f3d5cb 100644
--- a/datafusion/expr/src/type_coercion/binary.rs
+++ b/datafusion/expr/src/type_coercion/binary.rs
@@ -62,8 +62,7 @@ pub fn binary_operator_data_type(
                 .or_else(|| coerce_types(&lhs_type, op, &rhs_type).ok())
                 .ok_or_else(|| {
                     DataFusionError::Internal(format!(
-                        "Could not get return type for {:?} between {:?} and 
{:?}",
-                        op, lhs_type, rhs_type
+                        "Could not get return type for {op:?} between 
{lhs_type:?} and {rhs_type:?}"
                     ))
                 })?,
             _ => coerce_types(&lhs_type, op, &rhs_type)?,
diff --git a/datafusion/optimizer/src/analyzer/count_wildcard_rule.rs 
b/datafusion/optimizer/src/analyzer/count_wildcard_rule.rs
index 4520141de5..a7dc79374e 100644
--- a/datafusion/optimizer/src/analyzer/count_wildcard_rule.rs
+++ b/datafusion/optimizer/src/analyzer/count_wildcard_rule.rs
@@ -61,8 +61,8 @@ fn analyze_internal(plan: LogicalPlan) -> 
Result<Transformed<LogicalPlan>> {
             let window_expr = window
                 .window_expr
                 .iter()
-                .map(|expr| expr.clone().rewrite(&mut rewriter).unwrap())
-                .collect::<Vec<Expr>>();
+                .map(|expr| expr.clone().rewrite(&mut rewriter))
+                .collect::<Result<Vec<_>>>()?;
 
             Ok(Transformed::Yes(LogicalPlan::Window(Window {
                 input: window.input.clone(),
@@ -74,8 +74,8 @@ fn analyze_internal(plan: LogicalPlan) -> 
Result<Transformed<LogicalPlan>> {
             let aggr_expr = agg
                 .aggr_expr
                 .iter()
-                .map(|expr| expr.clone().rewrite(&mut rewriter).unwrap())
-                .collect();
+                .map(|expr| expr.clone().rewrite(&mut rewriter))
+                .collect::<Result<Vec<_>>>()?;
 
             Ok(Transformed::Yes(LogicalPlan::Aggregate(
                 Aggregate::try_new_with_schema(
@@ -89,8 +89,8 @@ fn analyze_internal(plan: LogicalPlan) -> 
Result<Transformed<LogicalPlan>> {
         LogicalPlan::Sort(Sort { expr, input, fetch }) => {
             let sort_expr = expr
                 .iter()
-                .map(|expr| expr.clone().rewrite(&mut rewriter).unwrap())
-                .collect();
+                .map(|expr| expr.clone().rewrite(&mut rewriter))
+                .collect::<Result<Vec<_>>>()?;
             Ok(Transformed::Yes(LogicalPlan::Sort(Sort {
                 expr: sort_expr,
                 input,
@@ -101,8 +101,8 @@ fn analyze_internal(plan: LogicalPlan) -> 
Result<Transformed<LogicalPlan>> {
             let projection_expr = projection
                 .expr
                 .iter()
-                .map(|expr| expr.clone().rewrite(&mut rewriter).unwrap())
-                .collect();
+                .map(|expr| expr.clone().rewrite(&mut rewriter))
+                .collect::<Result<Vec<_>>>()?;
             Ok(Transformed::Yes(LogicalPlan::Projection(
                 Projection::try_new_with_schema(
                     projection_expr,
@@ -115,10 +115,10 @@ fn analyze_internal(plan: LogicalPlan) -> 
Result<Transformed<LogicalPlan>> {
         LogicalPlan::Filter(Filter {
             predicate, input, ..
         }) => {
-            let predicate = predicate.rewrite(&mut rewriter).unwrap();
-            Ok(Transformed::Yes(LogicalPlan::Filter(
-                Filter::try_new(predicate, input).unwrap(),
-            )))
+            let predicate = predicate.rewrite(&mut rewriter)?;
+            Ok(Transformed::Yes(LogicalPlan::Filter(Filter::try_new(
+                predicate, input,
+            )?)))
         }
 
         _ => Ok(Transformed::No(plan)),
@@ -151,17 +151,15 @@ impl TreeNodeRewriter for CountWildcardRewriter {
                 order_by,
                 window_frame,
             }) if args.len() == 1 => match args[0] {
-                Expr::Wildcard => {
-                    Expr::WindowFunction(datafusion_expr::expr::WindowFunction 
{
-                        fun: 
window_function::WindowFunction::AggregateFunction(
-                            aggregate_function::AggregateFunction::Count,
-                        ),
-                        args: vec![lit(COUNT_STAR_EXPANSION)],
-                        partition_by,
-                        order_by,
-                        window_frame,
-                    })
-                }
+                Expr::Wildcard => Expr::WindowFunction(expr::WindowFunction {
+                    fun: window_function::WindowFunction::AggregateFunction(
+                        aggregate_function::AggregateFunction::Count,
+                    ),
+                    args: vec![lit(COUNT_STAR_EXPANSION)],
+                    partition_by,
+                    order_by,
+                    window_frame,
+                }),
 
                 _ => old_expr,
             },
@@ -187,8 +185,7 @@ impl TreeNodeRewriter for CountWildcardRewriter {
                 let new_plan = subquery
                     .as_ref()
                     .clone()
-                    .transform_down(&analyze_internal)
-                    .unwrap();
+                    .transform_down(&analyze_internal)?;
                 ScalarSubquery(Subquery {
                     subquery: Arc::new(new_plan),
                     outer_ref_columns,
@@ -203,8 +200,7 @@ impl TreeNodeRewriter for CountWildcardRewriter {
                     .subquery
                     .as_ref()
                     .clone()
-                    .transform_down(&analyze_internal)
-                    .unwrap();
+                    .transform_down(&analyze_internal)?;
 
                 InSubquery {
                     expr,
@@ -220,8 +216,7 @@ impl TreeNodeRewriter for CountWildcardRewriter {
                     .subquery
                     .as_ref()
                     .clone()
-                    .transform_down(&analyze_internal)
-                    .unwrap();
+                    .transform_down(&analyze_internal)?;
 
                 Exists {
                     subquery: Subquery {
diff --git a/datafusion/optimizer/src/common_subexpr_eliminate.rs 
b/datafusion/optimizer/src/common_subexpr_eliminate.rs
index 719b17110b..2930a8d817 100644
--- a/datafusion/optimizer/src/common_subexpr_eliminate.rs
+++ b/datafusion/optimizer/src/common_subexpr_eliminate.rs
@@ -123,9 +123,8 @@ impl OptimizerRule for CommonSubexprEliminate {
                 )?))
             }
             LogicalPlan::Filter(filter) => {
-                let input = &filter.input;
                 let predicate = &filter.predicate;
-                let input_schema = Arc::clone(input.schema());
+                let input_schema = Arc::clone(filter.input.schema());
                 let mut id_array = vec![];
                 expr_to_identifier(
                     predicate,
diff --git a/datafusion/physical-expr/src/expressions/datetime.rs 
b/datafusion/physical-expr/src/expressions/datetime.rs
index a1f7d82b38..4668745416 100644
--- a/datafusion/physical-expr/src/expressions/datetime.rs
+++ b/datafusion/physical-expr/src/expressions/datetime.rs
@@ -719,8 +719,7 @@ mod tests {
             let res2 = timestamp_scalar.add(&interval_scalar)?.to_array();
             assert_eq!(
                 &res1, &res2,
-                "Timestamp Scalar={} + Interval Scalar={}",
-                timestamp_scalar, interval_scalar
+                "Timestamp Scalar={timestamp_scalar} + Interval 
Scalar={interval_scalar}"
             );
         }
 
@@ -731,8 +730,7 @@ mod tests {
             let res2 = timestamp_scalar.sub(&interval_scalar)?.to_array();
             assert_eq!(
                 &res1, &res2,
-                "Timestamp Scalar={} - Interval Scalar={}",
-                timestamp_scalar, interval_scalar
+                "Timestamp Scalar={timestamp_scalar} - Interval 
Scalar={interval_scalar}"
             );
         }
 
@@ -743,8 +741,7 @@ mod tests {
             let res2 = timestamp_scalar.sub(&timestamp_scalar)?.to_array();
             assert_eq!(
                 &res1, &res2,
-                "Timestamp Scalar={} - Timestamp Scalar={}",
-                timestamp_scalar, timestamp_scalar
+                "Timestamp Scalar={timestamp_scalar} - Timestamp 
Scalar={timestamp_scalar}"
             );
         }
 
@@ -755,8 +752,7 @@ mod tests {
             let res2 = interval_scalar.sub(&interval_scalar)?.to_array();
             assert_eq!(
                 &res1, &res2,
-                "Interval Scalar={} - Interval Scalar={}",
-                interval_scalar, interval_scalar
+                "Interval Scalar={interval_scalar} - Interval 
Scalar={interval_scalar}"
             );
         }
 
@@ -767,8 +763,7 @@ mod tests {
             let res2 = interval_scalar.add(&interval_scalar)?.to_array();
             assert_eq!(
                 &res1, &res2,
-                "Interval Scalar={} + Interval Scalar={}",
-                interval_scalar, interval_scalar
+                "Interval Scalar={interval_scalar} + Interval 
Scalar={interval_scalar}"
             );
         }
 
diff --git a/datafusion/physical-expr/src/expressions/not.rs 
b/datafusion/physical-expr/src/expressions/not.rs
index b27dfdfef8..32040547b4 100644
--- a/datafusion/physical-expr/src/expressions/not.rs
+++ b/datafusion/physical-expr/src/expressions/not.rs
@@ -78,8 +78,7 @@ impl PhysicalExpr for NotExpr {
             DataType::Int64 => Ok(DataType::Int64),
             DataType::Null => Ok(DataType::Null),
             _ => Err(DataFusionError::Plan(format!(
-                "NOT or BITWISE_NOT not supported for datatype: '{:?}'",
-                data_type
+                "NOT or BITWISE_NOT not supported for datatype: 
'{data_type:?}'"
             ))),
         }
     }
diff --git a/datafusion/physical-expr/src/intervals/interval_aritmetic.rs 
b/datafusion/physical-expr/src/intervals/interval_aritmetic.rs
index 6c2d1b0f41..9745234a53 100644
--- a/datafusion/physical-expr/src/intervals/interval_aritmetic.rs
+++ b/datafusion/physical-expr/src/intervals/interval_aritmetic.rs
@@ -257,8 +257,7 @@ impl Interval {
             Ok(lower_type)
         } else {
             Err(DataFusionError::Internal(format!(
-                "Interval bounds have different types: {} != {}",
-                lower_type, upper_type,
+                "Interval bounds have different types: {lower_type} != 
{upper_type}",
             )))
         }
     }
diff --git a/datafusion/proto/src/physical_plan/mod.rs 
b/datafusion/proto/src/physical_plan/mod.rs
index 2c35428e86..2c67e0b9b4 100644
--- a/datafusion/proto/src/physical_plan/mod.rs
+++ b/datafusion/proto/src/physical_plan/mod.rs
@@ -438,8 +438,7 @@ impl AsExecutionPlan for PhysicalPlanNode {
                                                 .ok_or_else(
                                                     || {
                                                         proto_error(format!(
-                                                            "Received an 
unknown aggregate function: {}",
-                                                            i
+                                                            "Received an 
unknown aggregate function: {i}"
                                                         ))
                                                     },
                                                 )?;

Reply via email to