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/arrow-datafusion.git


The following commit(s) were added to refs/heads/main by this push:
     new 2983a7ff0f fix: incorrect nullability of `Like` expressions (#6829)
2983a7ff0f is described below

commit 2983a7ff0fcd16130243e4d7e4fb9f0efe69978a
Author: Jonah Gao <[email protected]>
AuthorDate: Tue Jul 4 03:36:30 2023 +0800

    fix: incorrect nullability of `Like` expressions (#6829)
    
    * fix: incorrect nullability of Like expr
    
    * Improve the documentation for ScalarType
---
 datafusion/common/src/scalar.rs    |  2 +-
 datafusion/expr/src/expr_schema.rs | 24 +++++++++++++++++++++---
 2 files changed, 22 insertions(+), 4 deletions(-)

diff --git a/datafusion/common/src/scalar.rs b/datafusion/common/src/scalar.rs
index e84ef54519..044d40534e 100644
--- a/datafusion/common/src/scalar.rs
+++ b/datafusion/common/src/scalar.rs
@@ -3802,7 +3802,7 @@ impl fmt::Debug for ScalarValue {
     }
 }
 
-/// Trait used to map a NativeTime to a ScalarType.
+/// Trait used to map a NativeType to a ScalarValue
 pub trait ScalarType<T: ArrowNativeType> {
     /// returns a scalar from an optional T
     fn scalar(r: Option<T>) -> ScalarValue;
diff --git a/datafusion/expr/src/expr_schema.rs 
b/datafusion/expr/src/expr_schema.rs
index 30537d0fdd..76f37e4d6c 100644
--- a/datafusion/expr/src/expr_schema.rs
+++ b/datafusion/expr/src/expr_schema.rs
@@ -251,9 +251,11 @@ impl ExprSchemable for Expr {
                 ref right,
                 ..
             }) => Ok(left.nullable(input_schema)? || 
right.nullable(input_schema)?),
-            Expr::Like(Like { expr, .. }) => expr.nullable(input_schema),
-            Expr::ILike(Like { expr, .. }) => expr.nullable(input_schema),
-            Expr::SimilarTo(Like { expr, .. }) => expr.nullable(input_schema),
+            Expr::Like(Like { expr, pattern, .. })
+            | Expr::ILike(Like { expr, pattern, .. })
+            | Expr::SimilarTo(Like { expr, pattern, .. }) => {
+                Ok(expr.nullable(input_schema)? || 
pattern.nullable(input_schema)?)
+            }
             Expr::Wildcard => Err(DataFusionError::Internal(
                 "Wildcard expressions are not valid in a logical query 
plan".to_owned(),
             )),
@@ -437,6 +439,22 @@ mod tests {
         assert!(expr.nullable(&get_schema(false)).unwrap());
     }
 
+    #[test]
+    fn test_like_nullability() {
+        let get_schema = |nullable| {
+            MockExprSchema::new()
+                .with_data_type(DataType::Utf8)
+                .with_nullable(nullable)
+        };
+
+        let expr = col("foo").like(lit("bar"));
+        assert!(!expr.nullable(&get_schema(false)).unwrap());
+        assert!(expr.nullable(&get_schema(true)).unwrap());
+
+        let expr = col("foo").like(lit(ScalarValue::Utf8(None)));
+        assert!(expr.nullable(&get_schema(false)).unwrap());
+    }
+
     #[test]
     fn expr_schema_data_type() {
         let expr = col("foo");

Reply via email to