From 1ccc74042125fdf8bbb7d0999ff5f750ec6c438c Mon Sep 17 00:00:00 2001 From: Xin Li Date: Sun, 4 Aug 2024 19:46:30 +0800 Subject: [PATCH] revert schema change v2 --- datafusion/functions-aggregate/src/array_agg.rs | 3 +-- datafusion/functions-aggregate/src/average.rs | 3 +-- datafusion/functions-aggregate/src/count.rs | 3 +-- datafusion/physical-plan/src/aggregates/mod.rs | 16 ++++++++-------- datafusion/physical-plan/src/windows/mod.rs | 3 +-- .../proto/tests/cases/roundtrip_physical_plan.rs | 4 +--- 6 files changed, 13 insertions(+), 19 deletions(-) diff --git a/datafusion/functions-aggregate/src/array_agg.rs b/datafusion/functions-aggregate/src/array_agg.rs index 06750754006e..35e7c417ade1 100644 --- a/datafusion/functions-aggregate/src/array_agg.rs +++ b/datafusion/functions-aggregate/src/array_agg.rs @@ -117,8 +117,7 @@ impl AggregateUDFImpl for ArrayAgg { } fn accumulator(&self, acc_args: AccumulatorArgs) -> Result> { - let data_type = - acc_args.input_exprs[0].data_type(acc_args.schema)?; + let data_type = acc_args.input_exprs[0].data_type(acc_args.schema)?; if acc_args.is_distinct { return Ok(Box::new(DistinctArrayAggAccumulator::try_new(&data_type)?)); diff --git a/datafusion/functions-aggregate/src/average.rs b/datafusion/functions-aggregate/src/average.rs index e27acb31a9d4..77a6c4f7457e 100644 --- a/datafusion/functions-aggregate/src/average.rs +++ b/datafusion/functions-aggregate/src/average.rs @@ -93,8 +93,7 @@ impl AggregateUDFImpl for Avg { } use DataType::*; // instantiate specialized accumulator based for the type - let input_type = - acc_args.input_exprs[0].data_type(acc_args.schema)?; + let input_type = acc_args.input_exprs[0].data_type(acc_args.schema)?; match (&input_type, acc_args.data_type) { (Float64, Float64) => Ok(Box::::default()), diff --git a/datafusion/functions-aggregate/src/count.rs b/datafusion/functions-aggregate/src/count.rs index 6b241fde4e8e..51c58b73f181 100644 --- a/datafusion/functions-aggregate/src/count.rs +++ b/datafusion/functions-aggregate/src/count.rs @@ -148,8 +148,7 @@ impl AggregateUDFImpl for Count { return not_impl_err!("COUNT DISTINCT with multiple arguments"); } - let data_type = - &acc_args.input_exprs[0].data_type(acc_args.schema)?; + let data_type = &acc_args.input_exprs[0].data_type(acc_args.schema)?; Ok(match data_type { // try and use a specialized accumulator if possible, otherwise fall back to generic accumulator DataType::Int8 => Box::new( diff --git a/datafusion/physical-plan/src/aggregates/mod.rs b/datafusion/physical-plan/src/aggregates/mod.rs index 9d7f45603464..e54cd5c6ae96 100644 --- a/datafusion/physical-plan/src/aggregates/mod.rs +++ b/datafusion/physical-plan/src/aggregates/mod.rs @@ -1192,7 +1192,7 @@ mod tests { use arrow_array::{Float32Array, Int32Array}; use datafusion_common::{ assert_batches_eq, assert_batches_sorted_eq, internal_err, DFSchema, DFSchemaRef, - DataFusionError, ScalarValue, ToDFSchema, + DataFusionError, ScalarValue, }; use datafusion_execution::config::SessionConfig; use datafusion_execution::memory_pool::FairSpillPool; @@ -1349,7 +1349,7 @@ mod tests { }; let aggregates = vec![AggregateExprBuilder::new(count_udaf(), vec![lit(1i8)]) - .dfschema(Arc::clone(&input_schema).to_dfschema()?) + .schema(Arc::clone(&input_schema)) .name("COUNT(1)") .logical_exprs(vec![datafusion_expr::lit(1i8)]) .build()?]; @@ -1494,7 +1494,7 @@ mod tests { let aggregates: Vec> = vec![ AggregateExprBuilder::new(avg_udaf(), vec![col("b", &input_schema)?]) - .dfschema(Arc::clone(&input_schema).to_dfschema()?) + .schema(Arc::clone(&input_schema)) .name("AVG(b)") .build()?, ]; @@ -1790,7 +1790,7 @@ mod tests { // Median(a) fn test_median_agg_expr(schema: SchemaRef) -> Result> { AggregateExprBuilder::new(median_udaf(), vec![col("a", &schema)?]) - .dfschema(schema.to_dfschema()?) + .schema(Arc::clone(&schema)) .name("MEDIAN(a)") .build() } @@ -1821,7 +1821,7 @@ mod tests { let aggregates_v2: Vec> = vec![ AggregateExprBuilder::new(avg_udaf(), vec![col("b", &input_schema)?]) - .dfschema(Arc::clone(&input_schema).to_dfschema()?) + .schema(Arc::clone(&input_schema)) .name("AVG(b)") .build()?, ]; @@ -1881,7 +1881,7 @@ mod tests { let aggregates: Vec> = vec![ AggregateExprBuilder::new(avg_udaf(), vec![col("a", &schema)?]) - .dfschema(Arc::clone(&schema).to_dfschema()?) + .schema(Arc::clone(&schema)) .name("AVG(a)") .build()?, ]; @@ -1921,7 +1921,7 @@ mod tests { let aggregates: Vec> = vec![ AggregateExprBuilder::new(avg_udaf(), vec![col("b", &schema)?]) - .dfschema(Arc::clone(&schema).to_dfschema()?) + .schema(Arc::clone(&schema)) .name("AVG(b)") .build()?, ]; @@ -2350,7 +2350,7 @@ mod tests { let aggregates: Vec> = vec![AggregateExprBuilder::new(count_udaf(), vec![lit(1)]) - .dfschema(Arc::clone(&schema).to_dfschema()?) + .schema(Arc::clone(&schema)) .name("1") .build()?]; diff --git a/datafusion/physical-plan/src/windows/mod.rs b/datafusion/physical-plan/src/windows/mod.rs index 70e11498c88f..65cef28efc45 100644 --- a/datafusion/physical-plan/src/windows/mod.rs +++ b/datafusion/physical-plan/src/windows/mod.rs @@ -395,7 +395,6 @@ impl BuiltInWindowFunctionExpr for WindowUDFExpr { } } -#[allow(clippy::needless_borrow)] pub(crate) fn calc_requirements< T: Borrow>, S: Borrow, @@ -413,7 +412,7 @@ pub(crate) fn calc_requirements< let PhysicalSortExpr { expr, options } = element.borrow(); if !sort_reqs.iter().any(|e| e.expr.eq(expr)) { sort_reqs.push(PhysicalSortRequirement::new( - Arc::clone(&expr), + Arc::clone(expr), Some(*options), )); } diff --git a/datafusion/proto/tests/cases/roundtrip_physical_plan.rs b/datafusion/proto/tests/cases/roundtrip_physical_plan.rs index 213a5590b742..0e2bc9cbb3e2 100644 --- a/datafusion/proto/tests/cases/roundtrip_physical_plan.rs +++ b/datafusion/proto/tests/cases/roundtrip_physical_plan.rs @@ -81,9 +81,7 @@ use datafusion_common::file_options::csv_writer::CsvWriterOptions; use datafusion_common::file_options::json_writer::JsonWriterOptions; use datafusion_common::parsers::CompressionTypeVariant; use datafusion_common::stats::Precision; -use datafusion_common::{ - internal_err, not_impl_err, DataFusionError, Result, -}; +use datafusion_common::{internal_err, not_impl_err, DataFusionError, Result}; use datafusion_expr::{ Accumulator, AccumulatorFactoryFunction, AggregateUDF, ColumnarValue, ScalarUDF, Signature, SimpleAggregateUDF, WindowFrame, WindowFrameBound,