Skip to content

Commit

Permalink
Fix null expression in AND or OR
Browse files Browse the repository at this point in the history
  • Loading branch information
cswinter committed Aug 3, 2024
1 parent 28ce33b commit 2bfa2f2
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
11 changes: 11 additions & 0 deletions src/engine/planning/query_plan.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1186,6 +1186,11 @@ impl QueryPlan {
QueryPlan::compile_expr(lhs, filter, columns, column_len, planner)?;
let (plan_rhs, type_rhs) =
QueryPlan::compile_expr(rhs, filter, columns, column_len, planner)?;
if type_lhs.decoded == BasicType::Null {
return Ok((plan_rhs, type_rhs));
} else if type_rhs.decoded == BasicType::Null {
return Ok((plan_lhs, type_lhs));
}
if type_lhs.decoded != BasicType::Boolean || type_rhs.decoded != BasicType::Boolean
{
log::info!(
Expand Down Expand Up @@ -1213,6 +1218,11 @@ impl QueryPlan {
QueryPlan::compile_expr(lhs, filter, columns, column_len, planner)?;
let (plan_rhs, type_rhs) =
QueryPlan::compile_expr(rhs, filter, columns, column_len, planner)?;
if type_lhs.decoded == BasicType::Null {
return Ok((plan_rhs, type_rhs));
} else if type_rhs.decoded == BasicType::Null {
return Ok((plan_lhs, type_lhs));
}
if type_lhs.decoded != BasicType::Boolean || type_rhs.decoded != BasicType::Boolean
{
bail!(
Expand Down Expand Up @@ -1590,6 +1600,7 @@ fn encoding_range(plan: &TypedBufferRef, qp: &QueryPlanner) -> Option<(i64, i64)
Floor { input, .. } => encoding_range(&input, qp),
ScalarI64 { value, .. } => Some((value, value)),
ScalarF64 { value, .. } => Some((value.floor() as i64, value.ceil() as i64)),
NullableFilter { ref plan, .. } => encoding_range(plan, qp),
ref plan => {
error!("encoding_range not implement for {:?}", plan);
None
Expand Down
9 changes: 9 additions & 0 deletions tests/query_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1974,3 +1974,12 @@ fn test_sum_where_nullable_gte_constant() {
&[vec![Int(11)]],
);
}


#[test]
fn test_sum_where_nullable_and_bool() {
test_query_ec(
"SELECT SUM(id) FROM default WHERE nullable_float >= 0.1 AND id > 5;",
&[vec![Int(9)]],
);
}

0 comments on commit 2bfa2f2

Please sign in to comment.