Skip to content

Apache DataFusion SQL Query Engine

ARROW-10891: [Rust][DataFusion] Enable / fix clone_on_copy, map_clone, or_fun_call

Heres, Danielabb6d9d84c53
diff --git a/rust/datafusion/src/lib.rs b/rust/datafusion/src/lib.rs
index 6916db1b8c..586250ae4f 100644
--- a/rust/datafusion/src/lib.rs
+++ b/rust/datafusion/src/lib.rs
@@ -20,7 +20,6 @@
clippy::assertions_on_constants,
clippy::bind_instead_of_map,
clippy::blocks_in_if_conditions,
- clippy::clone_on_copy,
clippy::collapsible_if,
clippy::explicit_counter_loop,
clippy::field_reassign_with_default,
@@ -28,7 +27,6 @@
clippy::into_iter_on_ref,
clippy::len_zero,
clippy::let_and_return,
- clippy::map_clone,
clippy::map_collect_result_unit,
clippy::match_like_matches_macro,
clippy::match_ref_pats,
@@ -37,7 +35,6 @@
clippy::needless_range_loop,
clippy::needless_return,
clippy::new_without_default,
- clippy::or_fun_call,
clippy::ptr_arg,
clippy::single_match,
clippy::stable_sort_primitive,
diff --git a/rust/datafusion/src/optimizer/utils.rs b/rust/datafusion/src/optimizer/utils.rs
index a134fa4213..7a7d89cf05 100644
--- a/rust/datafusion/src/optimizer/utils.rs
+++ b/rust/datafusion/src/optimizer/utils.rs
@@ -244,12 +244,10 @@ pub fn expr_sub_expressions(expr: &Expr) -> Result<Vec<Expr>> {
}
Expr::IsNull(e) => Ok(vec![e.as_ref().to_owned()]),
Expr::IsNotNull(e) => Ok(vec![e.as_ref().to_owned()]),
- Expr::ScalarFunction { args, .. } => Ok(args.iter().map(|e| e.clone()).collect()),
- Expr::ScalarUDF { args, .. } => Ok(args.iter().map(|e| e.clone()).collect()),
- Expr::AggregateFunction { args, .. } => {
- Ok(args.iter().map(|e| e.clone()).collect())
- }
- Expr::AggregateUDF { args, .. } => Ok(args.iter().map(|e| e.clone()).collect()),
+ Expr::ScalarFunction { args, .. } => Ok(args.clone()),
+ Expr::ScalarUDF { args, .. } => Ok(args.clone()),
+ Expr::AggregateFunction { args, .. } => Ok(args.clone()),
+ Expr::AggregateUDF { args, .. } => Ok(args.clone()),
Expr::Case {
expr,
when_then_expr,
@@ -373,8 +371,8 @@ pub fn rewrite_expression(expr: &Expr, expressions: &Vec<Expr>) -> Result<Expr>
asc, nulls_first, ..
} => Ok(Expr::Sort {
expr: Box::new(expressions[0].clone()),
- asc: asc.clone(),
- nulls_first: nulls_first.clone(),
+ asc: *asc,
+ nulls_first: *nulls_first,
}),
Expr::Between { negated, .. } => {
let expr = Expr::BinaryExpr {
diff --git a/rust/datafusion/src/physical_plan/expressions.rs b/rust/datafusion/src/physical_plan/expressions.rs
index d9a00c8e29..c294eedd0f 100644
--- a/rust/datafusion/src/physical_plan/expressions.rs
+++ b/rust/datafusion/src/physical_plan/expressions.rs
@@ -892,8 +892,8 @@ impl CountAccumulator {
fn update_from_option(&mut self, delta: &Option<u64>) -> Result<()> {
self.count = ScalarValue::UInt64(match (&self.count, delta) {
(ScalarValue::UInt64(None), None) => None,
- (ScalarValue::UInt64(None), Some(rhs)) => Some(rhs.clone()),
- (ScalarValue::UInt64(Some(lhs)), None) => Some(lhs.clone()),
+ (ScalarValue::UInt64(None), Some(rhs)) => Some(*rhs),
+ (ScalarValue::UInt64(Some(lhs)), None) => Some(*lhs),
(ScalarValue::UInt64(Some(lhs)), Some(rhs)) => Some(lhs + rhs),
_ => {
return Err(DataFusionError::Internal(
@@ -1649,11 +1649,15 @@ impl PhysicalExpr for NotExpr {
let arg = self.arg.evaluate(batch)?;
match arg {
ColumnarValue::Array(array) => {
- let array = array.as_any().downcast_ref::<BooleanArray>().ok_or(
- DataFusionError::Internal(
- "boolean_op failed to downcast array".to_owned(),
- ),
- )?;
+ let array =
+ array
+ .as_any()
+ .downcast_ref::<BooleanArray>()
+ .ok_or_else(|| {
+ DataFusionError::Internal(
+ "boolean_op failed to downcast array".to_owned(),
+ )
+ })?;
Ok(ColumnarValue::Array(Arc::new(
arrow::compute::kernels::boolean::not(array)?,
)))
diff --git a/rust/datafusion/src/physical_plan/filter.rs b/rust/datafusion/src/physical_plan/filter.rs
index 9324acddb5..3607997554 100644
--- a/rust/datafusion/src/physical_plan/filter.rs
+++ b/rust/datafusion/src/physical_plan/filter.rs
@@ -134,12 +134,12 @@ fn batch_filter(
array
.as_any()
.downcast_ref::<BooleanArray>()
- .ok_or(
+ .ok_or_else(|| {
DataFusionError::Internal(
"Filter predicate evaluated to non-boolean value".to_string(),
)
- .into_arrow_external_error(),
- )
+ .into_arrow_external_error()
+ })
// apply filter array to record batch
.and_then(|filter_array| filter_record_batch(batch, filter_array))
})
diff --git a/rust/datafusion/src/physical_plan/hash_aggregate.rs b/rust/datafusion/src/physical_plan/hash_aggregate.rs
index 3916e614b9..27deb9433b 100644
--- a/rust/datafusion/src/physical_plan/hash_aggregate.rs
+++ b/rust/datafusion/src/physical_plan/hash_aggregate.rs
@@ -165,7 +165,7 @@ impl ExecutionPlan for HashAggregateExec {
)))
} else {
Ok(Box::pin(GroupedHashAggregateStream::new(
- self.mode.clone(),
+ self.mode,
self.schema.clone(),
group_expr,
self.aggr_expr.clone(),
diff --git a/rust/datafusion/src/physical_plan/hash_join.rs b/rust/datafusion/src/physical_plan/hash_join.rs
index 1bcfe2c570..fad3b39aa7 100644
--- a/rust/datafusion/src/physical_plan/hash_join.rs
+++ b/rust/datafusion/src/physical_plan/hash_join.rs
@@ -556,7 +556,7 @@ mod tests {
/// is irrelevant
fn assert_same_rows(result: &[String], expected: &[&str]) {
// convert to set since row order is irrelevant
- let result = result.iter().map(|s| s.clone()).collect::<HashSet<_>>();
+ let result = result.iter().cloned().collect::<HashSet<_>>();
let expected = expected
.iter()
diff --git a/rust/datafusion/src/physical_plan/planner.rs b/rust/datafusion/src/physical_plan/planner.rs
index 046744e8ad..86af6f8786 100644
--- a/rust/datafusion/src/physical_plan/planner.rs
+++ b/rust/datafusion/src/physical_plan/planner.rs
@@ -338,7 +338,7 @@ impl DefaultPhysicalPlanner {
let mut stringified_plans = stringified_plans
.iter()
.filter(|s| s.should_display(*verbose))
- .map(|s| s.clone())
+ .cloned()
.collect::<Vec<_>>();
// add in the physical plan if requested
diff --git a/rust/datafusion/src/scalar.rs b/rust/datafusion/src/scalar.rs
index 6baf802d72..d6d20b9596 100644
--- a/rust/datafusion/src/scalar.rs
+++ b/rust/datafusion/src/scalar.rs
@@ -241,9 +241,12 @@ impl ScalarValue {
DataType::Utf8 => typed_cast!(array, index, StringArray, Utf8),
DataType::LargeUtf8 => typed_cast!(array, index, LargeStringArray, LargeUtf8),
DataType::List(nested_type) => {
- let list_array = array.as_any().downcast_ref::<ListArray>().ok_or(
- DataFusionError::Internal("Failed to downcast ListArray".to_string()),
- )?;
+ let list_array =
+ array.as_any().downcast_ref::<ListArray>().ok_or_else(|| {
+ DataFusionError::Internal(
+ "Failed to downcast ListArray".to_string(),
+ )
+ })?;
let value = match list_array.is_null(index) {
true => None,
false => {
diff --git a/rust/datafusion/src/sql/planner.rs b/rust/datafusion/src/sql/planner.rs
index a807ed08f6..dd375ddb95 100644
--- a/rust/datafusion/src/sql/planner.rs
+++ b/rust/datafusion/src/sql/planner.rs
@@ -415,7 +415,7 @@ impl<'a, S: SchemaProvider> SqlToRel<'a, S> {
let aggr_expr: Vec<Expr> = projection_expr
.iter()
.filter(|e| is_aggregate_expr(e))
- .map(|e| e.clone())
+ .cloned()
.collect();
// apply projection or aggregate