Apache DataFusion SQL Query Engine
chore(core): Enforce lint rule `clippy::needless_pass_by_value` to `datafusion-core` (#18640)
Alan Tanga9ad712d1c8b
diff --git a/datafusion/core/src/dataframe/mod.rs b/datafusion/core/src/dataframe/mod.rsindex aa378d4262..2b94bcf63b 100644--- a/datafusion/core/src/dataframe/mod.rs+++ b/datafusion/core/src/dataframe/mod.rs@@ -2392,6 +2392,7 @@ impl DataFrame {/// # Ok(())/// # }/// ```+ #[allow(clippy::needless_pass_by_value)]pub fn fill_null(&self,value: ScalarValue,diff --git a/datafusion/core/src/datasource/physical_plan/csv.rs b/datafusion/core/src/datasource/physical_plan/csv.rsindex ac5df24d49..1af6b330fd 100644--- a/datafusion/core/src/datasource/physical_plan/csv.rs+++ b/datafusion/core/src/datasource/physical_plan/csv.rs@@ -33,6 +33,7 @@ mod tests {use datafusion_datasource_csv::CsvFormat;use object_store::ObjectStore;+ use crate::datasource::file_format::FileFormat;use crate::prelude::CsvReadOptions;use crate::prelude::SessionContext;use crate::test::partitioned_file_groups;@@ -104,12 +105,13 @@ mod tests {let path = format!("{}/csv", arrow_test_data());let filename = "aggregate_test_100.csv";let tmp_dir = TempDir::new()?;+ let csv_format: Arc<dyn FileFormat> = Arc::new(CsvFormat::default());let file_groups = partitioned_file_groups(path.as_str(),filename,1,- Arc::new(CsvFormat::default()),+ &csv_format,file_compression_type.to_owned(),tmp_dir.path(),)?;@@ -176,12 +178,13 @@ mod tests {let path = format!("{}/csv", arrow_test_data());let filename = "aggregate_test_100.csv";let tmp_dir = TempDir::new()?;+ let csv_format: Arc<dyn FileFormat> = Arc::new(CsvFormat::default());let file_groups = partitioned_file_groups(path.as_str(),filename,1,- Arc::new(CsvFormat::default()),+ &csv_format,file_compression_type.to_owned(),tmp_dir.path(),)?;@@ -247,12 +250,13 @@ mod tests {let path = format!("{}/csv", arrow_test_data());let filename = "aggregate_test_100.csv";let tmp_dir = TempDir::new()?;+ let csv_format: Arc<dyn FileFormat> = Arc::new(CsvFormat::default());let file_groups = partitioned_file_groups(path.as_str(),filename,1,- Arc::new(CsvFormat::default()),+ &csv_format,file_compression_type.to_owned(),tmp_dir.path(),)?;@@ -317,12 +321,13 @@ mod tests {let path = format!("{}/csv", arrow_test_data());let filename = "aggregate_test_100.csv";let tmp_dir = TempDir::new()?;+ let csv_format: Arc<dyn FileFormat> = Arc::new(CsvFormat::default());let file_groups = partitioned_file_groups(path.as_str(),filename,1,- Arc::new(CsvFormat::default()),+ &csv_format,file_compression_type.to_owned(),tmp_dir.path(),)?;@@ -378,12 +383,13 @@ mod tests {let path = format!("{}/csv", arrow_test_data());let filename = "aggregate_test_100.csv";let tmp_dir = TempDir::new()?;+ let csv_format: Arc<dyn FileFormat> = Arc::new(CsvFormat::default());let mut file_groups = partitioned_file_groups(path.as_str(),filename,1,- Arc::new(CsvFormat::default()),+ &csv_format,file_compression_type.to_owned(),tmp_dir.path(),)?;@@ -489,12 +495,13 @@ mod tests {let path = format!("{}/csv", arrow_test_data());let filename = "aggregate_test_100.csv";let tmp_dir = TempDir::new()?;+ let csv_format: Arc<dyn FileFormat> = Arc::new(CsvFormat::default());let file_groups = partitioned_file_groups(path.as_str(),filename,1,- Arc::new(CsvFormat::default()),+ &csv_format,file_compression_type.to_owned(),tmp_dir.path(),)diff --git a/datafusion/core/src/datasource/physical_plan/json.rs b/datafusion/core/src/datasource/physical_plan/json.rsindex de7e87d25c..f36708901a 100644--- a/datafusion/core/src/datasource/physical_plan/json.rs+++ b/datafusion/core/src/datasource/physical_plan/json.rs@@ -69,11 +69,13 @@ mod tests {let store = state.runtime_env().object_store(&store_url).unwrap();let filename = "1.json";+ let json_format: Arc<dyn FileFormat> = Arc::new(JsonFormat::default());+let file_groups = partitioned_file_groups(TEST_DATA_BASE,filename,1,- Arc::new(JsonFormat::default()),+ &json_format,file_compression_type.to_owned(),work_dir,)@@ -104,11 +106,13 @@ mod tests {ctx.register_object_store(&url, store.clone());let filename = "1.json";let tmp_dir = TempDir::new()?;+ let json_format: Arc<dyn FileFormat> = Arc::new(JsonFormat::default());+let file_groups = partitioned_file_groups(TEST_DATA_BASE,filename,1,- Arc::new(JsonFormat::default()),+ &json_format,file_compression_type.to_owned(),tmp_dir.path(),)diff --git a/datafusion/core/src/execution/context/mod.rs b/datafusion/core/src/execution/context/mod.rsindex c732c2c92f..bca4cce9ba 100644--- a/datafusion/core/src/execution/context/mod.rs+++ b/datafusion/core/src/execution/context/mod.rs@@ -1054,18 +1054,18 @@ impl SessionContext {} else if allow_missing {return self.return_empty_dataframe();} else {- return self.schema_doesnt_exist_err(name);+ return self.schema_doesnt_exist_err(&name);}};let dereg = catalog.deregister_schema(name.schema_name(), cascade)?;match (dereg, allow_missing) {(None, true) => self.return_empty_dataframe(),- (None, false) => self.schema_doesnt_exist_err(name),+ (None, false) => self.schema_doesnt_exist_err(&name),(Some(_), _) => self.return_empty_dataframe(),}}- fn schema_doesnt_exist_err(&self, schemaref: SchemaReference) -> Result<DataFrame> {+ fn schema_doesnt_exist_err(&self, schemaref: &SchemaReference) -> Result<DataFrame> {exec_err!("Schema '{schemaref}' doesn't exist.")}diff --git a/datafusion/core/src/lib.rs b/datafusion/core/src/lib.rsindex 381dd5e9e8..2408488d04 100644--- a/datafusion/core/src/lib.rs+++ b/datafusion/core/src/lib.rs@@ -35,6 +35,8 @@))]#![warn(missing_docs, clippy::needless_borrow)]+#![deny(clippy::needless_pass_by_value)]+#![cfg_attr(test, allow(clippy::needless_pass_by_value))]//! [DataFusion] is an extensible query engine written in Rust that//! uses [Apache Arrow] as its in-memory format. DataFusion's target users arediff --git a/datafusion/core/src/physical_planner.rs b/datafusion/core/src/physical_planner.rsindex f10755a459..154fd6f9cb 100644--- a/datafusion/core/src/physical_planner.rs+++ b/datafusion/core/src/physical_planner.rs@@ -498,7 +498,7 @@ impl DefaultPhysicalPlanner {output_schema,}) => {let output_schema = Arc::clone(output_schema.inner());- self.plan_describe(Arc::clone(schema), output_schema)?+ self.plan_describe(&Arc::clone(schema), output_schema)?}// 1 Child@@ -2246,6 +2246,7 @@ impl DefaultPhysicalPlanner {/// Optimize a physical plan by applying each physical optimizer,/// calling observer(plan, optimizer after each one)+ #[allow(clippy::needless_pass_by_value)]pub fn optimize_physical_plan<F>(&self,plan: Arc<dyn ExecutionPlan>,@@ -2280,7 +2281,7 @@ impl DefaultPhysicalPlanner {// This only checks the schema in release build, and performs additional checks in debug mode.OptimizationInvariantChecker::new(optimizer)- .check(&new_plan, before_schema)?;+ .check(&new_plan, &before_schema)?;debug!("Optimized physical plan by {}:\n{}\n",@@ -2313,7 +2314,7 @@ impl DefaultPhysicalPlanner {// return an record_batch which describes a table's schema.fn plan_describe(&self,- table_schema: Arc<Schema>,+ table_schema: &Arc<Schema>,output_schema: Arc<Schema>,) -> Result<Arc<dyn ExecutionPlan>> {let mut column_names = StringBuilder::new();@@ -2516,10 +2517,10 @@ impl<'a> OptimizationInvariantChecker<'a> {pub fn check(&mut self,plan: &Arc<dyn ExecutionPlan>,- previous_schema: Arc<Schema>,+ previous_schema: &Arc<Schema>,) -> Result<()> {// if the rule is not permitted to change the schema, confirm that it did not change.- if self.rule.schema_check() && plan.schema() != previous_schema {+ if self.rule.schema_check() && plan.schema() != *previous_schema {internal_err!("PhysicalOptimizer rule '{}' failed. Schema mismatch. Expected original schema: {:?}, got new schema: {:?}",self.rule.name(),previous_schema,@@ -3709,20 +3710,20 @@ digraph {// Test: check should pass with same schemalet equal_schema = ok_plan.schema();- OptimizationInvariantChecker::new(&rule).check(&ok_plan, equal_schema)?;+ OptimizationInvariantChecker::new(&rule).check(&ok_plan, &equal_schema)?;// Test: should fail with schema changedlet different_schema =Arc::new(Schema::new(vec![Field::new("a", DataType::Boolean, false)]));let expected_err = OptimizationInvariantChecker::new(&rule)- .check(&ok_plan, different_schema)+ .check(&ok_plan, &different_schema).unwrap_err();assert!(expected_err.to_string().contains("PhysicalOptimizer rule 'OptimizerRuleWithSchemaCheck' failed. Schema mismatch. Expected original schema"));// Test: should fail when extension node fails it's own invariant checklet failing_node: Arc<dyn ExecutionPlan> = Arc::new(InvariantFailsExtensionNode);let expected_err = OptimizationInvariantChecker::new(&rule)- .check(&failing_node, ok_plan.schema())+ .check(&failing_node, &ok_plan.schema()).unwrap_err();assert!(expected_err.to_string()@@ -3735,7 +3736,7 @@ digraph {Arc::clone(&child),])?;let expected_err = OptimizationInvariantChecker::new(&rule)- .check(&invalid_plan, ok_plan.schema())+ .check(&invalid_plan, &ok_plan.schema()).unwrap_err();assert!(expected_err.to_string()diff --git a/datafusion/core/src/test/mod.rs b/datafusion/core/src/test/mod.rsindex bbc85af7d8..3a50167594 100644--- a/datafusion/core/src/test/mod.rs+++ b/datafusion/core/src/test/mod.rs@@ -87,11 +87,13 @@ pub fn scan_partitioned_csv(let schema = aggr_test_schema();let filename = "aggregate_test_100.csv";let path = format!("{}/csv", arrow_test_data());+ let csv_format: Arc<dyn FileFormat> = Arc::new(CsvFormat::default());+let file_groups = partitioned_file_groups(path.as_str(),filename,partitions,- Arc::new(CsvFormat::default()),+ &csv_format,FileCompressionType::UNCOMPRESSED,work_dir,)?;@@ -114,7 +116,7 @@ pub fn partitioned_file_groups(path: &str,filename: &str,partitions: usize,- file_format: Arc<dyn FileFormat>,+ file_format: &Arc<dyn FileFormat>,file_compression_type: FileCompressionType,work_dir: &Path,) -> Result<Vec<FileGroup>> {@@ -198,7 +200,7 @@ pub fn partitioned_file_groups(.collect::<Vec<_>>())}-pub fn assert_fields_eq(plan: &LogicalPlan, expected: Vec<&str>) {+pub fn assert_fields_eq(plan: &LogicalPlan, expected: &[&str]) {let actual: Vec<String> = plan.schema().fields()