From c1e53bc3f507237e5483cf53c2aa2da4d784d67e Mon Sep 17 00:00:00 2001 From: Mustafa Akur Date: Fri, 6 Oct 2023 10:19:42 +0300 Subject: [PATCH] Resolve linter errors --- datafusion/core/benches/topk_aggregate.rs | 7 +++++-- datafusion/core/src/catalog/mod.rs | 4 ++-- datafusion/core/src/datasource/default_table_source.rs | 2 +- datafusion/core/src/datasource/file_format/parquet.rs | 2 +- .../core/src/physical_optimizer/enforce_distribution.rs | 2 +- datafusion/core/src/physical_optimizer/enforce_sorting.rs | 6 +++--- datafusion/core/src/physical_optimizer/pipeline_checker.rs | 2 +- .../replace_with_order_preserving_variants.rs | 2 +- datafusion/core/src/physical_optimizer/test_utils.rs | 7 +++---- datafusion/core/tests/custom_sources.rs | 2 +- datafusion/execution/src/memory_pool/mod.rs | 6 +++--- datafusion/execution/src/stream.rs | 2 +- datafusion/expr/src/expr.rs | 2 +- datafusion/optimizer/src/push_down_filter.rs | 2 +- datafusion/physical-expr/src/aggregate/mod.rs | 2 +- datafusion/physical-expr/src/aggregate/utils.rs | 2 +- datafusion/physical-expr/src/expressions/binary.rs | 4 ++-- datafusion/physical-expr/src/physical_expr.rs | 2 +- datafusion/physical-expr/src/sort_properties.rs | 2 +- .../src/window/built_in_window_function_expr.rs | 2 +- datafusion/physical-expr/src/window/window_expr.rs | 2 +- datafusion/physical-plan/src/aggregates/mod.rs | 4 ++-- datafusion/physical-plan/src/lib.rs | 2 +- datafusion/physical-plan/src/memory.rs | 2 +- datafusion/physical-plan/src/projection.rs | 4 +--- datafusion/physical-plan/src/visitor.rs | 2 +- datafusion/sql/src/expr/mod.rs | 2 +- datafusion/sql/src/parser.rs | 3 +-- 28 files changed, 41 insertions(+), 42 deletions(-) diff --git a/datafusion/core/benches/topk_aggregate.rs b/datafusion/core/benches/topk_aggregate.rs index eaafea248894..ef84d6e3cac8 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::() + .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.rs index 6751edbd3a84..fe5bdc0ec6a9 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 catalogs pub 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.rs index 58d0997bb653..f93faa50a9b9 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 { self diff --git a/datafusion/core/src/datasource/file_format/parquet.rs b/datafusion/core/src/datasource/file_format/parquet.rs index 16050d66db5d..8ddddab71fd5 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 time fn write_in_chunks( writer: &mut ArrowWriter, batch: &RecordBatch, diff --git a/datafusion/core/src/physical_optimizer/enforce_distribution.rs b/datafusion/core/src/physical_optimizer/enforce_distribution.rs index 3463f3a31376..a1f509d28733 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.rs index 6e3b160c8922..95ec1973d017 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.rs index 44679647b5b2..3b994d5f893f 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::>>()?; let children_unbounded = new_children diff --git a/datafusion/core/src/physical_optimizer/replace_with_order_preserving_variants.rs b/datafusion/core/src/physical_optimizer/replace_with_order_preserving_variants.rs index cb3b6c3d0741..ede95fc67721 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.rs index e021cda2c868..0915fdbf1cd7 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.rs index 771da80aa6e7..3886ad3c42c0 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.rs index f8fc9fcdbbbb..bbd8f4be4f1c 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.rs index 5a1a9aaa2590..7fc5e458b86b 100644 --- a/datafusion/execution/src/stream.rs +++ b/datafusion/execution/src/stream.rs @@ -29,5 +29,5 @@ pub trait RecordBatchStream: Stream> { fn schema(&self) -> SchemaRef; } -/// Trait for a [`Stream`](futures::stream::Stream) of [`RecordBatch`]es +/// Trait for a [`Stream`] of [`RecordBatch`]es pub type SendableRecordBatchStream = Pin>; diff --git a/datafusion/expr/src/expr.rs b/datafusion/expr/src/expr.rs index 94ef69eb7933..3e4e3068977c 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.rs index fe726d5d7783..ee7b37979dc4 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.rs index 4920f7a3e07f..442d018b87d5 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` to allows comparing equality between the /// trait objects. pub trait AggregateExpr: Send + Sync + Debug + PartialEq { - /// 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.rs index e1af67071260..2f473f7608b0 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` or `Arc` -/// 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` diff --git a/datafusion/physical-expr/src/expressions/binary.rs b/datafusion/physical-expr/src/expressions/binary.rs index f75c2f951f56..63fa98011fdd 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> { diff --git a/datafusion/physical-expr/src/physical_expr.rs b/datafusion/physical-expr/src/physical_expr.rs index 81702d8bfae0..00fc9ed5fa98 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 { - /// 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 input diff --git a/datafusion/physical-expr/src/sort_properties.rs b/datafusion/physical-expr/src/sort_properties.rs index 001b86e60a86..097f491cb979 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.rs index 1a060817d2e1..66ffa990b78b 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.rs index da67bcabee0b..9b0a02d329c4 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::SlidingAggregateWindowExpr pub 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.rs index b6e4b0a44dec..6ab991c6f596 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::() { 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.rs index 3071fadcb1a2..30ac2cb98366 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.rs index 1dcdae56cfa3..4c83ff1528fa 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.rs index 4fc48e971ca9..f4a2cd339ee5 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.rs index 573e4f8b02be..ca826c50022d 100644 --- a/datafusion/physical-plan/src/visitor.rs +++ b/datafusion/physical-plan/src/visitor.rs @@ -38,7 +38,7 @@ pub fn accept( /// 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.rs index 2f6266f29d6a..cb34b6ca36e8 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) -> Resu let 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.rs index 0e3e47508904..f52fdec7f704 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