Apache DataFusion SQL Query Engine
Resolve linter errors (#7753)
Mustafa Akur85046001da91
diff --git a/datafusion/core/benches/topk_aggregate.rs b/datafusion/core/benches/topk_aggregate.rsindex eaafea2488..ef84d6e3ca 100644--- a/datafusion/core/benches/topk_aggregate.rs+++ b/datafusion/core/benches/topk_aggregate.rs@@ -28,6 +28,7 @@ use datafusion_execution::config::SessionConfig;use datafusion_execution::TaskContext;use rand_distr::Distribution;use rand_distr::{Normal, Pareto};+use std::fmt::Write;use std::sync::Arc;use tokio::runtime::Runtime;@@ -130,8 +131,10 @@ fn make_data(let gen_id = |rng: &mut rand::rngs::SmallRng| {rng.gen::<[u8; 16]>().iter()- .map(|b| format!("{:02x}", b))- .collect::<String>()+ .fold(String::new(), |mut output, b| {+ let _ = write!(output, "{b:02X}");+ output+ })};let gen_sample_cnt =|mut rng: &mut rand::rngs::SmallRng| pareto.sample(&mut rng).ceil() as u32;diff --git a/datafusion/core/src/catalog/mod.rs b/datafusion/core/src/catalog/mod.rsindex 6751edbd3a..fe5bdc0ec6 100644--- a/datafusion/core/src/catalog/mod.rs+++ b/datafusion/core/src/catalog/mod.rs@@ -31,7 +31,7 @@ use std::sync::Arc;/// Represent a list of named catalogspub trait CatalogList: Sync + Send {- /// Returns the catalog list as [`Any`](std::any::Any)+ /// Returns the catalog list as [`Any`]/// so that it can be downcast to a specific implementation.fn as_any(&self) -> &dyn Any;@@ -101,7 +101,7 @@ impl Default for MemoryCatalogProvider {/// Represents a catalog, comprising a number of named schemas.pub trait CatalogProvider: Sync + Send {- /// Returns the catalog provider as [`Any`](std::any::Any)+ /// Returns the catalog provider as [`Any`]/// so that it can be downcast to a specific implementation.fn as_any(&self) -> &dyn Any;diff --git a/datafusion/core/src/datasource/default_table_source.rs b/datafusion/core/src/datasource/default_table_source.rsindex 58d0997bb6..f93faa50a9 100644--- a/datafusion/core/src/datasource/default_table_source.rs+++ b/datafusion/core/src/datasource/default_table_source.rs@@ -43,7 +43,7 @@ impl DefaultTableSource {}impl TableSource for DefaultTableSource {- /// Returns the table source as [`Any`](std::any::Any) so that it can be+ /// Returns the table source as [`Any`] so that it can be/// downcast to a specific implementation.fn as_any(&self) -> &dyn Any {selfdiff --git a/datafusion/core/src/datasource/file_format/parquet.rs b/datafusion/core/src/datasource/file_format/parquet.rsindex 16050d66db..8ddddab71f 100644--- a/datafusion/core/src/datasource/file_format/parquet.rs+++ b/datafusion/core/src/datasource/file_format/parquet.rs@@ -1101,7 +1101,7 @@ pub(crate) mod test_util {Ok((meta, files))}- //// write batches chunk_size rows at a time+ /// write batches chunk_size rows at a timefn write_in_chunks<W: std::io::Write + Send>(writer: &mut ArrowWriter<W>,batch: &RecordBatch,diff --git a/datafusion/core/src/physical_optimizer/enforce_distribution.rs b/datafusion/core/src/physical_optimizer/enforce_distribution.rsindex 3463f3a313..a1f509d287 100644--- a/datafusion/core/src/physical_optimizer/enforce_distribution.rs+++ b/datafusion/core/src/physical_optimizer/enforce_distribution.rs@@ -1529,7 +1529,7 @@ impl DistributionContext {self.plan.children().into_iter()- .map(|child| DistributionContext::new(child))+ .map(DistributionContext::new).collect()}}diff --git a/datafusion/core/src/physical_optimizer/enforce_sorting.rs b/datafusion/core/src/physical_optimizer/enforce_sorting.rsindex 6e3b160c89..95ec1973d0 100644--- a/datafusion/core/src/physical_optimizer/enforce_sorting.rs+++ b/datafusion/core/src/physical_optimizer/enforce_sorting.rs@@ -151,7 +151,7 @@ impl PlanWithCorrespondingSort {self.plan.children().into_iter()- .map(|child| PlanWithCorrespondingSort::new(child))+ .map(PlanWithCorrespondingSort::new).collect()}}@@ -267,7 +267,7 @@ impl PlanWithCorrespondingCoalescePartitions {self.plan.children().into_iter()- .map(|child| PlanWithCorrespondingCoalescePartitions::new(child))+ .map(PlanWithCorrespondingCoalescePartitions::new).collect()}}@@ -602,7 +602,7 @@ fn analyze_window_sort_removal(let reqs = window_exec.required_input_ordering().swap_remove(0)- .unwrap_or(vec![]);+ .unwrap_or_default();let sort_expr = PhysicalSortRequirement::to_sort_exprs(reqs);// Satisfy the ordering requirement so that the window can run:add_sort_above(&mut window_child, sort_expr, None)?;diff --git a/datafusion/core/src/physical_optimizer/pipeline_checker.rs b/datafusion/core/src/physical_optimizer/pipeline_checker.rsindex 44679647b5..3b994d5f89 100644--- a/datafusion/core/src/physical_optimizer/pipeline_checker.rs+++ b/datafusion/core/src/physical_optimizer/pipeline_checker.rs@@ -108,7 +108,7 @@ impl TreeNode for PipelineStatePropagator {if !children.is_empty() {let new_children = children.into_iter()- .map(|child| PipelineStatePropagator::new(child))+ .map(PipelineStatePropagator::new).map(transform).collect::<Result<Vec<_>>>()?;let children_unbounded = new_childrendiff --git a/datafusion/core/src/physical_optimizer/replace_with_order_preserving_variants.rs b/datafusion/core/src/physical_optimizer/replace_with_order_preserving_variants.rsindex cb3b6c3d07..ede95fc677 100644--- a/datafusion/core/src/physical_optimizer/replace_with_order_preserving_variants.rs+++ b/datafusion/core/src/physical_optimizer/replace_with_order_preserving_variants.rs@@ -112,7 +112,7 @@ impl OrderPreservationContext {self.plan.children().into_iter()- .map(|child| OrderPreservationContext::new(child))+ .map(OrderPreservationContext::new).collect()}}diff --git a/datafusion/core/src/physical_optimizer/test_utils.rs b/datafusion/core/src/physical_optimizer/test_utils.rsindex e021cda2c8..0915fdbf1c 100644--- a/datafusion/core/src/physical_optimizer/test_utils.rs+++ b/datafusion/core/src/physical_optimizer/test_utils.rs@@ -140,14 +140,13 @@ impl QueryCase {async fn run_case(&self, ctx: SessionContext, error: Option<&String>) -> Result<()> {let dataframe = ctx.sql(self.sql.as_str()).await?;let plan = dataframe.create_physical_plan().await;- if error.is_some() {+ if let Some(error) = error {let plan_error = plan.unwrap_err();- let initial = error.unwrap().to_string();assert!(- plan_error.to_string().contains(initial.as_str()),+ plan_error.to_string().contains(error.as_str()),"plan_error: {:?} doesn't contain message: {:?}",plan_error,- initial.as_str()+ error.as_str());} else {assert!(plan.is_ok())diff --git a/datafusion/core/tests/custom_sources.rs b/datafusion/core/tests/custom_sources.rsindex 771da80aa6..3886ad3c42 100644--- a/datafusion/core/tests/custom_sources.rs+++ b/datafusion/core/tests/custom_sources.rs@@ -49,7 +49,7 @@ mod custom_sources_cases;use async_trait::async_trait;-//// Custom source dataframe tests ////+//--- Custom source dataframe tests ---//struct CustomTableProvider;#[derive(Debug, Clone)]diff --git a/datafusion/execution/src/memory_pool/mod.rs b/datafusion/execution/src/memory_pool/mod.rsindex f8fc9fcdbb..bbd8f4be4f 100644--- a/datafusion/execution/src/memory_pool/mod.rs+++ b/datafusion/execution/src/memory_pool/mod.rs@@ -46,9 +46,9 @@ pub use pool::*;////// The following memory pool implementations are available:///-/// * [`UnboundedMemoryPool`](pool::UnboundedMemoryPool)-/// * [`GreedyMemoryPool`](pool::GreedyMemoryPool)-/// * [`FairSpillPool`](pool::FairSpillPool)+/// * [`UnboundedMemoryPool`]+/// * [`GreedyMemoryPool`]+/// * [`FairSpillPool`]pub trait MemoryPool: Send + Sync + std::fmt::Debug {/// Registers a new [`MemoryConsumer`]///diff --git a/datafusion/execution/src/stream.rs b/datafusion/execution/src/stream.rsindex 5a1a9aaa25..7fc5e458b8 100644--- a/datafusion/execution/src/stream.rs+++ b/datafusion/execution/src/stream.rs@@ -29,5 +29,5 @@ pub trait RecordBatchStream: Stream<Item = Result<RecordBatch>> {fn schema(&self) -> SchemaRef;}-/// Trait for a [`Stream`](futures::stream::Stream) of [`RecordBatch`]es+/// Trait for a [`Stream`] of [`RecordBatch`]espub type SendableRecordBatchStream = Pin<Box<dyn RecordBatchStream + Send>>;diff --git a/datafusion/expr/src/expr.rs b/datafusion/expr/src/expr.rsindex 94ef69eb79..3e4e306897 100644--- a/datafusion/expr/src/expr.rs+++ b/datafusion/expr/src/expr.rs@@ -39,7 +39,7 @@ use std::sync::Arc;/// represent logical expressions such as `A + 1`, or `CAST(c1 AS/// int)`.///-/// An `Expr` can compute its [DataType](arrow::datatypes::DataType)+/// An `Expr` can compute its [DataType]/// and nullability, and has functions for building up complex/// expressions.///diff --git a/datafusion/optimizer/src/push_down_filter.rs b/datafusion/optimizer/src/push_down_filter.rsindex fe726d5d77..ee7b37979d 100644--- a/datafusion/optimizer/src/push_down_filter.rs+++ b/datafusion/optimizer/src/push_down_filter.rs@@ -488,7 +488,7 @@ fn push_down_join(.filter.as_ref().map(|e| utils::split_conjunction_owned(e.clone()))- .unwrap_or_else(Vec::new);+ .unwrap_or_default();let mut is_inner_join = false;let infer_predicates = if join.join_type == JoinType::Inner {diff --git a/datafusion/physical-expr/src/aggregate/mod.rs b/datafusion/physical-expr/src/aggregate/mod.rsindex 4920f7a3e0..442d018b87 100644--- a/datafusion/physical-expr/src/aggregate/mod.rs+++ b/datafusion/physical-expr/src/aggregate/mod.rs@@ -68,7 +68,7 @@ pub(crate) mod variance;/// `PartialEq<dyn Any>` to allows comparing equality between the/// trait objects.pub trait AggregateExpr: Send + Sync + Debug + PartialEq<dyn Any> {- /// Returns the aggregate expression as [`Any`](std::any::Any) so that it can be+ /// Returns the aggregate expression as [`Any`] so that it can be/// downcast to a specific implementation.fn as_any(&self) -> &dyn Any;diff --git a/datafusion/physical-expr/src/aggregate/utils.rs b/datafusion/physical-expr/src/aggregate/utils.rsindex e1af670712..2f473f7608 100644--- a/datafusion/physical-expr/src/aggregate/utils.rs+++ b/datafusion/physical-expr/src/aggregate/utils.rs@@ -161,7 +161,7 @@ pub fn adjust_output_array(}/// Downcast a `Box<dyn AggregateExpr>` or `Arc<dyn AggregateExpr>`-/// and return the inner trait object as [`Any`](std::any::Any) so+/// and return the inner trait object as [`Any`] so/// that it can be downcast to a specific implementation.////// This method is used when implementing the `PartialEq<dyn Any>`diff --git a/datafusion/physical-expr/src/expressions/binary.rs b/datafusion/physical-expr/src/expressions/binary.rsindex f75c2f951f..63fa98011f 100644--- a/datafusion/physical-expr/src/expressions/binary.rs+++ b/datafusion/physical-expr/src/expressions/binary.rs@@ -299,7 +299,7 @@ impl PhysicalExpr for BinaryExpr {};if let Some(result) = scalar_result {- return result.map(|a| ColumnarValue::Array(a));+ return result.map(ColumnarValue::Array);}// if both arrays or both literals - extract arrays and continue execution@@ -308,7 +308,7 @@ impl PhysicalExpr for BinaryExpr {rhs.into_array(batch.num_rows()),);self.evaluate_with_resolved_args(left, &left_data_type, right, &right_data_type)- .map(|a| ColumnarValue::Array(a))+ .map(ColumnarValue::Array)}fn children(&self) -> Vec<Arc<dyn PhysicalExpr>> {diff --git a/datafusion/physical-expr/src/physical_expr.rs b/datafusion/physical-expr/src/physical_expr.rsindex 81702d8bfa..00fc9ed5fa 100644--- a/datafusion/physical-expr/src/physical_expr.rs+++ b/datafusion/physical-expr/src/physical_expr.rs@@ -35,7 +35,7 @@ use std::sync::Arc;/// Expression that can be evaluated against a RecordBatch/// A Physical expression knows its type, nullability and how to evaluate itself.pub trait PhysicalExpr: Send + Sync + Display + Debug + PartialEq<dyn Any> {- /// Returns the physical expression as [`Any`](std::any::Any) so that it can be+ /// Returns the physical expression as [`Any`] so that it can be/// downcast to a specific implementation.fn as_any(&self) -> &dyn Any;/// Get the data type of this expression, given the schema of the inputdiff --git a/datafusion/physical-expr/src/sort_properties.rs b/datafusion/physical-expr/src/sort_properties.rsindex 001b86e60a..097f491cb9 100644--- a/datafusion/physical-expr/src/sort_properties.rs+++ b/datafusion/physical-expr/src/sort_properties.rs@@ -172,7 +172,7 @@ impl ExprOrdering {self.expr.children().into_iter()- .map(|e| ExprOrdering::new(e))+ .map(ExprOrdering::new).collect()}diff --git a/datafusion/physical-expr/src/window/built_in_window_function_expr.rs b/datafusion/physical-expr/src/window/built_in_window_function_expr.rsindex 1a060817d2..66ffa990b7 100644--- a/datafusion/physical-expr/src/window/built_in_window_function_expr.rs+++ b/datafusion/physical-expr/src/window/built_in_window_function_expr.rs@@ -37,7 +37,7 @@ use std::sync::Arc;/// `nth_value` need the value.#[allow(rustdoc::private_intra_doc_links)]pub trait BuiltInWindowFunctionExpr: Send + Sync + std::fmt::Debug {- /// Returns the aggregate expression as [`Any`](std::any::Any) so that it can be+ /// Returns the aggregate expression as [`Any`] so that it can be/// downcast to a specific implementation.fn as_any(&self) -> &dyn Any;diff --git a/datafusion/physical-expr/src/window/window_expr.rs b/datafusion/physical-expr/src/window/window_expr.rsindex da67bcabee..9b0a02d329 100644--- a/datafusion/physical-expr/src/window/window_expr.rs+++ b/datafusion/physical-expr/src/window/window_expr.rs@@ -59,7 +59,7 @@ use std::sync::Arc;/// [`PlainAggregateWindowExpr`]: crate::window::PlainAggregateWindowExpr/// [`SlidingAggregateWindowExpr`]: crate::window::SlidingAggregateWindowExprpub trait WindowExpr: Send + Sync + Debug {- /// Returns the window expression as [`Any`](std::any::Any) so that it can be+ /// Returns the window expression as [`Any`] so that it can be/// downcast to a specific implementation.fn as_any(&self) -> &dyn Any;diff --git a/datafusion/physical-plan/src/aggregates/mod.rs b/datafusion/physical-plan/src/aggregates/mod.rsindex b6e4b0a44d..6ab991c6f5 100644--- a/datafusion/physical-plan/src/aggregates/mod.rs+++ b/datafusion/physical-plan/src/aggregates/mod.rs@@ -681,7 +681,7 @@ impl AggregateExec {for (expression, name) in group_by.expr.iter() {if let Some(column) = expression.as_any().downcast_ref::<Column>() {let new_col_idx = schema.index_of(name)?;- let entry = columns_map.entry(column.clone()).or_insert_with(Vec::new);+ let entry = columns_map.entry(column.clone()).or_default();entry.push(Column::new(name, new_col_idx));};}@@ -1868,7 +1868,7 @@ mod tests {}}- //// Tests ////+ //--- Tests ---//#[tokio::test]async fn aggregate_source_not_yielding() -> Result<()> {diff --git a/datafusion/physical-plan/src/lib.rs b/datafusion/physical-plan/src/lib.rsindex 3071fadcb1..30ac2cb983 100644--- a/datafusion/physical-plan/src/lib.rs+++ b/datafusion/physical-plan/src/lib.rs@@ -62,7 +62,7 @@ pub use stream::EmptyRecordBatchStream;/// return value from [`displayable`] in addition to the (normally/// quite verbose) `Debug` output.pub trait ExecutionPlan: Debug + DisplayAs + Send + Sync {- /// Returns the execution plan as [`Any`](std::any::Any) so that it can be+ /// Returns the execution plan as [`Any`] so that it can be/// downcast to a specific implementation.fn as_any(&self) -> &dyn Any;diff --git a/datafusion/physical-plan/src/memory.rs b/datafusion/physical-plan/src/memory.rsindex 1dcdae56cf..4c83ff1528 100644--- a/datafusion/physical-plan/src/memory.rs+++ b/datafusion/physical-plan/src/memory.rs@@ -81,7 +81,7 @@ impl DisplayAs for MemoryExec {output_ordering.iter().map(|e| e.to_string()).collect();format!(", output_ordering={}", order_strings.join(","))})- .unwrap_or_else(|| "".to_string());+ .unwrap_or_default();write!(f,diff --git a/datafusion/physical-plan/src/projection.rs b/datafusion/physical-plan/src/projection.rsindex 4fc48e971c..f4a2cd339e 100644--- a/datafusion/physical-plan/src/projection.rs+++ b/datafusion/physical-plan/src/projection.rs@@ -111,9 +111,7 @@ impl ProjectionExec {let idx = column.index();let matching_input_field = input_schema.field(idx);let matching_input_column = Column::new(matching_input_field.name(), idx);- let entry = columns_map- .entry(matching_input_column)- .or_insert_with(Vec::new);+ let entry = columns_map.entry(matching_input_column).or_default();entry.push(Column::new(name, expr_idx));};}diff --git a/datafusion/physical-plan/src/visitor.rs b/datafusion/physical-plan/src/visitor.rsindex 573e4f8b02..ca826c5002 100644--- a/datafusion/physical-plan/src/visitor.rs+++ b/datafusion/physical-plan/src/visitor.rs@@ -38,7 +38,7 @@ pub fn accept<V: ExecutionPlanVisitor>(/// depth first walk of `ExecutionPlan` nodes. `pre_visit` is called/// before any children are visited, and then `post_visit` is called/// after all children have been visited.-////+////// To use, define a struct that implements this trait and then invoke/// ['accept'].///diff --git a/datafusion/sql/src/expr/mod.rs b/datafusion/sql/src/expr/mod.rsindex 2f6266f29d..cb34b6ca36 100644--- a/datafusion/sql/src/expr/mod.rs+++ b/datafusion/sql/src/expr/mod.rs@@ -719,7 +719,7 @@ fn rewrite_placeholder(expr: &mut Expr, other: &Expr, schema: &DFSchema) -> Resulet other_dt = other.get_type(schema);match other_dt {Err(e) => {- return Err(e.context(format!(+ Err(e.context(format!("Can not find type of {other} needed to infer type of {expr}")))?;}diff --git a/datafusion/sql/src/parser.rs b/datafusion/sql/src/parser.rsindex 0e3e475089..f52fdec7f7 100644--- a/datafusion/sql/src/parser.rs+++ b/datafusion/sql/src/parser.rs@@ -253,8 +253,7 @@ impl fmt::Display for Statement {/// Datafusion SQL Parser based on [`sqlparser`]///-/// Parses DataFusion's SQL dialect, often delegating to [`sqlparser`]'s-/// [`Parser`](sqlparser::parser::Parser).+/// Parses DataFusion's SQL dialect, often delegating to [`sqlparser`]'s [`Parser`].////// DataFusion mostly follows existing SQL dialects via/// `sqlparser`. However, certain statements such as `COPY` and