You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@arrow.apache.org by dh...@apache.org on 2022/09/29 19:18:01 UTC

[arrow-datafusion] branch master updated: make regexp_replace early abort with empty input (#3648)

This is an automated email from the ASF dual-hosted git repository.

dheres pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/arrow-datafusion.git


The following commit(s) were added to refs/heads/master by this push:
     new a9f7cacce make regexp_replace early abort with empty input (#3648)
a9f7cacce is described below

commit a9f7cacce7f22e1b645821d0ce9b0323895721ae
Author: Batuhan Taskaya <is...@gmail.com>
AuthorDate: Thu Sep 29 22:17:54 2022 +0300

    make regexp_replace early abort with empty input (#3648)
---
 datafusion/physical-expr/src/regex_expressions.rs | 25 ++++++++++++++++++++++-
 1 file changed, 24 insertions(+), 1 deletion(-)

diff --git a/datafusion/physical-expr/src/regex_expressions.rs b/datafusion/physical-expr/src/regex_expressions.rs
index 89805cade..6584b1356 100644
--- a/datafusion/physical-expr/src/regex_expressions.rs
+++ b/datafusion/physical-expr/src/regex_expressions.rs
@@ -35,10 +35,14 @@ use std::sync::Arc;
 
 use crate::functions::make_scalar_function;
 
+/// Get the first argument from the given string array.
+///
+/// Note: If the array is empty or the first argument is null,
+/// then calls the given early abort function.
 macro_rules! fetch_string_arg {
     ($ARG:expr, $NAME:expr, $T:ident, $EARLY_ABORT:ident) => {{
         let array = downcast_string_array_arg!($ARG, $NAME, $T);
-        if array.is_null(0) {
+        if array.len() == 0 || array.is_null(0) {
             return $EARLY_ABORT(array);
         } else {
             array.value(0)
@@ -202,6 +206,8 @@ fn _regexp_replace_early_abort<T: OffsetSizeTrait>(
 ) -> Result<ArrayRef> {
     // Mimicking the existing behavior of regexp_replace, if any of the scalar arguments
     // are actuall null, then the result will be an array of the same size but with nulls.
+    //
+    // Also acts like an early abort mechanism when the input array is empty.
     Ok(new_null_array(input_array.data_type(), input_array.len()))
 }
 
@@ -420,6 +426,23 @@ mod tests {
         assert_eq!(re.as_ref(), &expected);
     }
 
+    #[test]
+    fn test_static_pattern_regexp_replace_early_abort_when_empty() {
+        let values = StringArray::from(Vec::<Option<&str>>::new());
+        let patterns = StringArray::from(Vec::<Option<&str>>::new());
+        let replacements = StringArray::from(Vec::<Option<&str>>::new());
+        let expected = StringArray::from(Vec::<Option<&str>>::new());
+
+        let re = _regexp_replace_static_pattern_replace::<i32>(&[
+            Arc::new(values),
+            Arc::new(patterns),
+            Arc::new(replacements),
+        ])
+        .unwrap();
+
+        assert_eq!(re.as_ref(), &expected);
+    }
+
     #[test]
     fn test_static_pattern_regexp_replace_early_abort_flags() {
         let values = StringArray::from(vec!["abc"; 5]);