You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@arrow.apache.org by al...@apache.org on 2023/03/11 18:20:45 UTC

[arrow-datafusion] branch main updated: AggregateStatistics min/max/count take_optimizable replace col_expr name with casted_expr name (#5485)

This is an automated email from the ASF dual-hosted git repository.

alamb pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/arrow-datafusion.git


The following commit(s) were added to refs/heads/main by this push:
     new ecbc843a1 AggregateStatistics min/max/count take_optimizable replace col_expr name with casted_expr name (#5485)
ecbc843a1 is described below

commit ecbc843a1a8c38b2466748bc92a6e22ce08d51ed
Author: zhenxing jiang <ji...@gmail.com>
AuthorDate: Sun Mar 12 02:20:39 2023 +0800

    AggregateStatistics min/max/count take_optimizable replace col_expr name with casted_expr name (#5485)
---
 .../src/physical_optimizer/aggregate_statistics.rs   |  7 +++----
 datafusion/core/tests/custom_sources.rs              |  4 ++--
 datafusion/core/tests/sql/aggregates.rs              | 20 ++++++++++----------
 datafusion/core/tests/sql/parquet.rs                 | 20 ++++++++++----------
 datafusion/core/tests/sql/select.rs                  | 10 +++++-----
 5 files changed, 30 insertions(+), 31 deletions(-)

diff --git a/datafusion/core/src/physical_optimizer/aggregate_statistics.rs b/datafusion/core/src/physical_optimizer/aggregate_statistics.rs
index 3014f5c54..59806a0a2 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.rs
index e78351500..57314f2e1 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.rs
index 972c8a94a..3eaa2fd5d 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.rs
index b18528992..725324d2d 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.rs
index 9a746f656..00cc06bb4 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);