Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(query): fix boolean type comparison #15171

Merged
merged 2 commits into from
Apr 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/query/expression/src/types/boolean.rs
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ impl ValueType for BooleanType {

#[inline(always)]
fn greater_than_equal(left: Self::ScalarRef<'_>, right: Self::ScalarRef<'_>) -> bool {
(left & !right) || (left & right)
left | !right
}

#[inline(always)]
Expand All @@ -183,7 +183,7 @@ impl ValueType for BooleanType {

#[inline(always)]
fn less_than_equal(left: Self::ScalarRef<'_>, right: Self::ScalarRef<'_>) -> bool {
(!left & right) || (left & right)
!left | right
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/query/functions/src/scalars/comparison.rs
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ fn register_boolean_cmp(registry: &mut FunctionRegistry) {
(false, true, true, false) => FunctionDomain::Domain(ALL_FALSE_DOMAIN),
_ => FunctionDomain::Full,
},
|lhs, rhs, _| (lhs & !rhs) || (lhs & rhs),
|lhs, rhs, _| lhs | !rhs,
);
registry.register_2_arg::<BooleanType, BooleanType, BooleanType, _, _>(
"lt",
Expand All @@ -228,7 +228,7 @@ fn register_boolean_cmp(registry: &mut FunctionRegistry) {
(true, false, false, true) => FunctionDomain::Domain(ALL_FALSE_DOMAIN),
_ => FunctionDomain::Full,
},
|lhs, rhs, _| (!lhs & rhs) || (lhs & rhs),
|lhs, rhs, _| !lhs | rhs,
);
}

Expand Down
33 changes: 33 additions & 0 deletions tests/sqllogictests/suites/query/filter.test
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,36 @@ select a from t where a = 0 or 3 / a > 2 order by a

statement ok
drop table if exists t;

# Boolean comparison
statement ok
drop table if exists t;

statement ok
create table t(a boolean, b boolean);

statement ok
insert into t values(true, true), (true, false), (false, false);

query I
select count(*) from t where a > b;
----
1

query II
select count(*) from t where a >= b;
----
3

query III
select count(*) from t where a < b;
----
0

query I?
select count(*) from t where a <= b;
----
2

statement ok
drop table if exists t;
Loading