Skip to content

Commit

Permalink
Fix float comparison with offset encoded nullable integer
Browse files Browse the repository at this point in the history
  • Loading branch information
cswinter committed Aug 10, 2024
1 parent 136c891 commit 61a6bf3
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 6 deletions.
15 changes: 9 additions & 6 deletions src/engine/planning/query_plan.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1340,7 +1340,7 @@ impl QueryPlan {
};

if declaration.encoding_invariance && type_lhs.is_scalar && type_rhs.is_encoded() {
plan_lhs = if type_rhs.decoded == BasicType::Integer {
plan_lhs = if type_rhs.decoded == BasicType::Integer || type_rhs.decoded == BasicType::NullableInteger {
if let QueryPlan::ScalarI64 { value, .. } = *planner.resolve(&plan_lhs) {
planner
.scalar_i64(type_rhs.codec.encode_int(value), true)
Expand All @@ -1354,20 +1354,20 @@ impl QueryPlan {
} else {
panic!("Can't encode {:?}", plan_lhs)
}
} else if type_rhs.decoded == BasicType::String {
} else if type_rhs.decoded == BasicType::String || type_rhs.decoded == BasicType::NullableString {
type_rhs
.codec
.clone()
.encode_str(plan_lhs.scalar_str()?, planner)
.into()
} else {
panic!("Can't encode {:?}", plan_lhs)
panic!("Can't elide decode on {:?}", plan_rhs)
};
} else if declaration.encoding_invariance
&& type_rhs.is_scalar
&& type_lhs.is_encoded()
{
plan_rhs = if type_lhs.decoded == BasicType::Integer {
plan_rhs = if type_lhs.decoded == BasicType::Integer || type_lhs.decoded == BasicType::NullableInteger {
if let QueryPlan::ScalarI64 { value, .. } = *planner.resolve(&plan_rhs) {
planner
.scalar_i64(type_lhs.codec.encode_int(value), true)
Expand All @@ -1381,14 +1381,14 @@ impl QueryPlan {
} else {
panic!("Can't encode {:?}", plan_rhs)
}
} else if type_lhs.decoded == BasicType::String {
} else if type_lhs.decoded == BasicType::String || type_lhs.decoded == BasicType::NullableString {
type_lhs
.codec
.clone()
.encode_str(plan_rhs.scalar_str()?, planner)
.into()
} else {
panic!("whoops");
panic!("Can't elide decode on {:?}", type_lhs);
};
} else {
plan_lhs = type_lhs.codec.decode(plan_lhs, planner);
Expand Down Expand Up @@ -2367,6 +2367,9 @@ fn int_to_float_cast(
EncodingType::U8 | EncodingType::U16 | EncodingType::U32 | EncodingType::I64 => {
EncodingType::F64
}
EncodingType::NullableU8 | EncodingType::NullableU16 | EncodingType::NullableU32 | EncodingType::NullableI64 => {
EncodingType::NullableF64
}
EncodingType::ScalarI64 => EncodingType::ScalarF64,
_ => Err(QueryError::TypeError(format!(
"Cannot cast {:?} to float",
Expand Down
9 changes: 9 additions & 0 deletions tests/query_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1992,3 +1992,12 @@ fn test_gt_float_filter_offset_encoded_int() {
&[vec![Int(5)], vec![Int(8)], vec![Int(9)]],
);
}


#[test]
fn test_gt_float_filter_offset_encoded_nullable_int() {
test_query_ec(
"SELECT id FROM default WHERE nullable_int2 <= 0.123;",
&[vec![Int(1)], vec![Int(3)]],
);
}

0 comments on commit 61a6bf3

Please sign in to comment.