From 1e000384ca8b19d39b96da7fa7b5f569062d333b Mon Sep 17 00:00:00 2001 From: Clemens Winter Date: Tue, 30 Jul 2024 19:58:14 -0700 Subject: [PATCH] Fix mixed integer float aggregation --- src/engine/execution/batch_merging.rs | 3 ++ test_data/edge_cases.csv | 22 +++++++------- tests/query_tests.rs | 42 +++++++++++++++++---------- 3 files changed, 40 insertions(+), 27 deletions(-) diff --git a/src/engine/execution/batch_merging.rs b/src/engine/execution/batch_merging.rs index 6ce08303..11d9daaa 100644 --- a/src/engine/execution/batch_merging.rs +++ b/src/engine/execution/batch_merging.rs @@ -175,6 +175,9 @@ pub fn combine<'a>( { let left = left[ileft]; let right = right[iright]; + let (left, right) = unify_types(&mut qp, left, right); + let left = null_to_val(&mut qp, left); + let right = null_to_val(&mut qp, right); let aggregated = qp.merge_aggregate(ops, left, right, aggregator); aggregates.push((aggregated.any(), aggregator)); } diff --git a/test_data/edge_cases.csv b/test_data/edge_cases.csv index 2adf09a0..c18b6117 100644 --- a/test_data/edge_cases.csv +++ b/test_data/edge_cases.csv @@ -1,11 +1,11 @@ -u8_offset_encoded,non_dense_ints,enum,string_packed,constant0,constant0_2,negative,id,nullable_int,nullable_int2,country,largenum,float,nullable_float,float01 -256,0,aa,xyz,0,0,-199,0,-1,,Germany,-9223372036854775808,0.123412,,0.3 -258,2,aa,abc,0,0,39,1,-40,-40,USA,9223372036854775806,3e-4,,-0.4 -259,3,aa,axz,0,0,-100,2,,,France,9223372036854775806,-124.0,0.4,0.421231 -257,1,bb,AXY,0,0,34,3,,0,,9223372036854775806,3.15159,,0.9482 -275,4,bb,azy,0,0,4031,4,10,9,France,-9223372036854775808,0.1234e30,,0.1 -500,0,aa,$sss,0,0,32,5,,6,,9223372036854775806,1e-6,,0.2 -343,2,cc,asd,0,0,-130,6,,,Turkey,-9223372036854775808,0.0,1e-32,0.5 -432,1,aa,_f,0,0,-120,7,20,,,9223372036854775806,0.000001,,0.23 -511,2,cc,t,0,0,4010,8,,1,,-9223372036854775808,-1.0,,0.742 -500,3,bb,😈,0,0,-40,9,13,14,Germany,9223372036854775806,1234124.51325,1.123124e30,-0.2 \ No newline at end of file +u8_offset_encoded,non_dense_ints,enum,string_packed,constant0,constant0_2,negative,id,nullable_int,nullable_int2,country,largenum,float,nullable_float,float01,mixed_float_int_null +256,0,aa,xyz,0,0,-199,0,-1,,Germany,-9223372036854775808,0.123412,,0.3,1 +258,2,aa,abc,0,0,39,1,-40,-40,USA,9223372036854775806,3e-4,,-0.4,10 +259,3,aa,axz,0,0,-100,2,,,France,9223372036854775806,-124.0,0.4,0.421231,3 +257,1,bb,AXY,0,0,34,3,,0,,9223372036854775806,3.15159,,0.9482,0.21 +275,4,bb,azy,0,0,4031,4,10,9,France,-9223372036854775808,0.1234e30,,0.1,0.12 +500,0,aa,$sss,0,0,32,5,,6,,9223372036854775806,1e-6,,0.2, +343,2,cc,asd,0,0,-130,6,,,Turkey,-9223372036854775808,0.0,1e-32,0.5, +432,1,aa,_f,0,0,-120,7,20,,,9223372036854775806,0.000001,,0.23,0.1 +511,2,cc,t,0,0,4010,8,,1,,-9223372036854775808,-1.0,,0.742,0.1 +500,3,bb,😈,0,0,-40,9,13,14,Germany,9223372036854775806,1234124.51325,1.123124e30,-0.2,0.5 \ No newline at end of file diff --git a/tests/query_tests.rs b/tests/query_tests.rs index 80424a06..ab50dddf 100644 --- a/tests/query_tests.rs +++ b/tests/query_tests.rs @@ -891,6 +891,17 @@ fn test_divide_multiply_null() { ); } +#[test] +fn test_aggregate_mixed_int_float_null() { + test_query_ec( + "SELECT SUM(mixed_float_int_null), COUNT(mixed_float_int_null), MIN(mixed_float_int_null), MAX(mixed_float_int_null), id / 5 FROM default", + &[ + vec![Float(14.33), Int(5), Float(0.12), Float(10.0), Int(0)], + vec![Float(0.7), Int(3), Float(0.1), Float(0.5), Int(1)] + ] + ); +} + #[test] fn test_sort_by_nullable1() { test_query_ec( @@ -1395,7 +1406,8 @@ fn test_long_nullable() { "nullable_int".to_string(), locustdb::colgen::nullable_ints(vec![None, Some(1), Some(-10)], vec![0.9, 0.05, 0.05]), )], - })).unwrap(); + })) + .unwrap(); let query = "SELECT nullable_int FROM test LIMIT 0;"; let expected_rows: Vec<[Value; 1]> = vec![]; let result = block_on(locustdb.run_query(query, true, true, vec![])).unwrap(); @@ -1877,34 +1889,32 @@ fn test_float_greater_than_int() { // ); // } - #[test] fn test_floor1() { test_query_ec( "SELECT MAX(id), MIN(id), FLOOR(float01 * 10) FROM default", &[ - vec![Int(1), Int(1), Int(-4)], - vec![Int(9), Int(9), Int(-2)], - vec![Int(4), Int(4), Int(1)], - vec![Int(7), Int(5), Int(2)], - vec![Int(0), Int(0), Int(3)], - vec![Int(2), Int(2), Int(4)], - vec![Int(6), Int(6), Int(5)], - vec![Int(8), Int(8), Int(7)], - vec![Int(3), Int(3), Int(9)] + vec![Int(1), Int(1), Int(-4)], + vec![Int(9), Int(9), Int(-2)], + vec![Int(4), Int(4), Int(1)], + vec![Int(7), Int(5), Int(2)], + vec![Int(0), Int(0), Int(3)], + vec![Int(2), Int(2), Int(4)], + vec![Int(6), Int(6), Int(5)], + vec![Int(8), Int(8), Int(7)], + vec![Int(3), Int(3), Int(9)], ], ); } - #[test] fn test_floor2() { test_query_ec( "SELECT MIN(id), MAX(id), FLOOR(id * 0.23) FROM default", &[ - vec![Int(0), Int(4), Int(0)], - vec![Int(5), Int(8), Int(1)], - vec![Int(9), Int(9), Int(2)], + vec![Int(0), Int(4), Int(0)], + vec![Int(5), Int(8), Int(1)], + vec![Int(9), Int(9), Int(2)], ], ); -} \ No newline at end of file +}