diff --git a/datafusion/physical-expr-common/src/binary_map.rs b/datafusion/physical-expr-common/src/binary_map.rs index 80c4963ae035..59280a3abbdb 100644 --- a/datafusion/physical-expr-common/src/binary_map.rs +++ b/datafusion/physical-expr-common/src/binary_map.rs @@ -349,7 +349,7 @@ where let batch_hashes = &mut self.hashes_buffer; batch_hashes.clear(); batch_hashes.resize(values.len(), 0); - create_hashes(&[values.clone()], &self.random_state, batch_hashes) + create_hashes(&[Arc::clone(values)], &self.random_state, batch_hashes) // hash is supported for all types and create_hashes only // returns errors for unsupported types .unwrap(); diff --git a/datafusion/physical-expr-common/src/binary_view_map.rs b/datafusion/physical-expr-common/src/binary_view_map.rs index e131ad8f5085..8af35510dd6c 100644 --- a/datafusion/physical-expr-common/src/binary_view_map.rs +++ b/datafusion/physical-expr-common/src/binary_view_map.rs @@ -244,7 +244,7 @@ where let batch_hashes = &mut self.hashes_buffer; batch_hashes.clear(); batch_hashes.resize(values.len(), 0); - create_hashes(&[values.clone()], &self.random_state, batch_hashes) + create_hashes(&[Arc::clone(values)], &self.random_state, batch_hashes) // hash is supported for all types and create_hashes only // returns errors for unsupported types .unwrap(); diff --git a/datafusion/physical-expr-common/src/lib.rs b/datafusion/physical-expr-common/src/lib.rs index 7e2ea0c49397..a05f1c96306f 100644 --- a/datafusion/physical-expr-common/src/lib.rs +++ b/datafusion/physical-expr-common/src/lib.rs @@ -15,6 +15,9 @@ // 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)] + //! Physical Expr Common packages for [DataFusion] //! This package contains high level PhysicalExpr trait //! diff --git a/datafusion/physical-expr-common/src/tree_node.rs b/datafusion/physical-expr-common/src/tree_node.rs index d9892ce55509..c37e67575bf0 100644 --- a/datafusion/physical-expr-common/src/tree_node.rs +++ b/datafusion/physical-expr-common/src/tree_node.rs @@ -62,7 +62,7 @@ impl ExprContext { } pub fn update_expr_from_children(mut self) -> Result { - let children_expr = self.children.iter().map(|c| c.expr.clone()).collect(); + let children_expr = self.children.iter().map(|c| Arc::clone(&c.expr)).collect(); self.expr = with_new_children_if_necessary(self.expr, children_expr)?; Ok(self) } diff --git a/datafusion/physical-expr-common/src/utils.rs b/datafusion/physical-expr-common/src/utils.rs index ffdab6c6d385..114007bfa6af 100644 --- a/datafusion/physical-expr-common/src/utils.rs +++ b/datafusion/physical-expr-common/src/utils.rs @@ -99,7 +99,7 @@ pub fn scatter(mask: &BooleanArray, truthy: &dyn Array) -> Result { pub fn reverse_order_bys(order_bys: &LexOrdering) -> LexOrdering { order_bys .iter() - .map(|e| PhysicalSortExpr::new(e.expr.clone(), !e.options)) + .map(|e| PhysicalSortExpr::new(Arc::clone(&e.expr), !e.options)) .collect() }