This is an automated email from the ASF dual-hosted git repository.
alamb pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/datafusion.git
The following commit(s) were added to refs/heads/main by this push:
new e84f3436c0 Fix: handle NULL input for regex match operations (#12028)
e84f3436c0 is described below
commit e84f3436c079a8264bf3052f64db31ba6fbddbff
Author: HuSen <[email protected]>
AuthorDate: Sat Aug 17 18:48:55 2024 +0800
Fix: handle NULL input for regex match operations (#12028)
---
datafusion/physical-expr/src/expressions/binary.rs | 12 ++++--
datafusion/sqllogictest/test_files/regexp.slt | 45 ++++++++++++++++++++++
2 files changed, 53 insertions(+), 4 deletions(-)
diff --git a/datafusion/physical-expr/src/expressions/binary.rs
b/datafusion/physical-expr/src/expressions/binary.rs
index 06f54481a6..26885ae135 100644
--- a/datafusion/physical-expr/src/expressions/binary.rs
+++ b/datafusion/physical-expr/src/expressions/binary.rs
@@ -318,10 +318,14 @@ impl PhysicalExpr for BinaryExpr {
// Attempt to use special kernels if one input is scalar and the other
is an array
let scalar_result = match (&lhs, &rhs) {
(ColumnarValue::Array(array), ColumnarValue::Scalar(scalar)) => {
- // if left is array and right is literal - use scalar
operations
- self.evaluate_array_scalar(array, scalar.clone())?.map(|r| {
- r.and_then(|a| to_result_type_array(&self.op, a,
&result_type))
- })
+ // if left is array and right is literal(not NULL) - use
scalar operations
+ if scalar.is_null() {
+ None
+ } else {
+ self.evaluate_array_scalar(array, scalar.clone())?.map(|r|
{
+ r.and_then(|a| to_result_type_array(&self.op, a,
&result_type))
+ })
+ }
}
(_, _) => None, // default to array implementation
};
diff --git a/datafusion/sqllogictest/test_files/regexp.slt
b/datafusion/sqllogictest/test_files/regexp.slt
index c04021651a..1685ed51af 100644
--- a/datafusion/sqllogictest/test_files/regexp.slt
+++ b/datafusion/sqllogictest/test_files/regexp.slt
@@ -48,6 +48,51 @@ true
true
true
+query B
+SELECT str ~ NULL FROM t;
+----
+NULL
+NULL
+NULL
+NULL
+NULL
+NULL
+NULL
+NULL
+NULL
+NULL
+NULL
+
+query B
+select str ~ right('foo', NULL) FROM t;
+----
+NULL
+NULL
+NULL
+NULL
+NULL
+NULL
+NULL
+NULL
+NULL
+NULL
+NULL
+
+query B
+select right('foo', NULL) !~ str FROM t;
+----
+NULL
+NULL
+NULL
+NULL
+NULL
+NULL
+NULL
+NULL
+NULL
+NULL
+NULL
+
query B
SELECT regexp_like('foobarbequebaz', '');
----
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]