From 73922387391fa783b4a88e664234a5b0cef019ad Mon Sep 17 00:00:00 2001 From: NoeB Date: Sat, 11 May 2024 11:39:15 +0200 Subject: [PATCH 1/2] move bit_and_or_xor unit tests to slt Signed-off-by: NoeB --- .../src/aggregate/bit_and_or_xor.rs | 127 ------------ .../sqllogictest/test_files/aggregate.slt | 195 ++++++++++++++++++ 2 files changed, 195 insertions(+), 127 deletions(-) diff --git a/datafusion/physical-expr/src/aggregate/bit_and_or_xor.rs b/datafusion/physical-expr/src/aggregate/bit_and_or_xor.rs index 7244686a5195f..3fa225c5e4791 100644 --- a/datafusion/physical-expr/src/aggregate/bit_and_or_xor.rs +++ b/datafusion/physical-expr/src/aggregate/bit_and_or_xor.rs @@ -693,130 +693,3 @@ where + self.values.capacity() * std::mem::size_of::() } } - -#[cfg(test)] -mod tests { - use super::*; - use crate::expressions::col; - use crate::expressions::tests::aggregate; - use crate::generic_test_op; - use arrow::array::*; - use arrow::datatypes::*; - - #[test] - fn bit_and_i32() -> Result<()> { - let a: ArrayRef = Arc::new(Int32Array::from(vec![4, 7, 15])); - generic_test_op!(a, DataType::Int32, BitAnd, ScalarValue::from(4i32)) - } - - #[test] - fn bit_and_i32_with_nulls() -> Result<()> { - let a: ArrayRef = - Arc::new(Int32Array::from(vec![Some(1), None, Some(3), Some(5)])); - generic_test_op!(a, DataType::Int32, BitAnd, ScalarValue::from(1i32)) - } - - #[test] - fn bit_and_i32_all_nulls() -> Result<()> { - let a: ArrayRef = Arc::new(Int32Array::from(vec![None, None])); - generic_test_op!(a, DataType::Int32, BitAnd, ScalarValue::Int32(None)) - } - - #[test] - fn bit_and_u32() -> Result<()> { - let a: ArrayRef = Arc::new(UInt32Array::from(vec![4_u32, 7_u32, 15_u32])); - generic_test_op!(a, DataType::UInt32, BitAnd, ScalarValue::from(4u32)) - } - - #[test] - fn bit_or_i32() -> Result<()> { - let a: ArrayRef = Arc::new(Int32Array::from(vec![4, 7, 15])); - generic_test_op!(a, DataType::Int32, BitOr, ScalarValue::from(15i32)) - } - - #[test] - fn bit_or_i32_with_nulls() -> Result<()> { - let a: ArrayRef = - Arc::new(Int32Array::from(vec![Some(1), None, Some(3), Some(5)])); - generic_test_op!(a, DataType::Int32, BitOr, ScalarValue::from(7i32)) - } - - #[test] - fn bit_or_i32_all_nulls() -> Result<()> { - let a: ArrayRef = Arc::new(Int32Array::from(vec![None, None])); - generic_test_op!(a, DataType::Int32, BitOr, ScalarValue::Int32(None)) - } - - #[test] - fn bit_or_u32() -> Result<()> { - let a: ArrayRef = Arc::new(UInt32Array::from(vec![4_u32, 7_u32, 15_u32])); - generic_test_op!(a, DataType::UInt32, BitOr, ScalarValue::from(15u32)) - } - - #[test] - fn bit_xor_i32() -> Result<()> { - let a: ArrayRef = Arc::new(Int32Array::from(vec![4, 7, 4, 7, 15])); - generic_test_op!(a, DataType::Int32, BitXor, ScalarValue::from(15i32)) - } - - #[test] - fn bit_xor_i32_with_nulls() -> Result<()> { - let a: ArrayRef = Arc::new(Int32Array::from(vec![ - Some(1), - Some(1), - None, - Some(3), - Some(5), - ])); - generic_test_op!(a, DataType::Int32, BitXor, ScalarValue::from(6i32)) - } - - #[test] - fn bit_xor_i32_all_nulls() -> Result<()> { - let a: ArrayRef = Arc::new(Int32Array::from(vec![None, None])); - generic_test_op!(a, DataType::Int32, BitXor, ScalarValue::Int32(None)) - } - - #[test] - fn bit_xor_u32() -> Result<()> { - let a: ArrayRef = - Arc::new(UInt32Array::from(vec![4_u32, 7_u32, 4_u32, 7_u32, 15_u32])); - generic_test_op!(a, DataType::UInt32, BitXor, ScalarValue::from(15u32)) - } - - #[test] - fn bit_xor_distinct_i32() -> Result<()> { - let a: ArrayRef = Arc::new(Int32Array::from(vec![4, 7, 4, 7, 15])); - generic_test_op!(a, DataType::Int32, DistinctBitXor, ScalarValue::from(12i32)) - } - - #[test] - fn bit_xor_distinct_i32_with_nulls() -> Result<()> { - let a: ArrayRef = Arc::new(Int32Array::from(vec![ - Some(1), - Some(1), - None, - Some(3), - Some(5), - ])); - generic_test_op!(a, DataType::Int32, DistinctBitXor, ScalarValue::from(7i32)) - } - - #[test] - fn bit_xor_distinct_i32_all_nulls() -> Result<()> { - let a: ArrayRef = Arc::new(Int32Array::from(vec![None, None])); - generic_test_op!(a, DataType::Int32, DistinctBitXor, ScalarValue::Int32(None)) - } - - #[test] - fn bit_xor_distinct_u32() -> Result<()> { - let a: ArrayRef = - Arc::new(UInt32Array::from(vec![4_u32, 7_u32, 4_u32, 7_u32, 15_u32])); - generic_test_op!( - a, - DataType::UInt32, - DistinctBitXor, - ScalarValue::from(12u32) - ) - } -} diff --git a/datafusion/sqllogictest/test_files/aggregate.slt b/datafusion/sqllogictest/test_files/aggregate.slt index 40f78e7f4d24d..dffe72ed39117 100644 --- a/datafusion/sqllogictest/test_files/aggregate.slt +++ b/datafusion/sqllogictest/test_files/aggregate.slt @@ -2285,6 +2285,201 @@ ORDER BY tag 33 11 NULL 33 11 NULL 33 11 NULL B +# bit_and_i32 +statement ok +create table t (c int) as values (4), (7), (15); + +query IT +Select bit_and(c), arrow_typeof(bit_and(c)) from t; +---- +4 Int32 + +statement ok +drop table t; + +# bit_and_i32_with_nulls +statement ok +create table t (c int) as values (1), (NULL), (3), (5); + +query IT +Select bit_and(c), arrow_typeof(bit_and(c)) from t; +---- +1 Int32 + +statement ok +drop table t; + +# bit_and_i32_all_nulls +statement ok +create table t (c int) as values (NULL), (NULL); + +query IT +Select bit_and(c), arrow_typeof(bit_and(c)) from t; +---- +NULL Int32 + +statement ok +drop table t; + +# bit_and_u32 +statement ok +create table t (c int unsigned) as values (4), (7), (15); + +query IT +Select bit_and(c), arrow_typeof(bit_and(c)) from t; +---- +4 UInt32 + +statement ok +drop table t; + +# bit_or_i32 +statement ok +create table t (c int) as values (4), (7), (15); + +query IT +Select bit_or(c), arrow_typeof(bit_or(c)) from t; +---- +15 Int32 + +statement ok +drop table t; + +# bit_or_i32_with_nulls +statement ok +create table t (c int) as values (1), (NULL), (3), (5); + +query IT +Select bit_or(c), arrow_typeof(bit_or(c)) from t; +---- +7 Int32 + +statement ok +drop table t; + +#bit_or_i32_all_nulls +statement ok +create table t (c int) as values (NULL), (NULL); + +query IT +Select bit_or(c), arrow_typeof(bit_or(c)) from t; +---- +NULL Int32 + +statement ok +drop table t; + + +#bit_or_u32 +statement ok +create table t (c int unsigned) as values (4), (7), (15); + +query IT +Select bit_or(c), arrow_typeof(bit_or(c)) from t; +---- +15 UInt32 + +statement ok +drop table t; + +#bit_xor_i32 +statement ok +create table t (c int) as values (4), (7), (4), (7), (15); + +query IT +Select bit_xor(c), arrow_typeof(bit_xor(c)) from t; +---- +15 Int32 + +statement ok +drop table t; + +# bit_xor_i32_with_nulls +statement ok +create table t (c int) as values (1), (1), (NULL), (3), (5); + +query IT +Select bit_xor(c), arrow_typeof(bit_xor(c)) from t; +---- +6 Int32 + +statement ok +drop table t; + +# bit_xor_i32_all_nulls +statement ok +create table t (c int) as values (NULL), (NULL); + +query IT +Select bit_xor(c), arrow_typeof(bit_xor(c)) from t; +---- +NULL Int32 + +statement ok +drop table t; + +# bit_xor_u32 +statement ok +create table t (c int unsigned) as values (4), (7), (4), (7), (15); + +query IT +Select bit_xor(c), arrow_typeof(bit_xor(c)) from t; +---- +15 UInt32 + +statement ok +drop table t; + +# bit_xor_distinct_i32 +statement ok +create table t (c int) as values (4), (7), (4), (7), (15); + +query IT +Select bit_xor(DISTINCT c), arrow_typeof(bit_xor(c)) from t; +---- +12 Int32 + +statement ok +drop table t; + +# bit_xor_distinct_i32_with_nulls +statement ok +create table t (c int) as values (1), (1), (NULL), (3), (5); + +query IT +Select bit_xor(DISTINCT c), arrow_typeof(bit_xor(c)) from t; +---- +7 Int32 + + +statement ok +drop table t; + +# bit_xor_distinct_i32_all_nulls +statement ok +create table t (c int ) as values (NULL), (NULL); + +query IT +Select bit_xor(DISTINCT c), arrow_typeof(bit_xor(c)) from t; +---- +NULL Int32 + + +statement ok +drop table t; + +# bit_xor_distinct_u32 +statement ok +create table t (c int unsigned) as values (4), (7), (4), (7), (15); + +query IT +Select bit_xor(DISTINCT c), arrow_typeof(bit_xor(c)) from t; +---- +12 UInt32 + +statement ok +drop table t; + statement ok create table bool_aggregate_functions ( c1 boolean not null, From 15988c285c6857ae5dc7df354d6255174d16d948 Mon Sep 17 00:00:00 2001 From: NoeB Date: Sat, 11 May 2024 12:49:16 +0200 Subject: [PATCH 2/2] Apply suggestions from code review --- datafusion/sqllogictest/test_files/aggregate.slt | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/datafusion/sqllogictest/test_files/aggregate.slt b/datafusion/sqllogictest/test_files/aggregate.slt index dffe72ed39117..1e0d522492e79 100644 --- a/datafusion/sqllogictest/test_files/aggregate.slt +++ b/datafusion/sqllogictest/test_files/aggregate.slt @@ -2435,7 +2435,7 @@ statement ok create table t (c int) as values (4), (7), (4), (7), (15); query IT -Select bit_xor(DISTINCT c), arrow_typeof(bit_xor(c)) from t; +Select bit_xor(DISTINCT c), arrow_typeof(bit_xor(DISTINCT c)) from t; ---- 12 Int32 @@ -2447,7 +2447,7 @@ statement ok create table t (c int) as values (1), (1), (NULL), (3), (5); query IT -Select bit_xor(DISTINCT c), arrow_typeof(bit_xor(c)) from t; +Select bit_xor(DISTINCT c), arrow_typeof(bit_xor(DISTINCT c)) from t; ---- 7 Int32 @@ -2460,7 +2460,7 @@ statement ok create table t (c int ) as values (NULL), (NULL); query IT -Select bit_xor(DISTINCT c), arrow_typeof(bit_xor(c)) from t; +Select bit_xor(DISTINCT c), arrow_typeof(bit_xor(DISTINCT c)) from t; ---- NULL Int32 @@ -2473,7 +2473,7 @@ statement ok create table t (c int unsigned) as values (4), (7), (4), (7), (15); query IT -Select bit_xor(DISTINCT c), arrow_typeof(bit_xor(c)) from t; +Select bit_xor(DISTINCT c), arrow_typeof(bit_xor(DISTINCT c)) from t; ---- 12 UInt32