Jefffrey commented on code in PR #20354:
URL: https://github.com/apache/datafusion/pull/20354#discussion_r2832316597


##########
datafusion/functions/src/regex/regexplike.rs:
##########
@@ -314,6 +328,89 @@ pub fn regexp_like(args: &[ArrayRef]) -> Result<ArrayRef> {
     }
 }
 
+fn scalar_string(value: &ScalarValue) -> Result<Option<&str>> {
+    match value.try_as_str() {
+        Some(v) => Ok(v),
+        None => internal_err!(
+            "Unsupported data type {:?} for function `regexp_like`",
+            value.data_type()
+        ),
+    }
+}
+
+fn regexp_like_array_scalar(
+    values: &ArrayRef,
+    pattern: Option<&str>,
+    flags: Option<&str>,
+) -> Result<ArrayRef> {
+    use DataType::*;
+
+    if pattern.is_none() {
+        return Ok(Arc::new(BooleanArray::new_null(values.len())));
+    }
+
+    let pattern = pattern.unwrap();
+    let array = match values.data_type() {
+        Utf8 => {
+            let array = values.as_string::<i32>();
+            regexp::regexp_is_match_scalar(array, pattern, flags)?
+        }
+        Utf8View => {
+            let array = values.as_string_view();
+            regexp::regexp_is_match_scalar(array, pattern, flags)?
+        }
+        LargeUtf8 => {
+            let array = values.as_string::<i64>();
+            regexp::regexp_is_match_scalar(array, pattern, flags)?
+        }
+        other => {
+            return internal_err!(
+                "Unsupported data type {other:?} for function `regexp_like`"
+            );
+        }
+    };
+
+    Ok(Arc::new(array))
+}
+
+fn regexp_like_scalar(
+    value: &ScalarValue,

Review Comment:
   It's inconsistent how this function accepts `ScalarValue`s but the sibling 
function `regexp_like_array_scalar` directly accepts `Option<&str>`



##########
datafusion/functions/src/regex/regexplike.rs:
##########
@@ -314,6 +328,89 @@ pub fn regexp_like(args: &[ArrayRef]) -> Result<ArrayRef> {
     }
 }
 
+fn scalar_string(value: &ScalarValue) -> Result<Option<&str>> {
+    match value.try_as_str() {
+        Some(v) => Ok(v),
+        None => internal_err!(
+            "Unsupported data type {:?} for function `regexp_like`",
+            value.data_type()
+        ),
+    }
+}
+
+fn regexp_like_array_scalar(
+    values: &ArrayRef,
+    pattern: Option<&str>,
+    flags: Option<&str>,
+) -> Result<ArrayRef> {
+    use DataType::*;
+
+    if pattern.is_none() {
+        return Ok(Arc::new(BooleanArray::new_null(values.len())));
+    }
+
+    let pattern = pattern.unwrap();

Review Comment:
   ```suggestion
       let Some(pattern) = pattern else {
           return Ok(Arc::new(BooleanArray::new_null(values.len())));
       };
   ```
   
   More ergonomic destructuring



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to