Skip to content

Commit f84b483

Browse files
committed
feat(query): fix domain downcast error
1 parent 4f96660 commit f84b483

File tree

3 files changed

+16
-6
lines changed

3 files changed

+16
-6
lines changed

src/query/expression/src/types/nullable.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,14 @@ impl<T: ValueType> ValueType for NullableType<T> {
6969
has_null: *has_null,
7070
value: Some(Box::new(T::try_downcast_domain(value)?)),
7171
}),
72+
73+
Domain::Nullable(NullableDomain {
74+
has_null,
75+
value: None,
76+
}) => Some(NullableDomain {
77+
has_null: *has_null,
78+
value: None,
79+
}),
7280
_ => None,
7381
}
7482
}

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -140,10 +140,11 @@ pub fn register(registry: &mut FunctionRegistry) {
140140
}
141141
None
142142
},
143+
// value = lhs & rhs, valid = (lhs_v & rhs_v) | (!lhs & lhs_v) | (!rhs & rhs_v))
143144
vectorize_2_arg::<NullableType<BooleanType>, NullableType<BooleanType>, NullableType<BooleanType>>(|lhs, rhs| {
144145
let lhs_v = lhs.is_some();
145146
let rhs_v = rhs.is_some();
146-
let valid = (lhs_v & rhs_v) | (lhs == Some(true)) | (rhs == Some(true));
147+
let valid = (lhs_v & rhs_v) | (lhs == Some(false)) | (rhs == Some(false));
147148
if valid {
148149
Some(lhs.unwrap_or_default() & rhs.unwrap_or_default())
149150
} else {
@@ -171,8 +172,9 @@ pub fn register(registry: &mut FunctionRegistry) {
171172
}
172173
None
173174
},
175+
// value = lhs | rhs, valid = (lhs_v & rhs_v) | (lhs | rhs))
174176
vectorize_2_arg::<NullableType<BooleanType>, NullableType<BooleanType>, NullableType<BooleanType>>(|lhs, rhs| {
175-
let valid = (lhs.is_some() & rhs.is_some()) | lhs.unwrap_or_default() | rhs.unwrap_or_default();
177+
let valid = (lhs.is_some() & rhs.is_some()) | (lhs.unwrap_or_default() | rhs.unwrap_or_default());
176178
if valid {
177179
Some(lhs.unwrap_or_default() | rhs.unwrap_or_default())
178180
} else {

src/query/functions-v2/tests/it/scalars/testdata/boolean.txt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,10 @@ output : false
1010
ast : true AND null
1111
raw expr : and(true, NULL)
1212
checked expr : and<Boolean NULL, Boolean NULL>(CAST(true AS Boolean NULL), CAST(NULL AS Boolean NULL))
13-
optimized expr : false
13+
optimized expr : NULL
1414
output type : Boolean NULL
1515
output domain : Unknown
16-
output : false
16+
output : NULL
1717

1818

1919
ast : true AND true
@@ -37,10 +37,10 @@ output : false
3737
ast : false AND null
3838
raw expr : and(false, NULL)
3939
checked expr : and<Boolean NULL, Boolean NULL>(CAST(false AS Boolean NULL), CAST(NULL AS Boolean NULL))
40-
optimized expr : NULL
40+
optimized expr : false
4141
output type : Boolean NULL
4242
output domain : Unknown
43-
output : NULL
43+
output : false
4444

4545

4646
ast : false AND true

0 commit comments

Comments
 (0)