Skip to content

Commit 7e12654

Browse files
committed
feat(query): improve domain
1 parent 9ab84da commit 7e12654

File tree

1 file changed

+29
-2
lines changed

1 file changed

+29
-2
lines changed

src/query/functions-v2/src/scalars/boolean.rs

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
// limitations under the License.
1414

1515
use common_expression::types::boolean::BooleanDomain;
16+
use common_expression::types::nullable::NullableDomain;
1617
use common_expression::types::BooleanType;
1718
use common_expression::types::NullableType;
1819
use common_expression::vectorize_2_arg;
@@ -73,7 +74,20 @@ pub fn register(registry: &mut FunctionRegistry) {
7374
registry.register_2_arg_core::<NullableType<BooleanType>, NullableType<BooleanType>, NullableType<BooleanType>, _, _>(
7475
"and",
7576
FunctionProperty::default(),
76-
|_, _| {
77+
|lhs, rhs| {
78+
if !lhs.has_null && !rhs.has_null {
79+
let bools = match ( &lhs.value, &rhs.value) {
80+
(Some(a), Some(b)) => Some(Box::new(BooleanDomain {
81+
has_false: a.has_false || b.has_false,
82+
has_true: a.has_true && b.has_true,
83+
})),
84+
_ => None,
85+
};
86+
return Some(NullableDomain::<BooleanType> {
87+
has_null: false,
88+
value: bools,
89+
});
90+
}
7791
None
7892
},
7993
vectorize_2_arg::<NullableType<BooleanType>, NullableType<BooleanType>, NullableType<BooleanType>>(|lhs, rhs| {
@@ -91,7 +105,20 @@ pub fn register(registry: &mut FunctionRegistry) {
91105
registry.register_2_arg_core::<NullableType<BooleanType>, NullableType<BooleanType>, NullableType<BooleanType>, _, _>(
92106
"or",
93107
FunctionProperty::default(),
94-
|_, _| {
108+
|lhs, rhs| {
109+
if !lhs.has_null && !rhs.has_null {
110+
let bools = match (&lhs.value, &rhs.value) {
111+
(Some(a), Some(b)) => Some(Box::new(BooleanDomain {
112+
has_false: a.has_false && b.has_false,
113+
has_true: a.has_true || b.has_true,
114+
})),
115+
_ => None,
116+
};
117+
return Some(NullableDomain::<BooleanType> {
118+
has_null: false,
119+
value: bools,
120+
});
121+
}
95122
None
96123
},
97124
vectorize_2_arg::<NullableType<BooleanType>, NullableType<BooleanType>, NullableType<BooleanType>>(|lhs, rhs| {

0 commit comments

Comments
 (0)