Skip to content

Commit e84f343

Browse files
authored
Fix: handle NULL input for regex match operations (#12028)
1 parent 1f90b00 commit e84f343

File tree

2 files changed

+53
-4
lines changed

2 files changed

+53
-4
lines changed

datafusion/physical-expr/src/expressions/binary.rs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -318,10 +318,14 @@ impl PhysicalExpr for BinaryExpr {
318318
// Attempt to use special kernels if one input is scalar and the other is an array
319319
let scalar_result = match (&lhs, &rhs) {
320320
(ColumnarValue::Array(array), ColumnarValue::Scalar(scalar)) => {
321-
// if left is array and right is literal - use scalar operations
322-
self.evaluate_array_scalar(array, scalar.clone())?.map(|r| {
323-
r.and_then(|a| to_result_type_array(&self.op, a, &result_type))
324-
})
321+
// if left is array and right is literal(not NULL) - use scalar operations
322+
if scalar.is_null() {
323+
None
324+
} else {
325+
self.evaluate_array_scalar(array, scalar.clone())?.map(|r| {
326+
r.and_then(|a| to_result_type_array(&self.op, a, &result_type))
327+
})
328+
}
325329
}
326330
(_, _) => None, // default to array implementation
327331
};

datafusion/sqllogictest/test_files/regexp.slt

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,51 @@ true
4848
true
4949
true
5050

51+
query B
52+
SELECT str ~ NULL FROM t;
53+
----
54+
NULL
55+
NULL
56+
NULL
57+
NULL
58+
NULL
59+
NULL
60+
NULL
61+
NULL
62+
NULL
63+
NULL
64+
NULL
65+
66+
query B
67+
select str ~ right('foo', NULL) FROM t;
68+
----
69+
NULL
70+
NULL
71+
NULL
72+
NULL
73+
NULL
74+
NULL
75+
NULL
76+
NULL
77+
NULL
78+
NULL
79+
NULL
80+
81+
query B
82+
select right('foo', NULL) !~ str FROM t;
83+
----
84+
NULL
85+
NULL
86+
NULL
87+
NULL
88+
NULL
89+
NULL
90+
NULL
91+
NULL
92+
NULL
93+
NULL
94+
NULL
95+
5196
query B
5297
SELECT regexp_like('foobarbequebaz', '');
5398
----

0 commit comments

Comments
 (0)