Apache DataFusion SQL Query Engine
Minor: port some decimal tests to sqllogictests (#5739)
Andrew Lamb971951becfe3
diff --git a/datafusion/core/tests/sql/aggregates.rs b/datafusion/core/tests/sql/aggregates.rsindex 48dd53830a..e7324eed01 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.rsindex 65cbcdfe06..64c2d07d3f 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.sltindex 51e61ec4c3..37a3f016cf 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_avgquery 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_avgquery 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 @@ NULLquery error DataFusion error: Execution error: aggregate function needs at least one non-null elementselect 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)