Skip to content

Commit 7cf708f

Browse files
authored
Merge pull request #10594 from andylokandy/validity
2 parents d0fd5be + 37d3344 commit 7cf708f

File tree

23 files changed

+1259
-964
lines changed

23 files changed

+1259
-964
lines changed

docs/doc/15-sql-functions/11-conditional-functions/index.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,10 @@ title: 'Conditional Functions'
44

55
| Function | Description | Example | Result |
66
|------------------------------------------------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------|----------------------------------------------------------------------------------|----------|
7-
| **IF(expr1, expr2, expr3)** | Return expr2 if expr1 is TRUE. Otherwise return expr3. expr2 and expr3 must have the lowest common type. | **IF(1 > 2, 3, 4)** | 4 |
7+
| **IF(cond1, expr1, [cond2, expr2, ...], expr_else)** | If cond1 is TRUE, it returns expr1. Otherwise if cond2 is TRUE, it returns expr2, and so on. | **IF(1 > 2, 3, 4 < 5, 6, 7)** | 6 |
88
| **IFNULL(expr1, expr2)** | Return expr1 if it is not NULL. Otherwise return expr2. They must have the same data type. | **IFNULL(0, NULL)** | 0 |
99
| **value [ NOT ] IN (value1, value2, ...)** | Check whether value is (or is not) one of the members of an explicit list. | **1 not in (2, 3)** | 1(TRUE) |
1010
| **expr1 IS [ NOT ] DISTINCT FROM expr2** | Compares whether two expressions are equal (or not equal) with awareness of nullability, meaning it treats NULLs as known values for comparing equality. | **NULL is distinct from NULL** | 0(FALSE) |
1111
| **IS_NOT_NULL(expr)** | Check whether the value is not NULL. | **IS_NOT_NULL(1)** | 1(TRUE) |
1212
| **IS_NULL(expr)** | Check whether the value is NULL. | **IS_NULL(1)** | 0(FALSE) |
13-
| **MULTI_IF(cond1, expr1, [cond2, expr2, ...], expr_else)** | If cond1 is TRUE, it returns expr1. Otherwise if cond2 is TRUE, it returns expr2, and so on. | **MULTI_IF(1 > 2, 3, 4 < 5, 6, 7)** | 6 |
1413
| **NULLIF(expr1, expr2)** | Return NULL if two expressions are equal. Otherwise return expr1. They must have the same data type. | **NULLIF(0, NULL)** | 0 |

src/query/codegen/src/bin/codegen.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,6 @@
1313
// limitations under the License.
1414

1515
fn main() {
16-
codegen::writes::codegen_arithmetic_type_v2();
16+
codegen::writes::codegen_arithmetic_type();
1717
codegen::writes::codegen_register();
1818
}

src/query/codegen/src/writes/arithmetics_type.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ pub enum OP {
2929
Super,
3030
}
3131

32-
pub fn codegen_arithmetic_type_v2() {
32+
pub fn codegen_arithmetic_type() {
3333
let dest = Path::new("src/query/expression/src/utils");
3434
let path = dest.join("arithmetics_type.rs");
3535

src/query/codegen/src/writes/register.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -634,7 +634,8 @@ pub fn codegen_register() {
634634

635635
format!(
636636
"({arm_pat}) => {{
637-
let validity = {and_validity};
637+
let and_validity = {and_validity};
638+
let validity = ctx.validity.as_ref().map(|valid| valid & (&and_validity)).unwrap_or(and_validity);
638639
ctx.validity = Some(validity.clone());
639640
let column = func({func_arg} ctx).into_column().unwrap();
640641
Value::Column(NullableColumn {{ column, validity }})
@@ -741,11 +742,12 @@ pub fn codegen_register() {
741742

742743
format!(
743744
"({arm_pat}) => {{
744-
let validity = {and_validity};
745+
let and_validity = {and_validity};
746+
let validity = ctx.validity.as_ref().map(|valid| valid & (&and_validity)).unwrap_or(and_validity);
745747
ctx.validity = Some(validity.clone());
746748
let nullable_column = func({func_arg} ctx).into_column().unwrap();
747-
let merge_validity = common_arrow::arrow::bitmap::and(&validity, &nullable_column.validity);
748-
Value::Column(NullableColumn {{ column: nullable_column.column, validity: merge_validity }})
749+
let combine_validity = common_arrow::arrow::bitmap::and(&validity, &nullable_column.validity);
750+
Value::Column(NullableColumn {{ column: nullable_column.column, validity: combine_validity }})
749751
}}"
750752
)
751753
})

0 commit comments

Comments
 (0)