You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@arrow.apache.org by al...@apache.org on 2022/08/04 19:55:40 UTC

[arrow-datafusion] branch master updated: Use concat_elements_utf8 from arrow rather than custom kernel (#3036)

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

alamb 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 b2be7abd6 Use concat_elements_utf8 from arrow rather than custom kernel (#3036)
b2be7abd6 is described below

commit b2be7abd6fb4154f725cc4235318515f1183619a
Author: Andrew Lamb <an...@nerdnetworks.org>
AuthorDate: Thu Aug 4 15:55:36 2022 -0400

    Use concat_elements_utf8 from arrow rather than custom kernel (#3036)
---
 datafusion/physical-expr/src/expressions/binary.rs |  9 +++++----
 .../src/expressions/binary/kernels.rs              | 22 ----------------------
 2 files changed, 5 insertions(+), 26 deletions(-)

diff --git a/datafusion/physical-expr/src/expressions/binary.rs b/datafusion/physical-expr/src/expressions/binary.rs
index 004628a80..f199466e9 100644
--- a/datafusion/physical-expr/src/expressions/binary.rs
+++ b/datafusion/physical-expr/src/expressions/binary.rs
@@ -49,9 +49,8 @@ use arrow::compute::kernels::comparison::{
 };
 
 use adapter::{eq_dyn, gt_dyn, gt_eq_dyn, lt_dyn, lt_eq_dyn, neq_dyn};
-use kernels::{
-    bitwise_and, bitwise_and_scalar, bitwise_or, bitwise_or_scalar, string_concat,
-};
+use arrow::compute::kernels::concat_elements::concat_elements_utf8;
+use kernels::{bitwise_and, bitwise_and_scalar, bitwise_or, bitwise_or_scalar};
 use kernels_arrow::{
     add_decimal, add_decimal_scalar, divide_decimal, divide_decimal_scalar,
     eq_decimal_scalar, gt_decimal_scalar, gt_eq_decimal_scalar, is_distinct_from,
@@ -851,7 +850,9 @@ impl BinaryExpr {
             }
             Operator::BitwiseAnd => bitwise_and(left, right),
             Operator::BitwiseOr => bitwise_or(left, right),
-            Operator::StringConcat => string_concat(left, right),
+            Operator::StringConcat => {
+                binary_string_array_op!(left, right, concat_elements)
+            }
         }
     }
 }
diff --git a/datafusion/physical-expr/src/expressions/binary/kernels.rs b/datafusion/physical-expr/src/expressions/binary/kernels.rs
index e234815af..a89957447 100644
--- a/datafusion/physical-expr/src/expressions/binary/kernels.rs
+++ b/datafusion/physical-expr/src/expressions/binary/kernels.rs
@@ -167,25 +167,3 @@ pub(crate) fn bitwise_or_scalar(
     };
     Some(result)
 }
-
-/// Concat lhs and rhs String Array, any `NULL` exists on lhs or rhs will come out result `NULL`
-/// 1. 'a' || 'b' || 32 = 'ab32'
-/// 2. 'a' || NULL = NULL
-pub(crate) fn string_concat(left: ArrayRef, right: ArrayRef) -> Result<ArrayRef> {
-    let left_array = left.as_any().downcast_ref::<StringArray>().unwrap();
-    let right_array = right.as_any().downcast_ref::<StringArray>().unwrap();
-    let result = (0..left.len())
-        .into_iter()
-        .map(|i| {
-            if left.is_null(i) || right.is_null(i) {
-                None
-            } else {
-                let mut owned_string: String = "".to_owned();
-                owned_string.push_str(left_array.value(i));
-                owned_string.push_str(right_array.value(i));
-                Some(owned_string)
-            }
-        })
-        .collect::<StringArray>();
-    Ok(Arc::new(result) as ArrayRef)
-}