Skip to content

Commit c2095e4

Browse files
authored
Move bit_and_or_xor unit tests to slt (#10457)
* move bit_and_or_xor unit tests to slt Signed-off-by: NoeB <[email protected]> * Apply suggestions from code review --------- Signed-off-by: NoeB <[email protected]>
1 parent d8bcff5 commit c2095e4

File tree

2 files changed

+195
-127
lines changed

2 files changed

+195
-127
lines changed

datafusion/physical-expr/src/aggregate/bit_and_or_xor.rs

Lines changed: 0 additions & 127 deletions
Original file line numberDiff line numberDiff line change
@@ -693,130 +693,3 @@ where
693693
+ self.values.capacity() * std::mem::size_of::<T::Native>()
694694
}
695695
}
696-
697-
#[cfg(test)]
698-
mod tests {
699-
use super::*;
700-
use crate::expressions::col;
701-
use crate::expressions::tests::aggregate;
702-
use crate::generic_test_op;
703-
use arrow::array::*;
704-
use arrow::datatypes::*;
705-
706-
#[test]
707-
fn bit_and_i32() -> Result<()> {
708-
let a: ArrayRef = Arc::new(Int32Array::from(vec![4, 7, 15]));
709-
generic_test_op!(a, DataType::Int32, BitAnd, ScalarValue::from(4i32))
710-
}
711-
712-
#[test]
713-
fn bit_and_i32_with_nulls() -> Result<()> {
714-
let a: ArrayRef =
715-
Arc::new(Int32Array::from(vec![Some(1), None, Some(3), Some(5)]));
716-
generic_test_op!(a, DataType::Int32, BitAnd, ScalarValue::from(1i32))
717-
}
718-
719-
#[test]
720-
fn bit_and_i32_all_nulls() -> Result<()> {
721-
let a: ArrayRef = Arc::new(Int32Array::from(vec![None, None]));
722-
generic_test_op!(a, DataType::Int32, BitAnd, ScalarValue::Int32(None))
723-
}
724-
725-
#[test]
726-
fn bit_and_u32() -> Result<()> {
727-
let a: ArrayRef = Arc::new(UInt32Array::from(vec![4_u32, 7_u32, 15_u32]));
728-
generic_test_op!(a, DataType::UInt32, BitAnd, ScalarValue::from(4u32))
729-
}
730-
731-
#[test]
732-
fn bit_or_i32() -> Result<()> {
733-
let a: ArrayRef = Arc::new(Int32Array::from(vec![4, 7, 15]));
734-
generic_test_op!(a, DataType::Int32, BitOr, ScalarValue::from(15i32))
735-
}
736-
737-
#[test]
738-
fn bit_or_i32_with_nulls() -> Result<()> {
739-
let a: ArrayRef =
740-
Arc::new(Int32Array::from(vec![Some(1), None, Some(3), Some(5)]));
741-
generic_test_op!(a, DataType::Int32, BitOr, ScalarValue::from(7i32))
742-
}
743-
744-
#[test]
745-
fn bit_or_i32_all_nulls() -> Result<()> {
746-
let a: ArrayRef = Arc::new(Int32Array::from(vec![None, None]));
747-
generic_test_op!(a, DataType::Int32, BitOr, ScalarValue::Int32(None))
748-
}
749-
750-
#[test]
751-
fn bit_or_u32() -> Result<()> {
752-
let a: ArrayRef = Arc::new(UInt32Array::from(vec![4_u32, 7_u32, 15_u32]));
753-
generic_test_op!(a, DataType::UInt32, BitOr, ScalarValue::from(15u32))
754-
}
755-
756-
#[test]
757-
fn bit_xor_i32() -> Result<()> {
758-
let a: ArrayRef = Arc::new(Int32Array::from(vec![4, 7, 4, 7, 15]));
759-
generic_test_op!(a, DataType::Int32, BitXor, ScalarValue::from(15i32))
760-
}
761-
762-
#[test]
763-
fn bit_xor_i32_with_nulls() -> Result<()> {
764-
let a: ArrayRef = Arc::new(Int32Array::from(vec![
765-
Some(1),
766-
Some(1),
767-
None,
768-
Some(3),
769-
Some(5),
770-
]));
771-
generic_test_op!(a, DataType::Int32, BitXor, ScalarValue::from(6i32))
772-
}
773-
774-
#[test]
775-
fn bit_xor_i32_all_nulls() -> Result<()> {
776-
let a: ArrayRef = Arc::new(Int32Array::from(vec![None, None]));
777-
generic_test_op!(a, DataType::Int32, BitXor, ScalarValue::Int32(None))
778-
}
779-
780-
#[test]
781-
fn bit_xor_u32() -> Result<()> {
782-
let a: ArrayRef =
783-
Arc::new(UInt32Array::from(vec![4_u32, 7_u32, 4_u32, 7_u32, 15_u32]));
784-
generic_test_op!(a, DataType::UInt32, BitXor, ScalarValue::from(15u32))
785-
}
786-
787-
#[test]
788-
fn bit_xor_distinct_i32() -> Result<()> {
789-
let a: ArrayRef = Arc::new(Int32Array::from(vec![4, 7, 4, 7, 15]));
790-
generic_test_op!(a, DataType::Int32, DistinctBitXor, ScalarValue::from(12i32))
791-
}
792-
793-
#[test]
794-
fn bit_xor_distinct_i32_with_nulls() -> Result<()> {
795-
let a: ArrayRef = Arc::new(Int32Array::from(vec![
796-
Some(1),
797-
Some(1),
798-
None,
799-
Some(3),
800-
Some(5),
801-
]));
802-
generic_test_op!(a, DataType::Int32, DistinctBitXor, ScalarValue::from(7i32))
803-
}
804-
805-
#[test]
806-
fn bit_xor_distinct_i32_all_nulls() -> Result<()> {
807-
let a: ArrayRef = Arc::new(Int32Array::from(vec![None, None]));
808-
generic_test_op!(a, DataType::Int32, DistinctBitXor, ScalarValue::Int32(None))
809-
}
810-
811-
#[test]
812-
fn bit_xor_distinct_u32() -> Result<()> {
813-
let a: ArrayRef =
814-
Arc::new(UInt32Array::from(vec![4_u32, 7_u32, 4_u32, 7_u32, 15_u32]));
815-
generic_test_op!(
816-
a,
817-
DataType::UInt32,
818-
DistinctBitXor,
819-
ScalarValue::from(12u32)
820-
)
821-
}
822-
}

