Apache DataFusion SQL Query Engine
AggregateStatistics min/max/count take_optimizable replace col_expr name with casted_expr name (#5485)
zhenxing jiangecbc843a1a8c
diff --git a/datafusion/core/src/physical_optimizer/aggregate_statistics.rs b/datafusion/core/src/physical_optimizer/aggregate_statistics.rsindex 3014f5c542..59806a0a2f 100644--- a/datafusion/core/src/physical_optimizer/aggregate_statistics.rs+++ b/datafusion/core/src/physical_optimizer/aggregate_statistics.rs@@ -189,10 +189,9 @@ fn take_optimizable_column_count(..} = &col_stats[col_expr.index()]{- let expr = format!("COUNT({})", col_expr.name());return Some((ScalarValue::Int64(Some((num_rows - val) as i64)),- expr,+ casted_expr.name().to_string(),));}}@@ -221,7 +220,7 @@ fn take_optimizable_min(..} = &col_stats[col_expr.index()]{- return Some((val.clone(), format!("MIN({})", col_expr.name())));+ return Some((val.clone(), casted_expr.name().to_string()));}}}@@ -249,7 +248,7 @@ fn take_optimizable_max(..} = &col_stats[col_expr.index()]{- return Some((val.clone(), format!("MAX({})", col_expr.name())));+ return Some((val.clone(), casted_expr.name().to_string()));}}}diff --git a/datafusion/core/tests/custom_sources.rs b/datafusion/core/tests/custom_sources.rsindex e78351500c..57314f2e1e 100644--- a/datafusion/core/tests/custom_sources.rs+++ b/datafusion/core/tests/custom_sources.rs@@ -264,8 +264,8 @@ async fn optimizers_catch_all_statistics() {let expected = RecordBatch::try_new(Arc::new(Schema::new(vec![Field::new("COUNT(UInt8(1))", DataType::Int64, false),- Field::new("MIN(c1)", DataType::Int32, false),- Field::new("MAX(c1)", DataType::Int32, false),+ Field::new("MIN(test.c1)", DataType::Int32, false),+ Field::new("MAX(test.c1)", DataType::Int32, false),])),vec![Arc::new(Int64Array::from_slice([4])),diff --git a/datafusion/core/tests/sql/aggregates.rs b/datafusion/core/tests/sql/aggregates.rsindex 972c8a94a2..3eaa2fd5d1 100644--- a/datafusion/core/tests/sql/aggregates.rs+++ b/datafusion/core/tests/sql/aggregates.rs@@ -99,11 +99,11 @@ async fn aggregate_timestamps_count() -> Result<()> {.await;let expected = vec![- "+--------------+---------------+---------------+-------------+",- "| COUNT(nanos) | COUNT(micros) | COUNT(millis) | COUNT(secs) |",- "+--------------+---------------+---------------+-------------+",- "| 3 | 3 | 3 | 3 |",- "+--------------+---------------+---------------+-------------+",+ "+----------------+-----------------+-----------------+---------------+",+ "| COUNT(t.nanos) | COUNT(t.micros) | COUNT(t.millis) | COUNT(t.secs) |",+ "+----------------+-----------------+-----------------+---------------+",+ "| 3 | 3 | 3 | 3 |",+ "+----------------+-----------------+-----------------+---------------+",];assert_batches_sorted_eq!(expected, &results);@@ -185,11 +185,11 @@ async fn aggregate_times_count() -> Result<()> {.await;let expected = vec![- "+--------------+---------------+---------------+-------------+",- "| COUNT(nanos) | COUNT(micros) | COUNT(millis) | COUNT(secs) |",- "+--------------+---------------+---------------+-------------+",- "| 4 | 4 | 4 | 4 |",- "+--------------+---------------+---------------+-------------+",+ "+----------------+-----------------+-----------------+---------------+",+ "| COUNT(t.nanos) | COUNT(t.micros) | COUNT(t.millis) | COUNT(t.secs) |",+ "+----------------+-----------------+-----------------+---------------+",+ "| 4 | 4 | 4 | 4 |",+ "+----------------+-----------------+-----------------+---------------+",];assert_batches_sorted_eq!(expected, &results);diff --git a/datafusion/core/tests/sql/parquet.rs b/datafusion/core/tests/sql/parquet.rsindex b185289927..725324d2df 100644--- a/datafusion/core/tests/sql/parquet.rs+++ b/datafusion/core/tests/sql/parquet.rs@@ -342,11 +342,11 @@ async fn parquet_query_with_max_min() {let sql = "SELECT max(c1) FROM foo";let actual = execute_to_batches(&ctx, sql).await;let expected = vec![- "+---------+",- "| MAX(c1) |",- "+---------+",- "| 3 |",- "+---------+",+ "+-------------+",+ "| MAX(foo.c1) |",+ "+-------------+",+ "| 3 |",+ "+-------------+",];assert_batches_eq!(expected, &actual);@@ -366,11 +366,11 @@ async fn parquet_query_with_max_min() {let sql = "SELECT max(c3) FROM foo";let actual = execute_to_batches(&ctx, sql).await;let expected = vec![- "+---------+",- "| MAX(c3) |",- "+---------+",- "| 300 |",- "+---------+",+ "+-------------+",+ "| MAX(foo.c3) |",+ "+-------------+",+ "| 300 |",+ "+-------------+",];assert_batches_eq!(expected, &actual);diff --git a/datafusion/core/tests/sql/select.rs b/datafusion/core/tests/sql/select.rsindex 9a746f6569..00cc06bb44 100644--- a/datafusion/core/tests/sql/select.rs+++ b/datafusion/core/tests/sql/select.rs@@ -763,11 +763,11 @@ async fn query_on_string_dictionary() -> Result<()> {let sql = "SELECT COUNT(d1) FROM test";let actual = execute_to_batches(&ctx, sql).await;let expected = vec![- "+-----------+",- "| COUNT(d1) |",- "+-----------+",- "| 2 |",- "+-----------+",+ "+----------------+",+ "| COUNT(test.d1) |",+ "+----------------+",+ "| 2 |",+ "+----------------+",];assert_batches_eq!(expected, &actual);