Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
127 changes: 0 additions & 127 deletions datafusion/physical-expr/src/aggregate/bit_and_or_xor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -693,130 +693,3 @@ where
+ self.values.capacity() * std::mem::size_of::<T::Native>()
}
}

#[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)
)
}
}
195 changes: 195 additions & 0 deletions datafusion/sqllogictest/test_files/aggregate.slt
Original file line number Diff line number Diff line change
Expand Up @@ -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(DISTINCT 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(DISTINCT 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(DISTINCT 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(DISTINCT c)) from t;
----
12 UInt32

statement ok
drop table t;

statement ok
create table bool_aggregate_functions (
c1 boolean not null,
Expand Down