Apache DataFusion SQL Query Engine
Enable `clone_on_ref_ptr` clippy lint on physical-expr crate (#11240)
张林伟9355f4a5c7cb
diff --git a/datafusion/physical-expr/src/aggregate/array_agg.rs b/datafusion/physical-expr/src/aggregate/array_agg.rsindex c5a0662a22..634a0a0179 100644--- a/datafusion/physical-expr/src/aggregate/array_agg.rs+++ b/datafusion/physical-expr/src/aggregate/array_agg.rs@@ -91,7 +91,7 @@ impl AggregateExpr for ArrayAgg {}fn expressions(&self) -> Vec<Arc<dyn PhysicalExpr>> {- vec![self.expr.clone()]+ vec![Arc::clone(&self.expr)]}fn name(&self) -> &str {@@ -137,7 +137,7 @@ impl Accumulator for ArrayAggAccumulator {return Ok(());}assert!(values.len() == 1, "array_agg can only take 1 param!");- let val = values[0].clone();+ let val = Arc::clone(&values[0]);self.values.push(val);Ok(())}diff --git a/datafusion/physical-expr/src/aggregate/array_agg_distinct.rs b/datafusion/physical-expr/src/aggregate/array_agg_distinct.rsindex fc838196de..a59d85e84a 100644--- a/datafusion/physical-expr/src/aggregate/array_agg_distinct.rs+++ b/datafusion/physical-expr/src/aggregate/array_agg_distinct.rs@@ -95,7 +95,7 @@ impl AggregateExpr for DistinctArrayAgg {}fn expressions(&self) -> Vec<Arc<dyn PhysicalExpr>> {- vec![self.expr.clone()]+ vec![Arc::clone(&self.expr)]}fn name(&self) -> &str {diff --git a/datafusion/physical-expr/src/aggregate/array_agg_ordered.rs b/datafusion/physical-expr/src/aggregate/array_agg_ordered.rsindex 1234ab40c1..3b122fe9f8 100644--- a/datafusion/physical-expr/src/aggregate/array_agg_ordered.rs+++ b/datafusion/physical-expr/src/aggregate/array_agg_ordered.rs@@ -127,7 +127,7 @@ impl AggregateExpr for OrderSensitiveArrayAgg {}fn expressions(&self) -> Vec<Arc<dyn PhysicalExpr>> {- vec![self.expr.clone()]+ vec![Arc::clone(&self.expr)]}fn order_bys(&self) -> Option<&[PhysicalSortExpr]> {@@ -146,7 +146,7 @@ impl AggregateExpr for OrderSensitiveArrayAgg {Some(Arc::new(Self {name: self.name.to_string(),input_data_type: self.input_data_type.clone(),- expr: self.expr.clone(),+ expr: Arc::clone(&self.expr),nullable: self.nullable,order_by_data_types: self.order_by_data_types.clone(),// Reverse requirement:diff --git a/datafusion/physical-expr/src/aggregate/build_in.rs b/datafusion/physical-expr/src/aggregate/build_in.rsindex adbbbd3e63..1eadf7247f 100644--- a/datafusion/physical-expr/src/aggregate/build_in.rs+++ b/datafusion/physical-expr/src/aggregate/build_in.rs@@ -61,7 +61,7 @@ pub fn create_aggregate_expr(let input_phy_exprs = input_phy_exprs.to_vec();Ok(match (fun, distinct) {(AggregateFunction::ArrayAgg, false) => {- let expr = input_phy_exprs[0].clone();+ let expr = Arc::clone(&input_phy_exprs[0]);let nullable = expr.nullable(input_schema)?;if ordering_req.is_empty() {@@ -83,7 +83,7 @@ pub fn create_aggregate_expr("ARRAY_AGG(DISTINCT ORDER BY a ASC) order-sensitive aggregations are not available");}- let expr = input_phy_exprs[0].clone();+ let expr = Arc::clone(&input_phy_exprs[0]);let is_expr_nullable = expr.nullable(input_schema)?;Arc::new(expressions::DistinctArrayAgg::new(expr,@@ -93,12 +93,12 @@ pub fn create_aggregate_expr())}(AggregateFunction::Min, _) => Arc::new(expressions::Min::new(- input_phy_exprs[0].clone(),+ Arc::clone(&input_phy_exprs[0]),name,data_type,)),(AggregateFunction::Max, _) => Arc::new(expressions::Max::new(- input_phy_exprs[0].clone(),+ Arc::clone(&input_phy_exprs[0]),name,data_type,)),@@ -113,7 +113,7 @@ pub fn create_aggregate_expr(};let nullable = expr.nullable(input_schema)?;Arc::new(expressions::NthValueAgg::new(- expr.clone(),+ Arc::clone(expr),n.clone().try_into()?,name,input_phy_types[0].clone(),@@ -320,7 +320,7 @@ mod tests {input_exprs.iter().zip(coerced_types)- .map(|(expr, coerced_type)| try_cast(expr.clone(), schema, coerced_type))+ .map(|(expr, coerced_type)| try_cast(Arc::clone(expr), schema, coerced_type)).collect::<Result<Vec<_>>>()}}diff --git a/datafusion/physical-expr/src/aggregate/min_max.rs b/datafusion/physical-expr/src/aggregate/min_max.rsindex d142f68e41..65bb9e478c 100644--- a/datafusion/physical-expr/src/aggregate/min_max.rs+++ b/datafusion/physical-expr/src/aggregate/min_max.rs@@ -162,7 +162,7 @@ impl AggregateExpr for Max {}fn expressions(&self) -> Vec<Arc<dyn PhysicalExpr>> {- vec![self.expr.clone()]+ vec![Arc::clone(&self.expr)]}fn create_accumulator(&self) -> Result<Box<dyn Accumulator>> {@@ -927,7 +927,7 @@ impl AggregateExpr for Min {}fn expressions(&self) -> Vec<Arc<dyn PhysicalExpr>> {- vec![self.expr.clone()]+ vec![Arc::clone(&self.expr)]}fn name(&self) -> &str {@@ -1169,7 +1169,7 @@ mod tests {let mut min =MinAccumulator::try_new(&DataType::Interval(IntervalUnit::YearMonth)).unwrap();- min.update_batch(&[b.clone()]).unwrap();+ min.update_batch(&[Arc::clone(&b)]).unwrap();let min_res = min.evaluate().unwrap();assert_eq!(min_res,@@ -1181,7 +1181,7 @@ mod tests {let mut max =MaxAccumulator::try_new(&DataType::Interval(IntervalUnit::YearMonth)).unwrap();- max.update_batch(&[b.clone()]).unwrap();+ max.update_batch(&[Arc::clone(&b)]).unwrap();let max_res = max.evaluate().unwrap();assert_eq!(max_res,@@ -1202,7 +1202,7 @@ mod tests {let mut min =MinAccumulator::try_new(&DataType::Interval(IntervalUnit::DayTime)).unwrap();- min.update_batch(&[b.clone()]).unwrap();+ min.update_batch(&[Arc::clone(&b)]).unwrap();let min_res = min.evaluate().unwrap();assert_eq!(min_res,@@ -1211,7 +1211,7 @@ mod tests {let mut max =MaxAccumulator::try_new(&DataType::Interval(IntervalUnit::DayTime)).unwrap();- max.update_batch(&[b.clone()]).unwrap();+ max.update_batch(&[Arc::clone(&b)]).unwrap();let max_res = max.evaluate().unwrap();assert_eq!(max_res,@@ -1231,7 +1231,7 @@ mod tests {let mut min =MinAccumulator::try_new(&DataType::Interval(IntervalUnit::MonthDayNano)).unwrap();- min.update_batch(&[b.clone()]).unwrap();+ min.update_batch(&[Arc::clone(&b)]).unwrap();let min_res = min.evaluate().unwrap();assert_eq!(min_res,@@ -1243,7 +1243,7 @@ mod tests {let mut max =MaxAccumulator::try_new(&DataType::Interval(IntervalUnit::MonthDayNano)).unwrap();- max.update_batch(&[b.clone()]).unwrap();+ max.update_batch(&[Arc::clone(&b)]).unwrap();let max_res = max.evaluate().unwrap();assert_eq!(max_res,diff --git a/datafusion/physical-expr/src/aggregate/nth_value.rs b/datafusion/physical-expr/src/aggregate/nth_value.rsindex f6d25348f2..b75ecd1066 100644--- a/datafusion/physical-expr/src/aggregate/nth_value.rs+++ b/datafusion/physical-expr/src/aggregate/nth_value.rs@@ -119,7 +119,7 @@ impl AggregateExpr for NthValueAgg {fn expressions(&self) -> Vec<Arc<dyn PhysicalExpr>> {let n = Arc::new(Literal::new(ScalarValue::Int64(Some(self.n)))) as _;- vec![self.expr.clone(), n]+ vec![Arc::clone(&self.expr), n]}fn order_bys(&self) -> Option<&[PhysicalSortExpr]> {@@ -138,7 +138,7 @@ impl AggregateExpr for NthValueAgg {Some(Arc::new(Self {name: self.name.to_string(),input_data_type: self.input_data_type.clone(),- expr: self.expr.clone(),+ expr: Arc::clone(&self.expr),// index should be from the opposite siden: -self.n,nullable: self.nullable,diff --git a/datafusion/physical-expr/src/analysis.rs b/datafusion/physical-expr/src/analysis.rsindex e7b199af37..bcf1c8e510 100644--- a/datafusion/physical-expr/src/analysis.rs+++ b/datafusion/physical-expr/src/analysis.rs@@ -163,7 +163,7 @@ pub fn analyze() -> Result<AnalysisContext> {let target_boundaries = context.boundaries;- let mut graph = ExprIntervalGraph::try_new(expr.clone(), schema)?;+ let mut graph = ExprIntervalGraph::try_new(Arc::clone(expr), schema)?;let columns = collect_columns(expr).into_iter()diff --git a/datafusion/physical-expr/src/equivalence/class.rs b/datafusion/physical-expr/src/equivalence/class.rsindex 6c12acb934..4c0edd2a5d 100644--- a/datafusion/physical-expr/src/equivalence/class.rs+++ b/datafusion/physical-expr/src/equivalence/class.rs@@ -267,17 +267,19 @@ impl EquivalenceGroup {}(Some(group_idx), None) => {// Right side is new, extend left side's class:- self.classes[group_idx].push(right.clone());+ self.classes[group_idx].push(Arc::clone(right));}(None, Some(group_idx)) => {// Left side is new, extend right side's class:- self.classes[group_idx].push(left.clone());+ self.classes[group_idx].push(Arc::clone(left));}(None, None) => {// None of the expressions is among existing classes.// Create a new equivalence class and extend the group.- self.classes- .push(EquivalenceClass::new(vec![left.clone(), right.clone()]));+ self.classes.push(EquivalenceClass::new(vec![+ Arc::clone(left),+ Arc::clone(right),+ ]));}}}@@ -328,7 +330,7 @@ impl EquivalenceGroup {/// The expression is replaced with the first expression in the equivalence/// class it matches with (if any).pub fn normalize_expr(&self, expr: Arc<dyn PhysicalExpr>) -> Arc<dyn PhysicalExpr> {- expr.clone()+ Arc::clone(&expr).transform(|expr| {for cls in self.iter() {if cls.contains(&expr) {@@ -429,7 +431,7 @@ impl EquivalenceGroup {.get_equivalence_class(source).map_or(false, |group| group.contains(expr)){- return Some(target.clone());+ return Some(Arc::clone(target));}}}@@ -443,7 +445,7 @@ impl EquivalenceGroup {.into_iter().map(|child| self.project_expr(mapping, child)).collect::<Option<Vec<_>>>()- .map(|children| expr.clone().with_new_children(children).unwrap())+ .map(|children| Arc::clone(expr).with_new_children(children).unwrap())}/// Projects this equivalence group according to the given projection mapping.@@ -461,13 +463,13 @@ impl EquivalenceGroup {let mut new_classes = vec![];for (source, target) in mapping.iter() {if new_classes.is_empty() {- new_classes.push((source, vec![target.clone()]));+ new_classes.push((source, vec![Arc::clone(target)]));}if let Some((_, values)) =new_classes.iter_mut().find(|(key, _)| key.eq(source)){if !physical_exprs_contains(values, target) {- values.push(target.clone());+ values.push(Arc::clone(target));}}}@@ -515,10 +517,9 @@ impl EquivalenceGroup {// are equal in the resulting table.if join_type == &JoinType::Inner {for (lhs, rhs) in on.iter() {- let new_lhs = lhs.clone() as _;+ let new_lhs = Arc::clone(lhs) as _;// Rewrite rhs to point to the right side of the join:- let new_rhs = rhs- .clone()+ let new_rhs = Arc::clone(rhs).transform(|expr| {if let Some(column) =expr.as_any().downcast_ref::<Column>()@@ -649,7 +650,7 @@ mod tests {let eq_group = eq_properties.eq_group();for (expr, expected_eq) in expressions {assert!(- expected_eq.eq(&eq_group.normalize_expr(expr.clone())),+ expected_eq.eq(&eq_group.normalize_expr(Arc::clone(expr))),"error in test: expr: {expr:?}");}@@ -669,9 +670,11 @@ mod tests {Arc::new(Literal::new(ScalarValue::Int32(Some(1)))) as Arc<dyn PhysicalExpr>;let col_b_expr = Arc::new(Column::new("b", 1)) as Arc<dyn PhysicalExpr>;- let cls1 = EquivalenceClass::new(vec![lit_true.clone(), lit_false.clone()]);- let cls2 = EquivalenceClass::new(vec![lit_true.clone(), col_b_expr.clone()]);- let cls3 = EquivalenceClass::new(vec![lit2.clone(), lit1.clone()]);+ let cls1 =+ EquivalenceClass::new(vec![Arc::clone(&lit_true), Arc::clone(&lit_false)]);+ let cls2 =+ EquivalenceClass::new(vec![Arc::clone(&lit_true), Arc::clone(&col_b_expr)]);+ let cls3 = EquivalenceClass::new(vec![Arc::clone(&lit2), Arc::clone(&lit1)]);// lit_true is commonassert!(cls1.contains_any(&cls2));diff --git a/datafusion/physical-expr/src/equivalence/mod.rs b/datafusion/physical-expr/src/equivalence/mod.rsindex 5eb8a19e3d..1ed9a4ac21 100644--- a/datafusion/physical-expr/src/equivalence/mod.rs+++ b/datafusion/physical-expr/src/equivalence/mod.rs@@ -145,7 +145,7 @@ mod tests {let col_e = &col("e", &test_schema)?;let col_f = &col("f", &test_schema)?;let col_g = &col("g", &test_schema)?;- let mut eq_properties = EquivalenceProperties::new(test_schema.clone());+ let mut eq_properties = EquivalenceProperties::new(Arc::clone(&test_schema));eq_properties.add_equal_conditions(col_a, col_c)?;let option_asc = SortOptions {@@ -201,11 +201,11 @@ mod tests {let col_f = &col("f", &test_schema)?;let col_exprs = [col_a, col_b, col_c, col_d, col_e, col_f];- let mut eq_properties = EquivalenceProperties::new(test_schema.clone());+ let mut eq_properties = EquivalenceProperties::new(Arc::clone(&test_schema));// Define a and f are aliaseseq_properties.add_equal_conditions(col_a, col_f)?;// Column e has constant value.- eq_properties = eq_properties.add_constants([ConstExpr::new(col_e.clone())]);+ eq_properties = eq_properties.add_constants([ConstExpr::new(Arc::clone(col_e))]);// Randomly order columns for sortinglet mut rng = StdRng::seed_from_u64(seed);@@ -223,7 +223,7 @@ mod tests {let ordering = remaining_exprs.drain(0..n_sort_expr).map(|expr| PhysicalSortExpr {- expr: expr.clone(),+ expr: Arc::clone(expr),options: options_asc,}).collect();@@ -241,7 +241,7 @@ mod tests {in_data.iter().map(|(expr, options)| {- PhysicalSortRequirement::new((*expr).clone(), *options)+ PhysicalSortRequirement::new(Arc::clone(*expr), *options)}).collect()}@@ -253,7 +253,7 @@ mod tests {in_data.iter().map(|(expr, options)| PhysicalSortExpr {- expr: (*expr).clone(),+ expr: Arc::clone(*expr),options: *options,}).collect()@@ -276,7 +276,7 @@ mod tests {in_data.iter().map(|(expr, options)| PhysicalSortExpr {- expr: (*expr).clone(),+ expr: Arc::clone(expr),options: *options,}).collect()@@ -309,9 +309,9 @@ mod tests {.map(|(source, _target)| source.evaluate(input_data)?.into_array(num_rows)).collect::<Result<Vec<_>>>()?;let projected_batch = if projected_values.is_empty() {- RecordBatch::new_empty(output_schema.clone())+ RecordBatch::new_empty(Arc::clone(&output_schema))} else {- RecordBatch::try_new(output_schema.clone(), projected_values)?+ RecordBatch::try_new(Arc::clone(&output_schema), projected_values)?};let projected_eq =@@ -399,7 +399,7 @@ mod tests {let vals: Vec<usize> = (0..n_row).collect::<Vec<_>>();let vals: Vec<f64> = vals.into_iter().map(|val| val as f64).collect();let unique_col = Arc::new(Float64Array::from_iter_values(vals)) as ArrayRef;- columns.push(unique_col.clone());+ columns.push(Arc::clone(&unique_col));// Create a new schema with the added unique columnlet unique_col_name = "unique";@@ -414,7 +414,7 @@ mod tests {let schema = Arc::new(Schema::new(fields));// Create a new batch with the added column- let new_batch = RecordBatch::try_new(schema.clone(), columns)?;+ let new_batch = RecordBatch::try_new(Arc::clone(&schema), columns)?;// Add the unique column to the required ordering to ensure deterministic resultsrequired_ordering.push(PhysicalSortExpr {@@ -454,7 +454,7 @@ mod tests {let col = expr.as_any().downcast_ref::<Column>().unwrap();let (idx, _field) = schema.column_with_name(col.name()).unwrap();if let Some(res) = &existing_vec[idx] {- return Some(res.clone());+ return Some(Arc::clone(res));}}None@@ -516,13 +516,13 @@ mod tests {// Fill columns based on equivalence groupsfor eq_group in eq_properties.eq_group.iter() {let representative_array =- get_representative_arr(eq_group, &schema_vec, schema.clone())+ get_representative_arr(eq_group, &schema_vec, Arc::clone(schema)).unwrap_or_else(|| generate_random_array(n_elem, n_distinct));for expr in eq_group.iter() {let col = expr.as_any().downcast_ref::<Column>().unwrap();let (idx, _field) = schema.column_with_name(col.name()).unwrap();- schema_vec[idx] = Some(representative_array.clone());+ schema_vec[idx] = Some(Arc::clone(&representative_array));}}diff --git a/datafusion/physical-expr/src/equivalence/ordering.rs b/datafusion/physical-expr/src/equivalence/ordering.rsindex ac9d64e486..d71075dc77 100644--- a/datafusion/physical-expr/src/equivalence/ordering.rs+++ b/datafusion/physical-expr/src/equivalence/ordering.rs@@ -174,7 +174,7 @@ impl OrderingEquivalenceClass {pub fn add_offset(&mut self, offset: usize) {for ordering in self.orderings.iter_mut() {for sort_expr in ordering {- sort_expr.expr = add_offset_to_expr(sort_expr.expr.clone(), offset);+ sort_expr.expr = add_offset_to_expr(Arc::clone(&sort_expr.expr), offset);}}}@@ -264,12 +264,14 @@ mod tests {},];// finer ordering satisfies, crude ordering should return true- let mut eq_properties_finer = EquivalenceProperties::new(input_schema.clone());+ let mut eq_properties_finer =+ EquivalenceProperties::new(Arc::clone(&input_schema));eq_properties_finer.oeq_class.push(finer.clone());assert!(eq_properties_finer.ordering_satisfy(&crude));// Crude ordering doesn't satisfy finer ordering. should return false- let mut eq_properties_crude = EquivalenceProperties::new(input_schema.clone());+ let mut eq_properties_crude =+ EquivalenceProperties::new(Arc::clone(&input_schema));eq_properties_crude.oeq_class.push(crude.clone());assert!(!eq_properties_crude.ordering_satisfy(&finer));Ok(())@@ -307,9 +309,9 @@ mod tests {&DFSchema::empty(),)?;let a_plus_b = Arc::new(BinaryExpr::new(- col_a.clone(),+ Arc::clone(col_a),Operator::Plus,- col_b.clone(),+ Arc::clone(col_b),)) as Arc<dyn PhysicalExpr>;let options = SortOptions {descending: false,@@ -541,7 +543,7 @@ mod tests {for (orderings, eq_group, constants, reqs, expected) in test_cases {let err_msg =format!("error in test orderings: {orderings:?}, eq_group: {eq_group:?}, constants: {constants:?}, reqs: {reqs:?}, expected: {expected:?}");- let mut eq_properties = EquivalenceProperties::new(test_schema.clone());+ let mut eq_properties = EquivalenceProperties::new(Arc::clone(&test_schema));let orderings = convert_to_orderings(&orderings);eq_properties.add_new_orderings(orderings);let eq_group = eq_group@@ -554,9 +556,9 @@ mod tests {let eq_group = EquivalenceGroup::new(eq_group);eq_properties.add_equivalence_group(eq_group);- let constants = constants- .into_iter()- .map(|expr| ConstExpr::new(expr.clone()).with_across_partitions(true));+ let constants = constants.into_iter().map(|expr| {+ ConstExpr::new(Arc::clone(expr)).with_across_partitions(true)+ });eq_properties = eq_properties.add_constants(constants);let reqs = convert_to_sort_exprs(&reqs);@@ -717,7 +719,7 @@ mod tests {let required = cols.into_iter().map(|(expr, options)| PhysicalSortExpr {- expr: expr.clone(),+ expr: Arc::clone(expr),options,}).collect::<Vec<_>>();@@ -769,7 +771,7 @@ mod tests {let requirement = exprs.into_iter().map(|expr| PhysicalSortExpr {- expr: expr.clone(),+ expr: Arc::clone(expr),options: SORT_OPTIONS,}).collect::<Vec<_>>();@@ -842,7 +844,7 @@ mod tests {let requirement = exprs.into_iter().map(|expr| PhysicalSortExpr {- expr: expr.clone(),+ expr: Arc::clone(expr),options: SORT_OPTIONS,}).collect::<Vec<_>>();diff --git a/datafusion/physical-expr/src/equivalence/projection.rs b/datafusion/physical-expr/src/equivalence/projection.rsindex b5ac149d8b..f1ce3f0448 100644--- a/datafusion/physical-expr/src/equivalence/projection.rs+++ b/datafusion/physical-expr/src/equivalence/projection.rs@@ -56,8 +56,7 @@ impl ProjectionMapping {.enumerate().map(|(expr_idx, (expression, name))| {let target_expr = Arc::new(Column::new(name, expr_idx)) as _;- expression- .clone()+ Arc::clone(expression).transform_down(|e| match e.as_any().downcast_ref::<Column>() {Some(col) => {// Sometimes, an expression and its name in the input_schema@@ -107,7 +106,7 @@ impl ProjectionMapping {self.map.iter().find(|(source, _)| source.eq(expr))- .map(|(_, target)| target.clone())+ .map(|(_, target)| Arc::clone(target))}}@@ -149,24 +148,24 @@ mod tests {let col_e = &col("e", &schema)?;let col_ts = &col("ts", &schema)?;let a_plus_b = Arc::new(BinaryExpr::new(- col_a.clone(),+ Arc::clone(col_a),Operator::Plus,- col_b.clone(),+ Arc::clone(col_b),)) as Arc<dyn PhysicalExpr>;let b_plus_d = Arc::new(BinaryExpr::new(- col_b.clone(),+ Arc::clone(col_b),Operator::Plus,- col_d.clone(),+ Arc::clone(col_d),)) as Arc<dyn PhysicalExpr>;let b_plus_e = Arc::new(BinaryExpr::new(- col_b.clone(),+ Arc::clone(col_b),Operator::Plus,- col_e.clone(),+ Arc::clone(col_e),)) as Arc<dyn PhysicalExpr>;let c_plus_d = Arc::new(BinaryExpr::new(- col_c.clone(),+ Arc::clone(col_c),Operator::Plus,- col_d.clone(),+ Arc::clone(col_d),)) as Arc<dyn PhysicalExpr>;let option_asc = SortOptions {@@ -587,14 +586,14 @@ mod tests {for (idx, (orderings, proj_exprs, expected)) in test_cases.into_iter().enumerate(){- let mut eq_properties = EquivalenceProperties::new(schema.clone());+ let mut eq_properties = EquivalenceProperties::new(Arc::clone(&schema));let orderings = convert_to_orderings(&orderings);eq_properties.add_new_orderings(orderings);let proj_exprs = proj_exprs.into_iter()- .map(|(expr, name)| (expr.clone(), name))+ .map(|(expr, name)| (Arc::clone(expr), name)).collect::<Vec<_>>();let projection_mapping = ProjectionMapping::try_new(&proj_exprs, &schema)?;let output_schema = output_schema(&projection_mapping, &schema)?;@@ -643,15 +642,15 @@ mod tests {let col_c = &col("c", &schema)?;let col_ts = &col("ts", &schema)?;let a_plus_b = Arc::new(BinaryExpr::new(- col_a.clone(),+ Arc::clone(col_a),Operator::Plus,- col_b.clone(),+ Arc::clone(col_b),)) as Arc<dyn PhysicalExpr>;let test_fun = ScalarUDF::new_from_impl(TestScalarUDF::new());let round_c = &create_physical_expr(&test_fun,- &[col_c.clone()],+ &[Arc::clone(col_c)],&schema,&[],&DFSchema::empty(),@@ -670,7 +669,7 @@ mod tests {];let proj_exprs = proj_exprs.into_iter()- .map(|(expr, name)| (expr.clone(), name))+ .map(|(expr, name)| (Arc::clone(expr), name)).collect::<Vec<_>>();let projection_mapping = ProjectionMapping::try_new(&proj_exprs, &schema)?;let output_schema = output_schema(&projection_mapping, &schema)?;@@ -680,9 +679,9 @@ mod tests {let col_c_new = &col("c_new", &output_schema)?;let col_round_c_res = &col("round_c_res", &output_schema)?;let a_new_plus_b_new = Arc::new(BinaryExpr::new(- col_a_new.clone(),+ Arc::clone(col_a_new),Operator::Plus,- col_b_new.clone(),+ Arc::clone(col_b_new),)) as Arc<dyn PhysicalExpr>;let test_cases = vec![@@ -793,7 +792,7 @@ mod tests {];for (idx, (orderings, expected)) in test_cases.iter().enumerate() {- let mut eq_properties = EquivalenceProperties::new(schema.clone());+ let mut eq_properties = EquivalenceProperties::new(Arc::clone(&schema));let orderings = convert_to_orderings(orderings);eq_properties.add_new_orderings(orderings);@@ -801,7 +800,7 @@ mod tests {let expected = convert_to_orderings(expected);let projected_eq =- eq_properties.project(&projection_mapping, output_schema.clone());+ eq_properties.project(&projection_mapping, Arc::clone(&output_schema));let orderings = projected_eq.oeq_class();let err_msg = format!(@@ -834,9 +833,9 @@ mod tests {let col_e = &col("e", &schema)?;let col_f = &col("f", &schema)?;let a_plus_b = Arc::new(BinaryExpr::new(- col_a.clone(),+ Arc::clone(col_a),Operator::Plus,- col_b.clone(),+ Arc::clone(col_b),)) as Arc<dyn PhysicalExpr>;let option_asc = SortOptions {@@ -851,7 +850,7 @@ mod tests {];let proj_exprs = proj_exprs.into_iter()- .map(|(expr, name)| (expr.clone(), name))+ .map(|(expr, name)| (Arc::clone(expr), name)).collect::<Vec<_>>();let projection_mapping = ProjectionMapping::try_new(&proj_exprs, &schema)?;let output_schema = output_schema(&projection_mapping, &schema)?;@@ -936,7 +935,7 @@ mod tests {),];for (orderings, equal_columns, expected) in test_cases {- let mut eq_properties = EquivalenceProperties::new(schema.clone());+ let mut eq_properties = EquivalenceProperties::new(Arc::clone(&schema));for (lhs, rhs) in equal_columns {eq_properties.add_equal_conditions(lhs, rhs)?;}@@ -947,7 +946,7 @@ mod tests {let expected = convert_to_orderings(&expected);let projected_eq =- eq_properties.project(&projection_mapping, output_schema.clone());+ eq_properties.project(&projection_mapping, Arc::clone(&output_schema));let orderings = projected_eq.oeq_class();let err_msg = format!(@@ -1006,7 +1005,7 @@ mod tests {for proj_exprs in proj_exprs.iter().combinations(n_req) {let proj_exprs = proj_exprs.into_iter()- .map(|(expr, name)| (expr.clone(), name.to_string()))+ .map(|(expr, name)| (Arc::clone(expr), name.to_string())).collect::<Vec<_>>();let (projected_batch, projected_eq) = apply_projection(proj_exprs.clone(),@@ -1084,7 +1083,7 @@ mod tests {for proj_exprs in proj_exprs.iter().combinations(n_req) {let proj_exprs = proj_exprs.into_iter()- .map(|(expr, name)| (expr.clone(), name.to_string()))+ .map(|(expr, name)| (Arc::clone(expr), name.to_string())).collect::<Vec<_>>();let (projected_batch, projected_eq) = apply_projection(proj_exprs.clone(),@@ -1097,7 +1096,7 @@ mod tests {let projected_exprs = projection_mapping.iter()- .map(|(_source, target)| target.clone())+ .map(|(_source, target)| Arc::clone(target)).collect::<Vec<_>>();for n_req in 0..=projected_exprs.len() {@@ -1105,7 +1104,7 @@ mod tests {let requirement = exprs.into_iter().map(|expr| PhysicalSortExpr {- expr: expr.clone(),+ expr: Arc::clone(expr),options: SORT_OPTIONS,}).collect::<Vec<_>>();diff --git a/datafusion/physical-expr/src/equivalence/properties.rs b/datafusion/physical-expr/src/equivalence/properties.rsindex e3a2d1c753..9a6a17f58c 100644--- a/datafusion/physical-expr/src/equivalence/properties.rs+++ b/datafusion/physical-expr/src/equivalence/properties.rs@@ -213,13 +213,13 @@ impl EquivalenceProperties {// Left expression is constant, add right as constantif !const_exprs_contains(&self.constants, right) {self.constants- .push(ConstExpr::new(right.clone()).with_across_partitions(true));+ .push(ConstExpr::new(Arc::clone(right)).with_across_partitions(true));}} else if self.is_expr_constant(right) {// Right expression is constant, add left as constantif !const_exprs_contains(&self.constants, left) {self.constants- .push(ConstExpr::new(left.clone()).with_across_partitions(true));+ .push(ConstExpr::new(Arc::clone(left)).with_across_partitions(true));}}@@ -357,7 +357,7 @@ impl EquivalenceProperties {constant_exprs.extend(self.constants.iter()- .map(|const_expr| const_expr.expr().clone()),+ .map(|const_expr| Arc::clone(const_expr.expr())),);let constants_normalized = self.eq_group.normalize_exprs(constant_exprs);// Prune redundant sections in the requirement:@@ -424,11 +424,11 @@ impl EquivalenceProperties {fn ordering_satisfy_single(&self, req: &PhysicalSortRequirement) -> bool {let ExprProperties {sort_properties, ..- } = self.get_expr_properties(req.expr.clone());+ } = self.get_expr_properties(Arc::clone(&req.expr));match sort_properties {SortProperties::Ordered(options) => {let sort_expr = PhysicalSortExpr {- expr: req.expr.clone(),+ expr: Arc::clone(&req.expr),options,};sort_expr.satisfy(req, self.schema())@@ -572,7 +572,7 @@ impl EquivalenceProperties {&& cast_expr.is_bigger_cast(expr_type){res.push(PhysicalSortExpr {- expr: r_expr.clone(),+ expr: Arc::clone(&r_expr),options: sort_expr.options,});}@@ -715,8 +715,9 @@ impl EquivalenceProperties {map: mapping.iter().map(|(source, target)| {- let normalized_source = self.eq_group.normalize_expr(source.clone());- (normalized_source, target.clone())+ let normalized_source =+ self.eq_group.normalize_expr(Arc::clone(source));+ (normalized_source, Arc::clone(target))}).collect(),}@@ -758,7 +759,7 @@ impl EquivalenceProperties {}).flat_map(|(options, relevant_deps)| {let sort_expr = PhysicalSortExpr {- expr: target.clone(),+ expr: Arc::clone(target),options,};// Generate dependent orderings (i.e. prefixes for `sort_expr`):@@ -831,8 +832,9 @@ impl EquivalenceProperties {&& !const_exprs_contains(&projected_constants, target){// Expression evaluates to single value- projected_constants- .push(ConstExpr::new(target.clone()).with_across_partitions(true));+ projected_constants.push(+ ConstExpr::new(Arc::clone(target)).with_across_partitions(true),+ );}}projected_constants@@ -889,11 +891,11 @@ impl EquivalenceProperties {.flat_map(|&idx| {let ExprProperties {sort_properties, ..- } = eq_properties.get_expr_properties(exprs[idx].clone());+ } = eq_properties.get_expr_properties(Arc::clone(&exprs[idx]));match sort_properties {SortProperties::Ordered(options) => Some((PhysicalSortExpr {- expr: exprs[idx].clone(),+ expr: Arc::clone(&exprs[idx]),options,},idx,@@ -903,7 +905,7 @@ impl EquivalenceProperties {let options = SortOptions::default();Some((PhysicalSortExpr {- expr: exprs[idx].clone(),+ expr: Arc::clone(&exprs[idx]),options,},idx,@@ -926,7 +928,7 @@ impl EquivalenceProperties {// an implementation strategy confined to this function.for (PhysicalSortExpr { expr, .. }, idx) in &ordered_exprs {eq_properties = eq_properties- .add_constants(std::iter::once(ConstExpr::new(expr.clone())));+ .add_constants(std::iter::once(ConstExpr::new(Arc::clone(expr))));search_indices.shift_remove(idx);}// Add new ordered section to the state.@@ -954,9 +956,9 @@ impl EquivalenceProperties {let const_exprs = self.constants.iter()- .map(|const_expr| const_expr.expr().clone());+ .map(|const_expr| Arc::clone(const_expr.expr()));let normalized_constants = self.eq_group.normalize_exprs(const_exprs);- let normalized_expr = self.eq_group.normalize_expr(expr.clone());+ let normalized_expr = self.eq_group.normalize_expr(Arc::clone(expr));is_constant_recurse(&normalized_constants, &normalized_expr)}@@ -1022,7 +1024,9 @@ fn update_properties(Interval::make_unbounded(&node.expr.data_type(eq_properties.schema())?)?}// Now, check what we know about orderings:- let normalized_expr = eq_properties.eq_group.normalize_expr(node.expr.clone());+ let normalized_expr = eq_properties+ .eq_group+ .normalize_expr(Arc::clone(&node.expr));if eq_properties.is_expr_constant(&normalized_expr) {node.data.sort_properties = SortProperties::Singleton;} else if let Some(options) = eq_properties@@ -1108,7 +1112,7 @@ fn referred_dependencies(.keys().filter(|sort_expr| expr_refers(source, &sort_expr.expr)){- let key = ExprWrapper(sort_expr.expr.clone());+ let key = ExprWrapper(Arc::clone(&sort_expr.expr));expr_to_sort_exprs.entry(key).or_default()@@ -1484,25 +1488,25 @@ mod tests {Field::new("c", DataType::Int64, true),]));- let input_properties = EquivalenceProperties::new(input_schema.clone());+ let input_properties = EquivalenceProperties::new(Arc::clone(&input_schema));let col_a = col("a", &input_schema)?;// a as a1, a as a2, a as a3, a as a3let proj_exprs = vec![- (col_a.clone(), "a1".to_string()),- (col_a.clone(), "a2".to_string()),- (col_a.clone(), "a3".to_string()),- (col_a.clone(), "a4".to_string()),+ (Arc::clone(&col_a), "a1".to_string()),+ (Arc::clone(&col_a), "a2".to_string()),+ (Arc::clone(&col_a), "a3".to_string()),+ (Arc::clone(&col_a), "a4".to_string()),];let projection_mapping = ProjectionMapping::try_new(&proj_exprs, &input_schema)?;let out_schema = output_schema(&projection_mapping, &input_schema)?;// a as a1, a as a2, a as a3, a as a3let proj_exprs = vec![- (col_a.clone(), "a1".to_string()),- (col_a.clone(), "a2".to_string()),- (col_a.clone(), "a3".to_string()),- (col_a.clone(), "a4".to_string()),+ (Arc::clone(&col_a), "a1".to_string()),+ (Arc::clone(&col_a), "a2".to_string()),+ (Arc::clone(&col_a), "a3".to_string()),+ (Arc::clone(&col_a), "a4".to_string()),];let projection_mapping = ProjectionMapping::try_new(&proj_exprs, &input_schema)?;@@ -1532,8 +1536,8 @@ mod tests {let col_b = &col("b", &schema)?;let col_c = &col("c", &schema)?;let offset = schema.fields.len();- let col_a2 = &add_offset_to_expr(col_a.clone(), offset);- let col_b2 = &add_offset_to_expr(col_b.clone(), offset);+ let col_a2 = &add_offset_to_expr(Arc::clone(col_a), offset);+ let col_b2 = &add_offset_to_expr(Arc::clone(col_b), offset);let option_asc = SortOptions {descending: false,nulls_first: false,@@ -1577,8 +1581,8 @@ mod tests {),];for (left_orderings, right_orderings, expected) in test_cases {- let mut left_eq_properties = EquivalenceProperties::new(schema.clone());- let mut right_eq_properties = EquivalenceProperties::new(schema.clone());+ let mut left_eq_properties = EquivalenceProperties::new(Arc::clone(&schema));+ let mut right_eq_properties = EquivalenceProperties::new(Arc::clone(&schema));let left_orderings = convert_to_orderings(&left_orderings);let right_orderings = convert_to_orderings(&right_orderings);let expected = convert_to_orderings(&expected);@@ -1626,17 +1630,17 @@ mod tests {let col_b = col("b", &schema)?;let col_d = col("d", &schema)?;let b_plus_d = Arc::new(BinaryExpr::new(- col_b.clone(),+ Arc::clone(&col_b),Operator::Plus,- col_d.clone(),+ Arc::clone(&col_d),)) as Arc<dyn PhysicalExpr>;- let constants = vec![col_a.clone(), col_b.clone()];- let expr = b_plus_d.clone();+ let constants = vec![Arc::clone(&col_a), Arc::clone(&col_b)];+ let expr = Arc::clone(&b_plus_d);assert!(!is_constant_recurse(&constants, &expr));- let constants = vec![col_a.clone(), col_b.clone(), col_d.clone()];- let expr = b_plus_d.clone();+ let constants = vec![Arc::clone(&col_a), Arc::clone(&col_b), Arc::clone(&col_d)];+ let expr = Arc::clone(&b_plus_d);assert!(is_constant_recurse(&constants, &expr));Ok(())}@@ -1726,11 +1730,11 @@ mod tests {eq_properties.add_equal_conditions(&col_a_expr, &col_c_expr)?;let others = vec![vec![PhysicalSortExpr {- expr: col_b_expr.clone(),+ expr: Arc::clone(&col_b_expr),options: sort_options,}],vec![PhysicalSortExpr {- expr: col_c_expr.clone(),+ expr: Arc::clone(&col_c_expr),options: sort_options,}],];@@ -1739,11 +1743,11 @@ mod tests {let mut expected_eqs = EquivalenceProperties::new(Arc::new(schema));expected_eqs.add_new_orderings([vec![PhysicalSortExpr {- expr: col_b_expr.clone(),+ expr: Arc::clone(&col_b_expr),options: sort_options,}],vec![PhysicalSortExpr {- expr: col_c_expr.clone(),+ expr: Arc::clone(&col_c_expr),options: sort_options,}],]);@@ -1766,7 +1770,7 @@ mod tests {]);let col_a = &col("a", &schema)?;let col_b = &col("b", &schema)?;- let required_columns = [col_b.clone(), col_a.clone()];+ let required_columns = [Arc::clone(col_b), Arc::clone(col_a)];let mut eq_properties = EquivalenceProperties::new(Arc::new(schema));eq_properties.add_new_orderings([vec![PhysicalSortExpr {@@ -1784,11 +1788,11 @@ mod tests {result,vec![PhysicalSortExpr {- expr: col_b.clone(),+ expr: Arc::clone(col_b),options: sort_options_not},PhysicalSortExpr {- expr: col_a.clone(),+ expr: Arc::clone(col_a),options: sort_options}]@@ -1801,7 +1805,7 @@ mod tests {]);let col_a = &col("a", &schema)?;let col_b = &col("b", &schema)?;- let required_columns = [col_b.clone(), col_a.clone()];+ let required_columns = [Arc::clone(col_b), Arc::clone(col_a)];let mut eq_properties = EquivalenceProperties::new(Arc::new(schema));eq_properties.add_new_orderings([vec![PhysicalSortExpr {@@ -1825,11 +1829,11 @@ mod tests {result,vec![PhysicalSortExpr {- expr: col_b.clone(),+ expr: Arc::clone(col_b),options: sort_options_not},PhysicalSortExpr {- expr: col_a.clone(),+ expr: Arc::clone(col_a),options: sort_options}]@@ -1890,11 +1894,11 @@ mod tests {// [b ASC], [d ASC]eq_properties.add_new_orderings(vec![vec![PhysicalSortExpr {- expr: col_b.clone(),+ expr: Arc::clone(col_b),options: option_asc,}],vec![PhysicalSortExpr {- expr: col_d.clone(),+ expr: Arc::clone(col_d),options: option_asc,}],]);@@ -1903,22 +1907,22 @@ mod tests {// d + b(Arc::new(BinaryExpr::new(- col_d.clone(),+ Arc::clone(col_d),Operator::Plus,- col_b.clone(),+ Arc::clone(col_b),)) as Arc<dyn PhysicalExpr>,SortProperties::Ordered(option_asc),),// b- (col_b.clone(), SortProperties::Ordered(option_asc)),+ (Arc::clone(col_b), SortProperties::Ordered(option_asc)),// a- (col_a.clone(), SortProperties::Ordered(option_asc)),+ (Arc::clone(col_a), SortProperties::Ordered(option_asc)),// a + c(Arc::new(BinaryExpr::new(- col_a.clone(),+ Arc::clone(col_a),Operator::Plus,- col_c.clone(),+ Arc::clone(col_c),)),SortProperties::Unordered,),@@ -1929,7 +1933,7 @@ mod tests {.iter().flat_map(|ordering| ordering.first().cloned()).collect::<Vec<_>>();- let expr_props = eq_properties.get_expr_properties(expr.clone());+ let expr_props = eq_properties.get_expr_properties(Arc::clone(&expr));let err_msg = format!("expr:{:?}, expected: {:?}, actual: {:?}, leading_orderings: {leading_orderings:?}",expr, expected, expr_props.sort_properties@@ -1987,7 +1991,7 @@ mod tests {.iter().zip(ordering.iter()).map(|(&idx, sort_expr)| PhysicalSortExpr {- expr: exprs[idx].clone(),+ expr: Arc::clone(&exprs[idx]),options: sort_expr.options,}).collect::<Vec<_>>();@@ -2034,9 +2038,9 @@ mod tests {let col_h = &col("h", &test_schema)?;// a + dlet a_plus_d = Arc::new(BinaryExpr::new(- col_a.clone(),+ Arc::clone(col_a),Operator::Plus,- col_d.clone(),+ Arc::clone(col_d),)) as Arc<dyn PhysicalExpr>;let option_asc = SortOptions {@@ -2050,11 +2054,11 @@ mod tests {// [d ASC, h DESC] also satisfies schema.eq_properties.add_new_orderings([vec![PhysicalSortExpr {- expr: col_d.clone(),+ expr: Arc::clone(col_d),options: option_asc,},PhysicalSortExpr {- expr: col_h.clone(),+ expr: Arc::clone(col_h),options: option_desc,},]]);@@ -2143,7 +2147,8 @@ mod tests {let col_h = &col("h", &test_schema)?;// Add column h as constant- eq_properties = eq_properties.add_constants(vec![ConstExpr::new(col_h.clone())]);+ eq_properties =+ eq_properties.add_constants(vec![ConstExpr::new(Arc::clone(col_h))]);let test_cases = vec![// TEST CASE 1@@ -2382,20 +2387,21 @@ mod tests {Field::new("b", DataType::Utf8, true),Field::new("c", DataType::Timestamp(TimeUnit::Nanosecond, None), true),]));- let base_properties = EquivalenceProperties::new(schema.clone()).with_reorder(- ["a", "b", "c"]- .into_iter()- .map(|c| {- col(c, schema.as_ref()).map(|expr| PhysicalSortExpr {- expr,- options: SortOptions {- descending: false,- nulls_first: true,- },+ let base_properties = EquivalenceProperties::new(Arc::clone(&schema))+ .with_reorder(+ ["a", "b", "c"]+ .into_iter()+ .map(|c| {+ col(c, schema.as_ref()).map(|expr| PhysicalSortExpr {+ expr,+ options: SortOptions {+ descending: false,+ nulls_first: true,+ },+ })})- })- .collect::<Result<Vec<_>>>()?,- );+ .collect::<Result<Vec<_>>>()?,+ );struct TestCase {name: &'static str,@@ -2414,8 +2420,11 @@ mod tests {TestCase {name: "(a, b, c) -> (c)",// b is constant, so it should be removed from the sort order- constants: vec![col_b.clone()],- equal_conditions: vec![[cast_c.clone(), col_a.clone()]],+ constants: vec![Arc::clone(&col_b)],+ equal_conditions: vec![[+ Arc::clone(&cast_c) as Arc<dyn PhysicalExpr>,+ Arc::clone(&col_a),+ ]],sort_columns: &["c"],should_satisfy_ordering: true,},@@ -2425,7 +2434,10 @@ mod tests {name: "(a, b, c) -> (c)",// b is constant, so it should be removed from the sort orderconstants: vec![col_b],- equal_conditions: vec![[col_a.clone(), cast_c.clone()]],+ equal_conditions: vec![[+ Arc::clone(&col_a),+ Arc::clone(&cast_c) as Arc<dyn PhysicalExpr>,+ ]],sort_columns: &["c"],should_satisfy_ordering: true,},@@ -2434,7 +2446,10 @@ mod tests {// b is not constant anymoreconstants: vec![],// a and c are still compatible, but this is irrelevant since the original ordering is (a, b, c)- equal_conditions: vec![[cast_c.clone(), col_a.clone()]],+ equal_conditions: vec![[+ Arc::clone(&cast_c) as Arc<dyn PhysicalExpr>,+ Arc::clone(&col_a),+ ]],sort_columns: &["c"],should_satisfy_ordering: false,},diff --git a/datafusion/physical-expr/src/expressions/binary.rs b/datafusion/physical-expr/src/expressions/binary.rsindex d19279c20d..f1e40575bc 100644--- a/datafusion/physical-expr/src/expressions/binary.rs+++ b/datafusion/physical-expr/src/expressions/binary.rs@@ -328,9 +328,9 @@ impl PhysicalExpr for BinaryExpr {children: Vec<Arc<dyn PhysicalExpr>>,) -> Result<Arc<dyn PhysicalExpr>> {Ok(Arc::new(BinaryExpr::new(- children[0].clone(),+ Arc::clone(&children[0]),self.op.clone(),- children[1].clone(),+ Arc::clone(&children[1]),)))}@@ -1493,8 +1493,11 @@ mod tests {let b = Arc::new(Int32Array::from(vec![1, 2, 3, 4, 5]));apply_arithmetic::<Int32Type>(- schema.clone(),- vec![a.clone(), b.clone()],+ Arc::clone(&schema),+ vec![+ Arc::clone(&a) as Arc<dyn Array>,+ Arc::clone(&b) as Arc<dyn Array>,+ ],Operator::Minus,Int32Array::from(vec![0, 0, 1, 4, 11]),)?;@@ -2376,8 +2379,8 @@ mod tests {expected: BooleanArray,) -> Result<()> {let op = binary_op(col("a", schema)?, op, col("b", schema)?, schema)?;- let data: Vec<ArrayRef> = vec![left.clone(), right.clone()];- let batch = RecordBatch::try_new(schema.clone(), data)?;+ let data: Vec<ArrayRef> = vec![Arc::clone(left), Arc::clone(right)];+ let batch = RecordBatch::try_new(Arc::clone(schema), data)?;let result = op.evaluate(&batch)?.into_array(batch.num_rows())@@ -3471,8 +3474,8 @@ mod tests {expected: ArrayRef,) -> Result<()> {let arithmetic_op = binary_op(col("a", schema)?, op, col("b", schema)?, schema)?;- let data: Vec<ArrayRef> = vec![left.clone(), right.clone()];- let batch = RecordBatch::try_new(schema.clone(), data)?;+ let data: Vec<ArrayRef> = vec![Arc::clone(left), Arc::clone(right)];+ let batch = RecordBatch::try_new(Arc::clone(schema), data)?;let result = arithmetic_op.evaluate(&batch)?.into_array(batch.num_rows())@@ -3767,15 +3770,15 @@ mod tests {let left = Arc::new(Int32Array::from(vec![Some(12), None, Some(11)])) as ArrayRef;let right =Arc::new(Int32Array::from(vec![Some(1), Some(3), Some(7)])) as ArrayRef;- let mut result = bitwise_and_dyn(left.clone(), right.clone())?;+ let mut result = bitwise_and_dyn(Arc::clone(&left), Arc::clone(&right))?;let expected = Int32Array::from(vec![Some(0), None, Some(3)]);assert_eq!(result.as_ref(), &expected);- result = bitwise_or_dyn(left.clone(), right.clone())?;+ result = bitwise_or_dyn(Arc::clone(&left), Arc::clone(&right))?;let expected = Int32Array::from(vec![Some(13), None, Some(15)]);assert_eq!(result.as_ref(), &expected);- result = bitwise_xor_dyn(left.clone(), right.clone())?;+ result = bitwise_xor_dyn(Arc::clone(&left), Arc::clone(&right))?;let expected = Int32Array::from(vec![Some(13), None, Some(12)]);assert_eq!(result.as_ref(), &expected);@@ -3783,15 +3786,15 @@ mod tests {Arc::new(UInt32Array::from(vec![Some(12), None, Some(11)])) as ArrayRef;let right =Arc::new(UInt32Array::from(vec![Some(1), Some(3), Some(7)])) as ArrayRef;- let mut result = bitwise_and_dyn(left.clone(), right.clone())?;+ let mut result = bitwise_and_dyn(Arc::clone(&left), Arc::clone(&right))?;let expected = UInt32Array::from(vec![Some(0), None, Some(3)]);assert_eq!(result.as_ref(), &expected);- result = bitwise_or_dyn(left.clone(), right.clone())?;+ result = bitwise_or_dyn(Arc::clone(&left), Arc::clone(&right))?;let expected = UInt32Array::from(vec![Some(13), None, Some(15)]);assert_eq!(result.as_ref(), &expected);- result = bitwise_xor_dyn(left.clone(), right.clone())?;+ result = bitwise_xor_dyn(Arc::clone(&left), Arc::clone(&right))?;let expected = UInt32Array::from(vec![Some(13), None, Some(12)]);assert_eq!(result.as_ref(), &expected);@@ -3803,24 +3806,26 @@ mod tests {let input = Arc::new(Int32Array::from(vec![Some(2), None, Some(10)])) as ArrayRef;let modules =Arc::new(Int32Array::from(vec![Some(2), Some(4), Some(8)])) as ArrayRef;- let mut result = bitwise_shift_left_dyn(input.clone(), modules.clone())?;+ let mut result =+ bitwise_shift_left_dyn(Arc::clone(&input), Arc::clone(&modules))?;let expected = Int32Array::from(vec![Some(8), None, Some(2560)]);assert_eq!(result.as_ref(), &expected);- result = bitwise_shift_right_dyn(result.clone(), modules.clone())?;+ result = bitwise_shift_right_dyn(Arc::clone(&result), Arc::clone(&modules))?;assert_eq!(result.as_ref(), &input);let input =Arc::new(UInt32Array::from(vec![Some(2), None, Some(10)])) as ArrayRef;let modules =Arc::new(UInt32Array::from(vec![Some(2), Some(4), Some(8)])) as ArrayRef;- let mut result = bitwise_shift_left_dyn(input.clone(), modules.clone())?;+ let mut result =+ bitwise_shift_left_dyn(Arc::clone(&input), Arc::clone(&modules))?;let expected = UInt32Array::from(vec![Some(8), None, Some(2560)]);assert_eq!(result.as_ref(), &expected);- result = bitwise_shift_right_dyn(result.clone(), modules.clone())?;+ result = bitwise_shift_right_dyn(Arc::clone(&result), Arc::clone(&modules))?;assert_eq!(result.as_ref(), &input);Ok(())}@@ -3829,14 +3834,14 @@ mod tests {fn bitwise_shift_array_overflow_test() -> Result<()> {let input = Arc::new(Int32Array::from(vec![Some(2)])) as ArrayRef;let modules = Arc::new(Int32Array::from(vec![Some(100)])) as ArrayRef;- let result = bitwise_shift_left_dyn(input.clone(), modules.clone())?;+ let result = bitwise_shift_left_dyn(Arc::clone(&input), Arc::clone(&modules))?;let expected = Int32Array::from(vec![Some(32)]);assert_eq!(result.as_ref(), &expected);let input = Arc::new(UInt32Array::from(vec![Some(2)])) as ArrayRef;let modules = Arc::new(UInt32Array::from(vec![Some(100)])) as ArrayRef;- let result = bitwise_shift_left_dyn(input.clone(), modules.clone())?;+ let result = bitwise_shift_left_dyn(Arc::clone(&input), Arc::clone(&modules))?;let expected = UInt32Array::from(vec![Some(32)]);assert_eq!(result.as_ref(), &expected);@@ -3973,9 +3978,12 @@ mod tests {Arc::new(DictionaryArray::try_new(keys, values).unwrap()) as ArrayRef;// Casting Dictionary to Int32- let casted =- to_result_type_array(&Operator::Plus, dictionary.clone(), &DataType::Int32)- .unwrap();+ let casted = to_result_type_array(+ &Operator::Plus,+ Arc::clone(&dictionary),+ &DataType::Int32,+ )+ .unwrap();assert_eq!(&casted,&(Arc::new(Int32Array::from(vec![Some(1), None, Some(3), Some(4)]))@@ -3985,16 +3993,19 @@ mod tests {// Array has same datatype as result type, no castinglet casted = to_result_type_array(&Operator::Plus,- dictionary.clone(),+ Arc::clone(&dictionary),dictionary.data_type(),).unwrap();assert_eq!(&casted, &dictionary);// Not numerical operator, no casting- let casted =- to_result_type_array(&Operator::Eq, dictionary.clone(), &DataType::Int32)- .unwrap();+ let casted = to_result_type_array(+ &Operator::Eq,+ Arc::clone(&dictionary),+ &DataType::Int32,+ )+ .unwrap();assert_eq!(&casted, &dictionary);}}diff --git a/datafusion/physical-expr/src/expressions/case.rs b/datafusion/physical-expr/src/expressions/case.rsindex 08d8cd4413..b1707d3abf 100644--- a/datafusion/physical-expr/src/expressions/case.rs+++ b/datafusion/physical-expr/src/expressions/case.rs@@ -173,8 +173,8 @@ impl CaseExpr {if let Some(e) = &self.else_expr {// keep `else_expr`'s data type and return type consistent- let expr = try_cast(e.clone(), &batch.schema(), return_type.clone())- .unwrap_or_else(|_| e.clone());+ let expr = try_cast(Arc::clone(e), &batch.schema(), return_type.clone())+ .unwrap_or_else(|_| Arc::clone(e));// null and unmatched tuples should be assigned else valueremainder = or(&base_nulls, &remainder)?;let else_ = expr@@ -246,8 +246,8 @@ impl CaseExpr {if let Some(e) = &self.else_expr {// keep `else_expr`'s data type and return type consistent- let expr = try_cast(e.clone(), &batch.schema(), return_type.clone())- .unwrap_or_else(|_| e.clone());+ let expr = try_cast(Arc::clone(e), &batch.schema(), return_type.clone())+ .unwrap_or_else(|_| Arc::clone(e));let else_ = expr.evaluate_selection(batch, &remainder)?.into_array(batch.num_rows())?;@@ -887,26 +887,26 @@ mod tests {let expr1 = generate_case_when_with_type_coercion(Some(col("a", &schema)?),vec![- (when1.clone(), then1.clone()),- (when2.clone(), then2.clone()),+ (Arc::clone(&when1), Arc::clone(&then1)),+ (Arc::clone(&when2), Arc::clone(&then2)),],- Some(else_value.clone()),+ Some(Arc::clone(&else_value)),&schema,)?;let expr2 = generate_case_when_with_type_coercion(Some(col("a", &schema)?),vec![- (when1.clone(), then1.clone()),- (when2.clone(), then2.clone()),+ (Arc::clone(&when1), Arc::clone(&then1)),+ (Arc::clone(&when2), Arc::clone(&then2)),],- Some(else_value.clone()),+ Some(Arc::clone(&else_value)),&schema,)?;let expr3 = generate_case_when_with_type_coercion(Some(col("a", &schema)?),- vec![(when1.clone(), then1.clone()), (when2, then2)],+ vec![(Arc::clone(&when1), Arc::clone(&then1)), (when2, then2)],None,&schema,)?;@@ -943,15 +943,14 @@ mod tests {let expr = generate_case_when_with_type_coercion(Some(col("a", &schema)?),vec![- (when1.clone(), then1.clone()),- (when2.clone(), then2.clone()),+ (Arc::clone(&when1), Arc::clone(&then1)),+ (Arc::clone(&when2), Arc::clone(&then2)),],- Some(else_value.clone()),+ Some(Arc::clone(&else_value)),&schema,)?;- let expr2 = expr- .clone()+ let expr2 = Arc::clone(&expr).transform(|e| {let transformed =match e.as_any().downcast_ref::<crate::expressions::Literal>() {@@ -972,8 +971,7 @@ mod tests {.data().unwrap();- let expr3 = expr- .clone()+ let expr3 = Arc::clone(&expr).transform_down(|e| {let transformed =match e.as_any().downcast_ref::<crate::expressions::Literal>() {diff --git a/datafusion/physical-expr/src/expressions/in_list.rs b/datafusion/physical-expr/src/expressions/in_list.rsindex 53c790ff6b..8a3885030b 100644--- a/datafusion/physical-expr/src/expressions/in_list.rs+++ b/datafusion/physical-expr/src/expressions/in_list.rs@@ -389,7 +389,7 @@ impl PhysicalExpr for InListExpr {) -> Result<Arc<dyn PhysicalExpr>> {// assume the static_filter will not change during the rewrite processOk(Arc::new(InListExpr::new(- children[0].clone(),+ Arc::clone(&children[0]),children[1..].to_vec(),self.negated,self.static_filter.clone(),@@ -540,7 +540,7 @@ mod tests {list,&false,vec![Some(true), Some(false), None],- col_a.clone(),+ Arc::clone(&col_a),&schema);@@ -551,7 +551,7 @@ mod tests {list,&true,vec![Some(false), Some(true), None],- col_a.clone(),+ Arc::clone(&col_a),&schema);@@ -562,7 +562,7 @@ mod tests {list,&false,vec![Some(true), None, None],- col_a.clone(),+ Arc::clone(&col_a),&schema);@@ -573,7 +573,7 @@ mod tests {list,&true,vec![Some(false), None, None],- col_a.clone(),+ Arc::clone(&col_a),&schema);@@ -598,7 +598,7 @@ mod tests {list.clone(),&false,vec![Some(true), Some(false), None],- col_a.clone(),+ Arc::clone(&col_a),&schema);@@ -608,7 +608,7 @@ mod tests {list,&true,vec![Some(false), Some(true), None],- col_a.clone(),+ Arc::clone(&col_a),&schema);@@ -623,7 +623,7 @@ mod tests {list.clone(),&false,vec![Some(true), None, None],- col_a.clone(),+ Arc::clone(&col_a),&schema);@@ -633,7 +633,7 @@ mod tests {list,&true,vec![Some(false), None, None],- col_a.clone(),+ Arc::clone(&col_a),&schema);@@ -654,7 +654,7 @@ mod tests {list,&false,vec![Some(true), Some(false), None],- col_a.clone(),+ Arc::clone(&col_a),&schema);@@ -665,7 +665,7 @@ mod tests {list,&true,vec![Some(false), Some(true), None],- col_a.clone(),+ Arc::clone(&col_a),&schema);@@ -676,7 +676,7 @@ mod tests {list,&false,vec![Some(true), None, None],- col_a.clone(),+ Arc::clone(&col_a),&schema);@@ -687,7 +687,7 @@ mod tests {list,&true,vec![Some(false), None, None],- col_a.clone(),+ Arc::clone(&col_a),&schema);@@ -714,7 +714,7 @@ mod tests {list,&false,vec![Some(true), Some(false), None, Some(false), Some(false)],- col_a.clone(),+ Arc::clone(&col_a),&schema);@@ -725,7 +725,7 @@ mod tests {list,&true,vec![Some(false), Some(true), None, Some(true), Some(true)],- col_a.clone(),+ Arc::clone(&col_a),&schema);@@ -736,7 +736,7 @@ mod tests {list,&false,vec![Some(true), None, None, None, None],- col_a.clone(),+ Arc::clone(&col_a),&schema);@@ -747,7 +747,7 @@ mod tests {list,&true,vec![Some(false), None, None, None, None],- col_a.clone(),+ Arc::clone(&col_a),&schema);@@ -758,7 +758,7 @@ mod tests {list,&false,vec![Some(true), Some(false), None, Some(true), Some(false)],- col_a.clone(),+ Arc::clone(&col_a),&schema);@@ -769,7 +769,7 @@ mod tests {list,&true,vec![Some(false), Some(true), None, Some(false), Some(true)],- col_a.clone(),+ Arc::clone(&col_a),&schema);@@ -780,7 +780,7 @@ mod tests {list,&false,vec![Some(true), Some(false), None, Some(false), Some(true)],- col_a.clone(),+ Arc::clone(&col_a),&schema);@@ -791,7 +791,7 @@ mod tests {list,&true,vec![Some(false), Some(true), None, Some(true), Some(false)],- col_a.clone(),+ Arc::clone(&col_a),&schema);@@ -812,7 +812,7 @@ mod tests {list,&false,vec![Some(true), None],- col_a.clone(),+ Arc::clone(&col_a),&schema);@@ -823,7 +823,7 @@ mod tests {list,&true,vec![Some(false), None],- col_a.clone(),+ Arc::clone(&col_a),&schema);@@ -834,7 +834,7 @@ mod tests {list,&false,vec![Some(true), None],- col_a.clone(),+ Arc::clone(&col_a),&schema);@@ -845,7 +845,7 @@ mod tests {list,&true,vec![Some(false), None],- col_a.clone(),+ Arc::clone(&col_a),&schema);@@ -869,7 +869,7 @@ mod tests {list,&false,vec![Some(true), Some(false), None],- col_a.clone(),+ Arc::clone(&col_a),&schema);@@ -883,7 +883,7 @@ mod tests {list,&true,vec![Some(false), Some(true), None],- col_a.clone(),+ Arc::clone(&col_a),&schema);@@ -898,7 +898,7 @@ mod tests {list,&false,vec![Some(true), None, None],- col_a.clone(),+ Arc::clone(&col_a),&schema);@@ -913,7 +913,7 @@ mod tests {list,&true,vec![Some(false), None, None],- col_a.clone(),+ Arc::clone(&col_a),&schema);@@ -937,7 +937,7 @@ mod tests {list,&false,vec![Some(true), Some(false), None],- col_a.clone(),+ Arc::clone(&col_a),&schema);@@ -951,7 +951,7 @@ mod tests {list,&true,vec![Some(false), Some(true), None],- col_a.clone(),+ Arc::clone(&col_a),&schema);@@ -966,7 +966,7 @@ mod tests {list,&false,vec![Some(true), None, None],- col_a.clone(),+ Arc::clone(&col_a),&schema);@@ -981,7 +981,7 @@ mod tests {list,&true,vec![Some(false), None, None],- col_a.clone(),+ Arc::clone(&col_a),&schema);@@ -1008,7 +1008,7 @@ mod tests {list,&false,vec![Some(true), None, Some(false)],- col_a.clone(),+ Arc::clone(&col_a),&schema);// expression: "a not in (100,200)@@ -1018,7 +1018,7 @@ mod tests {list,&true,vec![Some(false), None, Some(true)],- col_a.clone(),+ Arc::clone(&col_a),&schema);@@ -1029,7 +1029,7 @@ mod tests {list.clone(),&false,vec![Some(true), None, None],- col_a.clone(),+ Arc::clone(&col_a),&schema);// expression: "a not in (200,NULL), the data type of list is INT32 AND NULL@@ -1038,7 +1038,7 @@ mod tests {list,&true,vec![Some(false), None, None],- col_a.clone(),+ Arc::clone(&col_a),&schema);@@ -1049,7 +1049,7 @@ mod tests {list,&false,vec![Some(true), None, Some(true)],- col_a.clone(),+ Arc::clone(&col_a),&schema);@@ -1060,7 +1060,7 @@ mod tests {list,&true,vec![Some(true), None, Some(false)],- col_a.clone(),+ Arc::clone(&col_a),&schema);@@ -1073,7 +1073,7 @@ mod tests {list.clone(),&false,vec![Some(true), None, Some(false)],- col_a.clone(),+ Arc::clone(&col_a),&schema);@@ -1082,7 +1082,7 @@ mod tests {list,&true,vec![Some(false), None, Some(true)],- col_a.clone(),+ Arc::clone(&col_a),&schema);@@ -1168,7 +1168,7 @@ mod tests {list.clone(),&false,vec![Some(true), Some(false), None],- col_a.clone(),+ Arc::clone(&col_a),&schema);@@ -1177,7 +1177,7 @@ mod tests {list.clone(),&true,vec![Some(false), Some(true), None],- col_a.clone(),+ Arc::clone(&col_a),&schema);Ok(())@@ -1219,13 +1219,13 @@ mod tests {vec![Arc::new(a), Arc::new(b), Arc::new(c)],)?;- let list = vec![col_b.clone(), col_c.clone()];+ let list = vec![Arc::clone(&col_b), Arc::clone(&col_c)];in_list!(batch,list.clone(),&false,vec![Some(false), Some(true), None, Some(true), Some(true)],- col_a.clone(),+ Arc::clone(&col_a),&schema);@@ -1234,7 +1234,7 @@ mod tests {list,&true,vec![Some(true), Some(false), None, Some(false), Some(false)],- col_a.clone(),+ Arc::clone(&col_a),&schema);@@ -1262,22 +1262,22 @@ mod tests {// static_filter has no nullslet list = vec![lit(1_i64), lit(2_i64)];- test_nullable!(c1_nullable.clone(), list.clone(), &schema, true);- test_nullable!(c2_non_nullable.clone(), list.clone(), &schema, false);+ test_nullable!(Arc::clone(&c1_nullable), list.clone(), &schema, true);+ test_nullable!(Arc::clone(&c2_non_nullable), list.clone(), &schema, false);// static_filter has nullslet list = vec![lit(1_i64), lit(2_i64), lit(ScalarValue::Null)];- test_nullable!(c1_nullable.clone(), list.clone(), &schema, true);- test_nullable!(c2_non_nullable.clone(), list.clone(), &schema, true);+ test_nullable!(Arc::clone(&c1_nullable), list.clone(), &schema, true);+ test_nullable!(Arc::clone(&c2_non_nullable), list.clone(), &schema, true);- let list = vec![c1_nullable.clone()];- test_nullable!(c2_non_nullable.clone(), list.clone(), &schema, true);+ let list = vec![Arc::clone(&c1_nullable)];+ test_nullable!(Arc::clone(&c2_non_nullable), list.clone(), &schema, true);- let list = vec![c2_non_nullable.clone()];- test_nullable!(c1_nullable.clone(), list.clone(), &schema, true);+ let list = vec![Arc::clone(&c2_non_nullable)];+ test_nullable!(Arc::clone(&c1_nullable), list.clone(), &schema, true);- let list = vec![c2_non_nullable.clone(), c2_non_nullable.clone()];- test_nullable!(c2_non_nullable.clone(), list.clone(), &schema, false);+ let list = vec![Arc::clone(&c2_non_nullable), Arc::clone(&c2_non_nullable)];+ test_nullable!(Arc::clone(&c2_non_nullable), list.clone(), &schema, false);Ok(())}@@ -1370,7 +1370,7 @@ mod tests {list.clone(),&false,vec![Some(true), Some(false), None],- col_a.clone(),+ Arc::clone(&col_a),&schema);}@@ -1382,7 +1382,7 @@ mod tests {list.clone(),&true,vec![Some(false), Some(true), None],- col_a.clone(),+ Arc::clone(&col_a),&schema);}@@ -1402,7 +1402,7 @@ mod tests {list.clone(),&false,vec![Some(true), None, None],- col_a.clone(),+ Arc::clone(&col_a),&schema);}@@ -1414,7 +1414,7 @@ mod tests {list.clone(),&true,vec![Some(false), None, None],- col_a.clone(),+ Arc::clone(&col_a),&schema);}diff --git a/datafusion/physical-expr/src/expressions/is_not_null.rs b/datafusion/physical-expr/src/expressions/is_not_null.rsindex 1918f0891f..d8fa77585b 100644--- a/datafusion/physical-expr/src/expressions/is_not_null.rs+++ b/datafusion/physical-expr/src/expressions/is_not_null.rs@@ -90,7 +90,7 @@ impl PhysicalExpr for IsNotNullExpr {self: Arc<Self>,children: Vec<Arc<dyn PhysicalExpr>>,) -> Result<Arc<dyn PhysicalExpr>> {- Ok(Arc::new(IsNotNullExpr::new(children[0].clone())))+ Ok(Arc::new(IsNotNullExpr::new(Arc::clone(&children[0]))))}fn dyn_hash(&self, state: &mut dyn Hasher) {diff --git a/datafusion/physical-expr/src/expressions/is_null.rs b/datafusion/physical-expr/src/expressions/is_null.rsindex 3430efcd76..41becafde6 100644--- a/datafusion/physical-expr/src/expressions/is_null.rs+++ b/datafusion/physical-expr/src/expressions/is_null.rs@@ -91,7 +91,7 @@ impl PhysicalExpr for IsNullExpr {self: Arc<Self>,children: Vec<Arc<dyn PhysicalExpr>>,) -> Result<Arc<dyn PhysicalExpr>> {- Ok(Arc::new(IsNullExpr::new(children[0].clone())))+ Ok(Arc::new(IsNullExpr::new(Arc::clone(&children[0]))))}fn dyn_hash(&self, state: &mut dyn Hasher) {diff --git a/datafusion/physical-expr/src/expressions/like.rs b/datafusion/physical-expr/src/expressions/like.rsindex e0c02b0a90..b84ba82b64 100644--- a/datafusion/physical-expr/src/expressions/like.rs+++ b/datafusion/physical-expr/src/expressions/like.rs@@ -123,8 +123,8 @@ impl PhysicalExpr for LikeExpr {Ok(Arc::new(LikeExpr::new(self.negated,self.case_insensitive,- children[0].clone(),- children[1].clone(),+ Arc::clone(&children[0]),+ Arc::clone(&children[1]),)))}diff --git a/datafusion/physical-expr/src/expressions/negative.rs b/datafusion/physical-expr/src/expressions/negative.rsindex aed2675e04..b5ebc250cb 100644--- a/datafusion/physical-expr/src/expressions/negative.rs+++ b/datafusion/physical-expr/src/expressions/negative.rs@@ -97,7 +97,7 @@ impl PhysicalExpr for NegativeExpr {self: Arc<Self>,children: Vec<Arc<dyn PhysicalExpr>>,) -> Result<Arc<dyn PhysicalExpr>> {- Ok(Arc::new(NegativeExpr::new(children[0].clone())))+ Ok(Arc::new(NegativeExpr::new(Arc::clone(&children[0]))))}fn dyn_hash(&self, state: &mut dyn Hasher) {diff --git a/datafusion/physical-expr/src/expressions/not.rs b/datafusion/physical-expr/src/expressions/not.rsindex 9aaab0658d..b69954e00b 100644--- a/datafusion/physical-expr/src/expressions/not.rs+++ b/datafusion/physical-expr/src/expressions/not.rs@@ -97,7 +97,7 @@ impl PhysicalExpr for NotExpr {self: Arc<Self>,children: Vec<Arc<dyn PhysicalExpr>>,) -> Result<Arc<dyn PhysicalExpr>> {- Ok(Arc::new(NotExpr::new(children[0].clone())))+ Ok(Arc::new(NotExpr::new(Arc::clone(&children[0]))))}fn dyn_hash(&self, state: &mut dyn Hasher) {diff --git a/datafusion/physical-expr/src/expressions/try_cast.rs b/datafusion/physical-expr/src/expressions/try_cast.rsindex d31306e239..3549a3df83 100644--- a/datafusion/physical-expr/src/expressions/try_cast.rs+++ b/datafusion/physical-expr/src/expressions/try_cast.rs@@ -106,7 +106,7 @@ impl PhysicalExpr for TryCastExpr {children: Vec<Arc<dyn PhysicalExpr>>,) -> Result<Arc<dyn PhysicalExpr>> {Ok(Arc::new(TryCastExpr::new(- children[0].clone(),+ Arc::clone(&children[0]),self.cast_type.clone(),)))}@@ -137,7 +137,7 @@ pub fn try_cast() -> Result<Arc<dyn PhysicalExpr>> {let expr_type = expr.data_type(input_schema)?;if expr_type == cast_type {- Ok(expr.clone())+ Ok(Arc::clone(&expr))} else if can_cast_types(&expr_type, &cast_type) {Ok(Arc::new(TryCastExpr::new(expr, cast_type)))} else {diff --git a/datafusion/physical-expr/src/intervals/cp_solver.rs b/datafusion/physical-expr/src/intervals/cp_solver.rsindex 6fbcd461af..ef9dd36cfb 100644--- a/datafusion/physical-expr/src/intervals/cp_solver.rs+++ b/datafusion/physical-expr/src/intervals/cp_solver.rs@@ -180,7 +180,7 @@ impl ExprIntervalGraphNode {/// object. Literals are created with definite, singleton intervals while/// any other expression starts with an indefinite interval ([-∞, ∞]).pub fn make_node(node: &ExprTreeNode<NodeIndex>, schema: &Schema) -> Result<Self> {- let expr = node.expr.clone();+ let expr = Arc::clone(&node.expr);if let Some(literal) = expr.as_any().downcast_ref::<Literal>() {let value = literal.value();Interval::try_new(value.clone(), value.clone())@@ -422,7 +422,7 @@ impl ExprIntervalGraph {let mut removals = vec![];let mut expr_node_indices = exprs.iter()- .map(|e| (e.clone(), usize::MAX))+ .map(|e| (Arc::clone(e), usize::MAX)).collect::<Vec<_>>();while let Some(node) = bfs.next(graph) {// Get the plan corresponding to this node:@@ -744,16 +744,17 @@ mod tests {schema: &Schema,) -> Result<()> {let col_stats = vec![- (exprs_with_interval.0.clone(), left_interval),- (exprs_with_interval.1.clone(), right_interval),+ (Arc::clone(&exprs_with_interval.0), left_interval),+ (Arc::clone(&exprs_with_interval.1), right_interval),];let expected = vec![- (exprs_with_interval.0.clone(), left_expected),- (exprs_with_interval.1.clone(), right_expected),+ (Arc::clone(&exprs_with_interval.0), left_expected),+ (Arc::clone(&exprs_with_interval.1), right_expected),];let mut graph = ExprIntervalGraph::try_new(expr, schema)?;- let expr_indexes = graph- .gather_node_indices(&col_stats.iter().map(|(e, _)| e.clone()).collect_vec());+ let expr_indexes = graph.gather_node_indices(+ &col_stats.iter().map(|(e, _)| Arc::clone(e)).collect_vec(),+ );let mut col_stat_nodes = col_stats.iter()@@ -870,14 +871,21 @@ mod tests {// left_watermark > right_watermark + 5let left_and_1 = Arc::new(BinaryExpr::new(- left_col.clone(),+ Arc::clone(&left_col) as Arc<dyn PhysicalExpr>,Operator::Plus,Arc::new(Literal::new(ScalarValue::Int32(Some(5)))),));- let expr = Arc::new(BinaryExpr::new(left_and_1, Operator::Gt, right_col.clone()));+ let expr = Arc::new(BinaryExpr::new(+ left_and_1,+ Operator::Gt,+ Arc::clone(&right_col) as Arc<dyn PhysicalExpr>,+ ));experiment(expr,- (left_col.clone(), right_col.clone()),+ (+ Arc::clone(&left_col) as Arc<dyn PhysicalExpr>,+ Arc::clone(&right_col) as Arc<dyn PhysicalExpr>,+ ),Interval::make(Some(10_i32), Some(20_i32))?,Interval::make(Some(100), None)?,Interval::make(Some(10), Some(20))?,diff --git a/datafusion/physical-expr/src/intervals/test_utils.rs b/datafusion/physical-expr/src/intervals/test_utils.rsindex 075b824035..cedf55bccb 100644--- a/datafusion/physical-expr/src/intervals/test_utils.rs+++ b/datafusion/physical-expr/src/intervals/test_utils.rs@@ -41,12 +41,12 @@ pub fn gen_conjunctive_numerical_expr() -> Arc<dyn PhysicalExpr> {let (op_1, op_2, op_3, op_4) = op;let left_and_1 = Arc::new(BinaryExpr::new(- left_col.clone(),+ Arc::clone(&left_col),op_1,Arc::new(Literal::new(a)),));let left_and_2 = Arc::new(BinaryExpr::new(- right_col.clone(),+ Arc::clone(&right_col),op_2,Arc::new(Literal::new(b)),));@@ -78,8 +78,18 @@ pub fn gen_conjunctive_temporal_expr(d: ScalarValue,schema: &Schema,) -> Result<Arc<dyn PhysicalExpr>, DataFusionError> {- let left_and_1 = binary(left_col.clone(), op_1, Arc::new(Literal::new(a)), schema)?;- let left_and_2 = binary(right_col.clone(), op_2, Arc::new(Literal::new(b)), schema)?;+ let left_and_1 = binary(+ Arc::clone(&left_col),+ op_1,+ Arc::new(Literal::new(a)),+ schema,+ )?;+ let left_and_2 = binary(+ Arc::clone(&right_col),+ op_2,+ Arc::new(Literal::new(b)),+ schema,+ )?;let right_and_1 = binary(left_col, op_3, Arc::new(Literal::new(c)), schema)?;let right_and_2 = binary(right_col, op_4, Arc::new(Literal::new(d)), schema)?;let left_expr = Arc::new(BinaryExpr::new(left_and_1, Operator::Gt, left_and_2));diff --git a/datafusion/physical-expr/src/lib.rs b/datafusion/physical-expr/src/lib.rsindex 06c7363677..4f83ae0195 100644--- a/datafusion/physical-expr/src/lib.rs+++ b/datafusion/physical-expr/src/lib.rs@@ -14,6 +14,8 @@// KIND, either express or implied. See the License for the// specific language governing permissions and limitations// under the License.+// Make cheap clones clear: https://github.com/apache/datafusion/issues/11143+#![deny(clippy::clone_on_ref_ptr)]pub mod aggregate;pub mod analysis;diff --git a/datafusion/physical-expr/src/partitioning.rs b/datafusion/physical-expr/src/partitioning.rsindex 273c77fb1d..821b2c9fe1 100644--- a/datafusion/physical-expr/src/partitioning.rs+++ b/datafusion/physical-expr/src/partitioning.rs@@ -169,11 +169,11 @@ impl Partitioning {if !eq_groups.is_empty() {let normalized_required_exprs = required_exprs.iter()- .map(|e| eq_groups.normalize_expr(e.clone()))+ .map(|e| eq_groups.normalize_expr(Arc::clone(e))).collect::<Vec<_>>();let normalized_partition_exprs = partition_exprs.iter()- .map(|e| eq_groups.normalize_expr(e.clone()))+ .map(|e| eq_groups.normalize_expr(Arc::clone(e))).collect::<Vec<_>>();return physical_exprs_equal(&normalized_required_exprs,diff --git a/datafusion/physical-expr/src/physical_expr.rs b/datafusion/physical-expr/src/physical_expr.rsindex 127194f681..c60a772b9c 100644--- a/datafusion/physical-expr/src/physical_expr.rs+++ b/datafusion/physical-expr/src/physical_expr.rs@@ -117,12 +117,12 @@ mod tests {// lit(true), lit(false), lit(4), lit(2), Col(a), Col(b)let physical_exprs: Vec<Arc<dyn PhysicalExpr>> = vec![- lit_true.clone(),- lit_false.clone(),- lit4.clone(),- lit2.clone(),- col_a_expr.clone(),- col_b_expr.clone(),+ Arc::clone(&lit_true),+ Arc::clone(&lit_false),+ Arc::clone(&lit4),+ Arc::clone(&lit2),+ Arc::clone(&col_a_expr),+ Arc::clone(&col_b_expr),];// below expressions are inside physical_exprsassert!(physical_exprs_contains(&physical_exprs, &lit_true));@@ -146,10 +146,10 @@ mod tests {Arc::new(Literal::new(ScalarValue::Int32(Some(2)))) as Arc<dyn PhysicalExpr>;let col_b_expr = Arc::new(Column::new("b", 1)) as Arc<dyn PhysicalExpr>;- let vec1 = vec![lit_true.clone(), lit_false.clone()];- let vec2 = vec![lit_true.clone(), col_b_expr.clone()];- let vec3 = vec![lit2.clone(), lit1.clone()];- let vec4 = vec![lit_true.clone(), lit_false.clone()];+ let vec1 = vec![Arc::clone(&lit_true), Arc::clone(&lit_false)];+ let vec2 = vec![Arc::clone(&lit_true), Arc::clone(&col_b_expr)];+ let vec3 = vec![Arc::clone(&lit2), Arc::clone(&lit1)];+ let vec4 = vec![Arc::clone(&lit_true), Arc::clone(&lit_false)];// these vectors are sameassert!(physical_exprs_equal(&vec1, &vec1));diff --git a/datafusion/physical-expr/src/planner.rs b/datafusion/physical-expr/src/planner.rsindex 8fe99cdca5..dbebf4c18b 100644--- a/datafusion/physical-expr/src/planner.rs+++ b/datafusion/physical-expr/src/planner.rs@@ -242,7 +242,7 @@ pub fn create_physical_expr(when_expr.iter().zip(then_expr.iter())- .map(|(w, t)| (w.clone(), t.clone()))+ .map(|(w, t)| (Arc::clone(w), Arc::clone(t))).collect();let else_expr: Option<Arc<dyn PhysicalExpr>> =if let Some(e) = &case.else_expr {@@ -288,7 +288,7 @@ pub fn create_physical_expr(create_physical_exprs(args, input_dfschema, execution_props)?;scalar_function::create_physical_expr(- func.clone().as_ref(),+ Arc::clone(func).as_ref(),&physical_args,input_schema,args,@@ -307,9 +307,19 @@ pub fn create_physical_expr(// rewrite the between into the two binary operatorslet binary_expr = binary(- binary(value_expr.clone(), Operator::GtEq, low_expr, input_schema)?,+ binary(+ Arc::clone(&value_expr),+ Operator::GtEq,+ low_expr,+ input_schema,+ )?,Operator::And,- binary(value_expr.clone(), Operator::LtEq, high_expr, input_schema)?,+ binary(+ Arc::clone(&value_expr),+ Operator::LtEq,+ high_expr,+ input_schema,+ )?,input_schema,);diff --git a/datafusion/physical-expr/src/scalar_function.rs b/datafusion/physical-expr/src/scalar_function.rsindex 10e29b4103..83272fc9b2 100644--- a/datafusion/physical-expr/src/scalar_function.rs+++ b/datafusion/physical-expr/src/scalar_function.rs@@ -153,7 +153,7 @@ impl PhysicalExpr for ScalarFunctionExpr {) -> Result<Arc<dyn PhysicalExpr>> {Ok(Arc::new(ScalarFunctionExpr::new(&self.name,- self.fun.clone(),+ Arc::clone(&self.fun),children,self.return_type().clone(),)))diff --git a/datafusion/physical-expr/src/utils/guarantee.rs b/datafusion/physical-expr/src/utils/guarantee.rsindex 070034116f..42e5e6fcf3 100644--- a/datafusion/physical-expr/src/utils/guarantee.rs+++ b/datafusion/physical-expr/src/utils/guarantee.rs@@ -870,14 +870,12 @@ mod test {// Schema for testingfn schema() -> SchemaRef {- SCHEMA- .get_or_init(|| {- Arc::new(Schema::new(vec![- Field::new("a", DataType::Utf8, false),- Field::new("b", DataType::Int32, false),- ]))- })- .clone()+ Arc::clone(SCHEMA.get_or_init(|| {+ Arc::new(Schema::new(vec![+ Field::new("a", DataType::Utf8, false),+ Field::new("b", DataType::Int32, false),+ ]))+ }))}static SCHEMA: OnceLock<SchemaRef> = OnceLock::new();diff --git a/datafusion/physical-expr/src/utils/mod.rs b/datafusion/physical-expr/src/utils/mod.rsindex 492cb02941..a33f65f92a 100644--- a/datafusion/physical-expr/src/utils/mod.rs+++ b/datafusion/physical-expr/src/utils/mod.rs@@ -111,7 +111,7 @@ pub fn convert_to_expr<T: Borrow<PhysicalSortExpr>>() -> Vec<Arc<dyn PhysicalExpr>> {sequence.into_iter()- .map(|elem| elem.borrow().expr.clone())+ .map(|elem| Arc::clone(&elem.borrow().expr)).collect()}@@ -166,7 +166,7 @@ impl<'a, T, F: Fn(&ExprTreeNode<NodeIndex>) -> Result<T>>for expr_node in node.children.iter() {self.graph.add_edge(node_idx, expr_node.data.unwrap(), 0);}- self.visited_plans.push((expr.clone(), node_idx));+ self.visited_plans.push((Arc::clone(expr), node_idx));node_idx}};@@ -379,7 +379,7 @@ pub(crate) mod tests {}fn make_dummy_node(node: &ExprTreeNode<NodeIndex>) -> Result<PhysicalExprDummyNode> {- let expr = node.expr.clone();+ let expr = Arc::clone(&node.expr);let dummy_property = if expr.as_any().is::<BinaryExpr>() {"Binary"} else if expr.as_any().is::<Column>() {diff --git a/datafusion/physical-expr/src/window/built_in.rs b/datafusion/physical-expr/src/window/built_in.rsindex 065260a73e..04d359903e 100644--- a/datafusion/physical-expr/src/window/built_in.rs+++ b/datafusion/physical-expr/src/window/built_in.rs@@ -137,7 +137,7 @@ impl WindowExpr for BuiltInWindowExpr {let order_bys_ref = &values[n_args..];let mut window_frame_ctx =- WindowFrameContext::new(self.window_frame.clone(), sort_options);+ WindowFrameContext::new(Arc::clone(&self.window_frame), sort_options);let mut last_range = Range { start: 0, end: 0 };// We iterate on each row to calculate window frame range and and window function resultfor idx in 0..num_rows {@@ -217,7 +217,7 @@ impl WindowExpr for BuiltInWindowExpr {.window_frame_ctx.get_or_insert_with(|| {WindowFrameContext::new(- self.window_frame.clone(),+ Arc::clone(&self.window_frame),sort_options.clone(),)})diff --git a/datafusion/physical-expr/src/window/lead_lag.rs b/datafusion/physical-expr/src/window/lead_lag.rsindex 9a7c89dca5..1656b7c303 100644--- a/datafusion/physical-expr/src/window/lead_lag.rs+++ b/datafusion/physical-expr/src/window/lead_lag.rs@@ -104,7 +104,7 @@ impl BuiltInWindowFunctionExpr for WindowShift {}fn expressions(&self) -> Vec<Arc<dyn PhysicalExpr>> {- vec![self.expr.clone()]+ vec![Arc::clone(&self.expr)]}fn name(&self) -> &str {@@ -125,7 +125,7 @@ impl BuiltInWindowFunctionExpr for WindowShift {name: self.name.clone(),data_type: self.data_type.clone(),shift_offset: -self.shift_offset,- expr: self.expr.clone(),+ expr: Arc::clone(&self.expr),default_value: self.default_value.clone(),ignore_nulls: self.ignore_nulls,}))@@ -209,7 +209,7 @@ fn shift_with_default_value(let value_len = array.len() as i64;if offset == 0 {- Ok(array.clone())+ Ok(Arc::clone(array))} else if offset == i64::MIN || offset.abs() >= value_len {default_value.to_array_of_size(value_len as usize)} else {diff --git a/datafusion/physical-expr/src/window/nth_value.rs b/datafusion/physical-expr/src/window/nth_value.rsindex 4bd40066ff..87c74579c6 100644--- a/datafusion/physical-expr/src/window/nth_value.rs+++ b/datafusion/physical-expr/src/window/nth_value.rs@@ -116,7 +116,7 @@ impl BuiltInWindowFunctionExpr for NthValue {}fn expressions(&self) -> Vec<Arc<dyn PhysicalExpr>> {- vec![self.expr.clone()]+ vec![Arc::clone(&self.expr)]}fn name(&self) -> &str {@@ -142,7 +142,7 @@ impl BuiltInWindowFunctionExpr for NthValue {};Some(Arc::new(Self {name: self.name.clone(),- expr: self.expr.clone(),+ expr: Arc::clone(&self.expr),data_type: self.data_type.clone(),kind: reversed_kind,ignore_nulls: self.ignore_nulls,diff --git a/datafusion/physical-expr/src/window/sliding_aggregate.rs b/datafusion/physical-expr/src/window/sliding_aggregate.rsindex 961f0884dd..50e9632b21 100644--- a/datafusion/physical-expr/src/window/sliding_aggregate.rs+++ b/datafusion/physical-expr/src/window/sliding_aggregate.rs@@ -163,7 +163,7 @@ impl WindowExpr for SlidingAggregateWindowExpr {aggregate: self.aggregate.with_new_expressions(args, vec![])?,partition_by: partition_bys,order_by: new_order_by,- window_frame: self.window_frame.clone(),+ window_frame: Arc::clone(&self.window_frame),}))}}diff --git a/datafusion/physical-expr/src/window/window_expr.rs b/datafusion/physical-expr/src/window/window_expr.rsindex 3cf68379d7..7020f7f5cf 100644--- a/datafusion/physical-expr/src/window/window_expr.rs+++ b/datafusion/physical-expr/src/window/window_expr.rs@@ -137,7 +137,7 @@ pub trait WindowExpr: Send + Sync + Debug {let order_by_exprs = self.order_by().iter()- .map(|sort_expr| sort_expr.expr.clone())+ .map(|sort_expr| Arc::clone(&sort_expr.expr)).collect::<Vec<_>>();WindowPhysicalExpressions {args,@@ -193,7 +193,7 @@ pub trait AggregateWindowExpr: WindowExpr {let sort_options: Vec<SortOptions> =self.order_by().iter().map(|o| o.options).collect();let mut window_frame_ctx =- WindowFrameContext::new(self.get_window_frame().clone(), sort_options);+ WindowFrameContext::new(Arc::clone(self.get_window_frame()), sort_options);self.get_result_column(&mut accumulator,batch,@@ -241,7 +241,7 @@ pub trait AggregateWindowExpr: WindowExpr {let window_frame_ctx = state.window_frame_ctx.get_or_insert_with(|| {let sort_options: Vec<SortOptions> =self.order_by().iter().map(|o| o.options).collect();- WindowFrameContext::new(self.get_window_frame().clone(), sort_options)+ WindowFrameContext::new(Arc::clone(self.get_window_frame()), sort_options)});let out_col = self.get_result_column(accumulator,