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 971951bec Minor: port some decimal tests to sqllogictests (#5739)
971951bec is described below

commit 971951becfe323d4e07f6e9847e1bf825a4d9da7
Author: Andrew Lamb <[email protected]>
AuthorDate: Tue Mar 28 14:50:29 2023 +0200

    Minor: port some decimal tests to sqllogictests (#5739)
    
    * Minor: port some decimal tests to sqllogictests
    
    * more cleanup
---
 datafusion/core/tests/sql/aggregates.rs            | 46 ----------------------
 datafusion/core/tests/sql/mod.rs                   | 24 -----------
 .../tests/sqllogictests/test_files/aggregate.slt   | 26 +++++++++---
 3 files changed, 20 insertions(+), 76 deletions(-)

diff --git a/datafusion/core/tests/sql/aggregates.rs 
b/datafusion/core/tests/sql/aggregates.rs
index 48dd53830..e7324eed0 100644
--- a/datafusion/core/tests/sql/aggregates.rs
+++ b/datafusion/core/tests/sql/aggregates.rs
@@ -70,52 +70,6 @@ async fn csv_query_array_agg_distinct() -> Result<()> {
     Ok(())
 }
 
-#[tokio::test]
-async fn aggregate_decimal_sum() -> Result<()> {
-    let ctx = SessionContext::new();
-    // the data type of c1 is decimal(10,3)
-    ctx.register_table("d_table", table_with_decimal()).unwrap();
-    let result = plan_and_collect(&ctx, "select sum(c1) from d_table")
-        .await
-        .unwrap();
-    let expected = vec![
-        "+-----------------+",
-        "| SUM(d_table.c1) |",
-        "+-----------------+",
-        "| 100.000         |",
-        "+-----------------+",
-    ];
-    assert_eq!(
-        &DataType::Decimal128(20, 3),
-        result[0].schema().field(0).data_type()
-    );
-    assert_batches_sorted_eq!(expected, &result);
-    Ok(())
-}
-
-#[tokio::test]
-async fn aggregate_decimal_avg() -> Result<()> {
-    let ctx = SessionContext::new();
-    // the data type of c1 is decimal(10,3)
-    ctx.register_table("d_table", table_with_decimal()).unwrap();
-    let result = plan_and_collect(&ctx, "select avg(c1) from d_table")
-        .await
-        .unwrap();
-    let expected = vec![
-        "+-----------------+",
-        "| AVG(d_table.c1) |",
-        "+-----------------+",
-        "| 5.0000000       |",
-        "+-----------------+",
-    ];
-    assert_eq!(
-        &DataType::Decimal128(14, 7),
-        result[0].schema().field(0).data_type()
-    );
-    assert_batches_sorted_eq!(expected, &result);
-    Ok(())
-}
-
 #[tokio::test]
 async fn aggregate() -> Result<()> {
     let results = execute_with_partition("SELECT SUM(c1), SUM(c2) FROM test", 
4).await?;
diff --git a/datafusion/core/tests/sql/mod.rs b/datafusion/core/tests/sql/mod.rs
index 65cbcdfe0..64c2d07d3 100644
--- a/datafusion/core/tests/sql/mod.rs
+++ b/datafusion/core/tests/sql/mod.rs
@@ -1238,30 +1238,6 @@ fn populate_csv_partitions(
     Ok(schema)
 }
 
-/// Return a new table which provide this decimal column
-pub fn table_with_decimal() -> Arc<dyn TableProvider> {
-    let batch_decimal = make_decimal();
-    let schema = batch_decimal.schema();
-    let partitions = vec![vec![batch_decimal]];
-    Arc::new(MemTable::try_new(schema, partitions).unwrap())
-}
-
-fn make_decimal() -> RecordBatch {
-    let mut decimal_builder = Decimal128Builder::with_capacity(20);
-    for i in 110000..110010 {
-        decimal_builder.append_value(i as i128);
-    }
-    for i in 100000..100010 {
-        decimal_builder.append_value(-i as i128);
-    }
-    let array = decimal_builder
-        .finish()
-        .with_precision_and_scale(10, 3)
-        .unwrap();
-    let schema = Schema::new(vec![Field::new("c1", array.data_type().clone(), 
true)]);
-    RecordBatch::try_new(Arc::new(schema), vec![Arc::new(array)]).unwrap()
-}
-
 /// Return a RecordBatch with a single Int32 array with values (0..sz)
 pub fn make_partition(sz: i32) -> RecordBatch {
     let seq_start = 0;
diff --git a/datafusion/core/tests/sqllogictests/test_files/aggregate.slt 
b/datafusion/core/tests/sqllogictests/test_files/aggregate.slt
index 51e61ec4c..37a3f016c 100644
--- a/datafusion/core/tests/sqllogictests/test_files/aggregate.slt
+++ b/datafusion/core/tests/sqllogictests/test_files/aggregate.slt
@@ -758,9 +758,9 @@ NULL NULL NULL 3833.525
 
 # csv_query_groupingsets_avg
 query TIIR
-SELECT c1, c2, c3, AVG(c4) 
-FROM aggregate_test_100_by_sql 
-WHERE c1 IN ('a', 'b', NULL) 
+SELECT c1, c2, c3, AVG(c4)
+FROM aggregate_test_100_by_sql
+WHERE c1 IN ('a', 'b', NULL)
 GROUP BY GROUPING SETS ((c1), (c1,c2), (c1,c2,c3))
 ORDER BY c1, c2, c3
 ----
@@ -818,9 +818,9 @@ b NULL NULL 7732.315789473684
 
 # csv_query_singlecol_with_rollup_avg
 query TIIR
-SELECT c1, c2, c3, AVG(c4) 
-FROM aggregate_test_100_by_sql 
-WHERE c1 IN ('a', 'b', NULL) 
+SELECT c1, c2, c3, AVG(c4)
+FROM aggregate_test_100_by_sql
+WHERE c1 IN ('a', 'b', NULL)
 GROUP BY c1, ROLLUP (c2, c3)
 ORDER BY c1, c2, c3
 ----
@@ -1524,3 +1524,17 @@ NULL
 
 query error DataFusion error: Execution error: aggregate function needs at 
least one non-null element
 select approx_median(a) from (select 1 as a where 1=0);
+
+
+# aggregate_decimal_sum
+query RT
+select sum(c1), arrow_typeof(sum(c1)) from d_table;
+----
+100 Decimal128(20, 3)
+
+
+# aggregate_decimal_avg
+query RT
+select avg(c1), arrow_typeof(avg(c1)) from d_table
+----
+5 Decimal128(14, 7)

Reply via email to