datafusion/sqllogictest/test_files/aggregate.slt

Lines changed: 195 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2285,6 +2285,201 @@ ORDER BY tag
22852285
33 11 NULL 33 11 NULL 33 11 NULL B
22862286

22872287

2288+
# bit_and_i32
2289+
statement ok
2290+
create table t (c int) as values (4), (7), (15);
2291+
2292+
query IT
2293+
Select bit_and(c), arrow_typeof(bit_and(c)) from t;
2294+
----
2295+
4 Int32
2296+
2297+
statement ok
2298+
drop table t;
2299+
2300+
# bit_and_i32_with_nulls
2301+
statement ok
2302+
create table t (c int) as values (1), (NULL), (3), (5);
2303+
2304+
query IT
2305+
Select bit_and(c), arrow_typeof(bit_and(c)) from t;
2306+
----
2307+
1 Int32
2308+
2309+
statement ok
2310+
drop table t;
2311+
2312+
# bit_and_i32_all_nulls
2313+
statement ok
2314+
create table t (c int) as values (NULL), (NULL);
2315+
2316+
query IT
2317+
Select bit_and(c), arrow_typeof(bit_and(c)) from t;
2318+
----
2319+
NULL Int32
2320+
2321+
statement ok
2322+
drop table t;
2323+
2324+
# bit_and_u32
2325+
statement ok
2326+
create table t (c int unsigned) as values (4), (7), (15);
2327+
2328+
query IT
2329+
Select bit_and(c), arrow_typeof(bit_and(c)) from t;
2330+
----
2331+
4 UInt32
2332+
2333+
statement ok
2334+
drop table t;
2335+
2336+
# bit_or_i32
2337+
statement ok
2338+
create table t (c int) as values (4), (7), (15);
2339+
2340+
query IT
2341+
Select bit_or(c), arrow_typeof(bit_or(c)) from t;
2342+
----
2343+
15 Int32
2344+
2345+
statement ok
2346+
drop table t;
2347+
2348+
# bit_or_i32_with_nulls
2349+
statement ok
2350+
create table t (c int) as values (1), (NULL), (3), (5);
2351+
2352+
query IT
2353+
Select bit_or(c), arrow_typeof(bit_or(c)) from t;
2354+
----
2355+
7 Int32
2356+
2357+
statement ok
2358+
drop table t;
2359+
2360+
#bit_or_i32_all_nulls
2361+
statement ok
2362+
create table t (c int) as values (NULL), (NULL);
2363+
2364+
query IT
2365+
Select bit_or(c), arrow_typeof(bit_or(c)) from t;
2366+
----
2367+
NULL Int32
2368+
2369+
statement ok
2370+
drop table t;
2371+
2372+
2373+
#bit_or_u32
2374+
statement ok
2375+
create table t (c int unsigned) as values (4), (7), (15);
2376+
2377+
query IT
2378+
Select bit_or(c), arrow_typeof(bit_or(c)) from t;
2379+
----
2380+
15 UInt32
2381+
2382+
statement ok
2383+
drop table t;
2384+
2385+
#bit_xor_i32
2386+
statement ok
2387+
create table t (c int) as values (4), (7), (4), (7), (15);
2388+
2389+
query IT
2390+
Select bit_xor(c), arrow_typeof(bit_xor(c)) from t;
2391+
----
2392+
15 Int32
2393+
2394+
statement ok
2395+
drop table t;
2396+
2397+
# bit_xor_i32_with_nulls
2398+
statement ok
2399+
create table t (c int) as values (1), (1), (NULL), (3), (5);
2400+
2401+
query IT
2402+
Select bit_xor(c), arrow_typeof(bit_xor(c)) from t;
2403+
----
2404+
6 Int32
2405+
2406+
statement ok
2407+
drop table t;
2408+
2409+
# bit_xor_i32_all_nulls
2410+
statement ok
2411+
create table t (c int) as values (NULL), (NULL);
2412+
2413+
query IT
2414+
Select bit_xor(c), arrow_typeof(bit_xor(c)) from t;
2415+
----
2416+
NULL Int32
2417+
2418+
statement ok
2419+
drop table t;
2420+
2421+
# bit_xor_u32
2422+
statement ok
2423+
create table t (c int unsigned) as values (4), (7), (4), (7), (15);
2424+
2425+
query IT
2426+
Select bit_xor(c), arrow_typeof(bit_xor(c)) from t;
2427+
----
2428+
15 UInt32
2429+
2430+
statement ok
2431+
drop table t;
2432+
2433+
# bit_xor_distinct_i32
2434+
statement ok
2435+
create table t (c int) as values (4), (7), (4), (7), (15);
2436+
2437+
query IT
2438+
Select bit_xor(DISTINCT c), arrow_typeof(bit_xor(DISTINCT c)) from t;
2439+
----
2440+
12 Int32
2441+
2442+
statement ok
2443+
drop table t;
2444+
2445+
# bit_xor_distinct_i32_with_nulls
2446+
statement ok
2447+
create table t (c int) as values (1), (1), (NULL), (3), (5);
2448+
2449+
query IT
2450+
Select bit_xor(DISTINCT c), arrow_typeof(bit_xor(DISTINCT c)) from t;
2451+
----
2452+
7 Int32
2453+
2454+
2455+
statement ok
2456+
drop table t;
2457+
2458+
# bit_xor_distinct_i32_all_nulls
2459+
statement ok
2460+
create table t (c int ) as values (NULL), (NULL);
2461+
2462+
query IT
2463+
Select bit_xor(DISTINCT c), arrow_typeof(bit_xor(DISTINCT c)) from t;
2464+
----
2465+
NULL Int32
2466+
2467+
2468+
statement ok
2469+
drop table t;
2470+
2471+
# bit_xor_distinct_u32
2472+
statement ok
2473+
create table t (c int unsigned) as values (4), (7), (4), (7), (15);
2474+
2475+
query IT
2476+
Select bit_xor(DISTINCT c), arrow_typeof(bit_xor(DISTINCT c)) from t;
2477+
----
2478+
12 UInt32
2479+
2480+
statement ok
2481+
drop table t;
2482+
22882483
statement ok
22892484
create table bool_aggregate_functions (
22902485
c1 boolean not null,

0 commit comments

Comments
 (0)