diff --git a/datafusion/execution/src/cache/cache_manager.rs b/datafusion/execution/src/cache/cache_manager.rs index 97529263688bf..c2403e34c6657 100644 --- a/datafusion/execution/src/cache/cache_manager.rs +++ b/datafusion/execution/src/cache/cache_manager.rs @@ -54,10 +54,10 @@ impl CacheManager { pub fn try_new(config: &CacheManagerConfig) -> Result> { let mut manager = CacheManager::default(); if let Some(cc) = &config.table_files_statistics_cache { - manager.file_statistic_cache = Some(cc.clone()) + manager.file_statistic_cache = Some(Arc::clone(cc)) } if let Some(lc) = &config.list_files_cache { - manager.list_files_cache = Some(lc.clone()) + manager.list_files_cache = Some(Arc::clone(lc)) } Ok(Arc::new(manager)) } diff --git a/datafusion/execution/src/cache/cache_unit.rs b/datafusion/execution/src/cache/cache_unit.rs index 25f9b9fa4d687..a9291659a3efa 100644 --- a/datafusion/execution/src/cache/cache_unit.rs +++ b/datafusion/execution/src/cache/cache_unit.rs @@ -39,7 +39,7 @@ impl CacheAccessor> for DefaultFileStatisticsCache { fn get(&self, k: &Path) -> Option> { self.statistics .get(k) - .map(|s| Some(s.value().1.clone())) + .map(|s| Some(Arc::clone(&s.value().1))) .unwrap_or(None) } @@ -55,7 +55,7 @@ impl CacheAccessor> for DefaultFileStatisticsCache { // file has changed None } else { - Some(statistics.clone()) + Some(Arc::clone(statistics)) } }) .unwrap_or(None) @@ -108,7 +108,7 @@ impl CacheAccessor>> for DefaultListFilesCache { type Extra = ObjectMeta; fn get(&self, k: &Path) -> Option>> { - self.statistics.get(k).map(|x| x.value().clone()) + self.statistics.get(k).map(|x| Arc::clone(x.value())) } fn get_with_extra( diff --git a/datafusion/execution/src/disk_manager.rs b/datafusion/execution/src/disk_manager.rs index 85cc6f8499f05..cca25c7c3e885 100644 --- a/datafusion/execution/src/disk_manager.rs +++ b/datafusion/execution/src/disk_manager.rs @@ -139,7 +139,7 @@ impl DiskManager { let dir_index = thread_rng().gen_range(0..local_dirs.len()); Ok(RefCountedTempFile { - parent_temp_dir: local_dirs[dir_index].clone(), + parent_temp_dir: Arc::clone(&local_dirs[dir_index]), tempfile: Builder::new() .tempfile_in(local_dirs[dir_index].as_ref()) .map_err(DataFusionError::IoError)?, diff --git a/datafusion/execution/src/lib.rs b/datafusion/execution/src/lib.rs index 2fe0d83b1d1c4..909364fa805da 100644 --- a/datafusion/execution/src/lib.rs +++ b/datafusion/execution/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)] //! DataFusion execution configuration and runtime structures diff --git a/datafusion/execution/src/memory_pool/mod.rs b/datafusion/execution/src/memory_pool/mod.rs index 321a89127be71..3f66a304dc18c 100644 --- a/datafusion/execution/src/memory_pool/mod.rs +++ b/datafusion/execution/src/memory_pool/mod.rs @@ -268,7 +268,7 @@ impl MemoryReservation { self.size = self.size.checked_sub(capacity).unwrap(); Self { size: capacity, - registration: self.registration.clone(), + registration: Arc::clone(&self.registration), } } @@ -276,7 +276,7 @@ impl MemoryReservation { pub fn new_empty(&self) -> Self { Self { size: 0, - registration: self.registration.clone(), + registration: Arc::clone(&self.registration), } } diff --git a/datafusion/execution/src/object_store.rs b/datafusion/execution/src/object_store.rs index 3ba21e399f93a..9e1d94b346eb4 100644 --- a/datafusion/execution/src/object_store.rs +++ b/datafusion/execution/src/object_store.rs @@ -234,7 +234,7 @@ impl ObjectStoreRegistry for DefaultObjectStoreRegistry { let s = get_url_key(url); self.object_stores .get(&s) - .map(|o| o.value().clone()) + .map(|o| Arc::clone(o.value())) .ok_or_else(|| { DataFusionError::Internal(format!( "No suitable object store found for {url}. See `RuntimeEnv::register_object_store`" diff --git a/datafusion/execution/src/task.rs b/datafusion/execution/src/task.rs index b3a510ef2a3f5..c21ce3d21da10 100644 --- a/datafusion/execution/src/task.rs +++ b/datafusion/execution/src/task.rs @@ -121,7 +121,7 @@ impl TaskContext { /// Return the [RuntimeEnv] associated with this [TaskContext] pub fn runtime_env(&self) -> Arc { - self.runtime.clone() + Arc::clone(&self.runtime) } /// Update the [`SessionConfig`] @@ -172,19 +172,22 @@ impl FunctionRegistry for TaskContext { udaf: Arc, ) -> Result>> { udaf.aliases().iter().for_each(|alias| { - self.aggregate_functions.insert(alias.clone(), udaf.clone()); + self.aggregate_functions + .insert(alias.clone(), Arc::clone(&udaf)); }); Ok(self.aggregate_functions.insert(udaf.name().into(), udaf)) } fn register_udwf(&mut self, udwf: Arc) -> Result>> { udwf.aliases().iter().for_each(|alias| { - self.window_functions.insert(alias.clone(), udwf.clone()); + self.window_functions + .insert(alias.clone(), Arc::clone(&udwf)); }); Ok(self.window_functions.insert(udwf.name().into(), udwf)) } fn register_udf(&mut self, udf: Arc) -> Result>> { udf.aliases().iter().for_each(|alias| { - self.scalar_functions.insert(alias.clone(), udf.clone()); + self.scalar_functions + .insert(alias.clone(), Arc::clone(&udf)); }); Ok(self.scalar_functions.insert(udf.name().into(), udf)) }