Skip to content

Commit

Permalink
Fix mixed integer float aggregation
Browse files Browse the repository at this point in the history
  • Loading branch information
cswinter committed Jul 31, 2024
1 parent 3bc0870 commit 1e00038
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 27 deletions.
3 changes: 3 additions & 0 deletions src/engine/execution/batch_merging.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
Expand Down
22 changes: 11 additions & 11 deletions test_data/edge_cases.csv
Original file line number Diff line number Diff line change
@@ -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
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
42 changes: 26 additions & 16 deletions tests/query_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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)],
],
);
}
}

0 comments on commit 1e00038

Please sign in to comment.