Apache DataFusion SQL Query Engine
move count test to slt (#10383)
Jay Zhandac2a7edc9ee
diff --git a/datafusion/physical-expr/src/aggregate/count.rs b/datafusion/physical-expr/src/aggregate/count.rsindex 567a5589cb..e3660221e6 100644--- a/datafusion/physical-expr/src/aggregate/count.rs+++ b/datafusion/physical-expr/src/aggregate/count.rs@@ -331,123 +331,3 @@ impl Accumulator for CountAccumulator {std::mem::size_of_val(self)}}--#[cfg(test)]-mod tests {- use super::*;- use crate::expressions::tests::aggregate;- use crate::expressions::{col, lit};- use crate::generic_test_op;- use arrow::{array::*, datatypes::*};-- #[test]- fn count_elements() -> Result<()> {- let a: ArrayRef = Arc::new(Int32Array::from(vec![1, 2, 3, 4, 5]));- generic_test_op!(a, DataType::Int32, Count, ScalarValue::from(5i64))- }-- #[test]- fn count_with_nulls() -> Result<()> {- let a: ArrayRef = Arc::new(Int32Array::from(vec![- Some(1),- Some(2),- None,- None,- Some(3),- None,- ]));- generic_test_op!(a, DataType::Int32, Count, ScalarValue::from(3i64))- }-- #[test]- fn count_all_nulls() -> Result<()> {- let a: ArrayRef = Arc::new(BooleanArray::from(vec![- None, None, None, None, None, None, None, None,- ]));- generic_test_op!(a, DataType::Boolean, Count, ScalarValue::from(0i64))- }-- #[test]- fn count_empty() -> Result<()> {- let a: Vec<bool> = vec![];- let a: ArrayRef = Arc::new(BooleanArray::from(a));- generic_test_op!(a, DataType::Boolean, Count, ScalarValue::from(0i64))- }-- #[test]- fn count_utf8() -> Result<()> {- let a: ArrayRef =- Arc::new(StringArray::from(vec!["a", "bb", "ccc", "dddd", "ad"]));- generic_test_op!(a, DataType::Utf8, Count, ScalarValue::from(5i64))- }-- #[test]- fn count_large_utf8() -> Result<()> {- let a: ArrayRef =- Arc::new(LargeStringArray::from(vec!["a", "bb", "ccc", "dddd", "ad"]));- generic_test_op!(a, DataType::LargeUtf8, Count, ScalarValue::from(5i64))- }-- #[test]- fn count_multi_cols() -> Result<()> {- let a: ArrayRef = Arc::new(Int32Array::from(vec![- Some(1),- Some(2),- None,- None,- Some(3),- None,- ]));- let b: ArrayRef = Arc::new(Int32Array::from(vec![- Some(1),- None,- Some(2),- None,- Some(3),- Some(4),- ]));- let schema = Schema::new(vec![- Field::new("a", DataType::Int32, true),- Field::new("b", DataType::Int32, true),- ]);-- let batch = RecordBatch::try_new(Arc::new(schema.clone()), vec![a, b])?;-- let agg = Arc::new(Count::new_with_multiple_exprs(- vec![col("a", &schema)?, col("b", &schema)?],- "bla".to_string(),- DataType::Int64,- ));- let actual = aggregate(&batch, agg)?;- let expected = ScalarValue::from(2i64);-- assert_eq!(expected, actual);- Ok(())- }-- #[test]- fn count_eq() -> Result<()> {- let count = Count::new(lit(1i8), "COUNT(1)".to_string(), DataType::Int64);- let arc_count: Arc<dyn AggregateExpr> = Arc::new(Count::new(- lit(1i8),- "COUNT(1)".to_string(),- DataType::Int64,- ));- let box_count: Box<dyn AggregateExpr> = Box::new(Count::new(- lit(1i8),- "COUNT(1)".to_string(),- DataType::Int64,- ));- let count2 = Count::new(lit(1i8), "COUNT(2)".to_string(), DataType::Int64);-- assert!(arc_count.eq(&box_count));- assert!(box_count.eq(&arc_count));- assert!(arc_count.eq(&count));- assert!(count.eq(&box_count));- assert!(count.eq(&arc_count));-- assert!(count2.ne(&arc_count));-- Ok(())- }-}diff --git a/datafusion/sqllogictest/test_files/aggregate.slt b/datafusion/sqllogictest/test_files/aggregate.sltindex 933bbb4b63..50c9c5eb95 100644--- a/datafusion/sqllogictest/test_files/aggregate.slt+++ b/datafusion/sqllogictest/test_files/aggregate.slt@@ -1562,6 +1562,91 @@ SELECT max(c1) FROM test;# count_basic+statement ok+create table t (c int) as values (1), (2), (null), (3), (null), (4), (5);++query IT+select count(c), arrow_typeof(count(c)) from t;+----+5 Int64++statement ok+drop table t;++# test count with all nulls+statement ok+create table t (c int) as values (null), (null), (null), (null), (null);++query IT+select count(c), arrow_typeof(count(c)) from t;+----+0 Int64++statement ok+drop table t;++# test with empty+statement ok+create table t (c int);++query IT+select count(c), arrow_typeof(count(c)) from t;+----+0 Int64++statement ok+drop table t;++# test count with string+statement ok+create table t (c string) as values ('a'), ('b'), (null), ('c'), (null), ('d'), ('e');++query IT+select count(c), arrow_typeof(count(c)) from t;+----+5 Int64++statement ok+drop table t;++# test count with largeutf8+statement ok+create table t (c string) as values+ (arrow_cast('a', 'LargeUtf8')),+ (arrow_cast('b', 'LargeUtf8')),+ (arrow_cast(null, 'LargeUtf8')),+ (arrow_cast('c', 'LargeUtf8'))+;++query T+select arrow_typeof(c) from t;+----+Utf8+Utf8+Utf8+Utf8++query IT+select count(c), arrow_typeof(count(c)) from t;+----+3 Int64++statement ok+drop table t;++# test count with multiple columns+statement ok+create table t (c1 int, c2 int) as values (1, 1), (2, null), (null, 2), (null, null), (3, 3), (null, 4);++query IT+select count(c1, c2), arrow_typeof(count(c1, c2)) from t;+----+2 Int64++statement ok+drop table t;++query IISELECT COUNT(c1), COUNT(c2) FROM test----