Apache DataFusion SQL Query Engine
Enable clone_on_ref_ptr clippy lint on execution crate (#11239)
张林伟4615a2d56cda
diff --git a/datafusion/execution/src/cache/cache_manager.rs b/datafusion/execution/src/cache/cache_manager.rsindex 9752926368..c2403e34c6 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<Arc<Self>> {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.rsindex 25f9b9fa4d..a9291659a3 100644--- a/datafusion/execution/src/cache/cache_unit.rs+++ b/datafusion/execution/src/cache/cache_unit.rs@@ -39,7 +39,7 @@ impl CacheAccessor<Path, Arc<Statistics>> for DefaultFileStatisticsCache {fn get(&self, k: &Path) -> Option<Arc<Statistics>> {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<Path, Arc<Statistics>> for DefaultFileStatisticsCache {// file has changedNone} else {- Some(statistics.clone())+ Some(Arc::clone(statistics))}}).unwrap_or(None)@@ -108,7 +108,7 @@ impl CacheAccessor<Path, Arc<Vec<ObjectMeta>>> for DefaultListFilesCache {type Extra = ObjectMeta;fn get(&self, k: &Path) -> Option<Arc<Vec<ObjectMeta>>> {- 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.rsindex 85cc6f8499..cca25c7c3e 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.rsindex 2fe0d83b1d..909364fa80 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 structuresdiff --git a/datafusion/execution/src/memory_pool/mod.rs b/datafusion/execution/src/memory_pool/mod.rsindex 321a89127b..3f66a304dc 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.rsindex 3ba21e399f..9e1d94b346 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.rsindex b3a510ef2a..c21ce3d21d 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<RuntimeEnv> {- self.runtime.clone()+ Arc::clone(&self.runtime)}/// Update the [`SessionConfig`]@@ -172,19 +172,22 @@ impl FunctionRegistry for TaskContext {udaf: Arc<AggregateUDF>,) -> Result<Option<Arc<AggregateUDF>>> {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<WindowUDF>) -> Result<Option<Arc<WindowUDF>>> {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<ScalarUDF>) -> Result<Option<Arc<ScalarUDF>>> {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))}