You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@arrow.apache.org by ks...@apache.org on 2021/05/17 11:37:16 UTC

[arrow] 10/13: ARROW-12670: [C++] Fix extract_regex output after non-matching values

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

kszucs pushed a commit to branch maint-4.0.x
in repository https://gitbox.apache.org/repos/asf/arrow.git

commit af476c6ebbe30855ad91439eb6ee6d77b3123ef6
Author: Antoine Pitrou <an...@python.org>
AuthorDate: Tue May 11 12:16:54 2021 -0400

    ARROW-12670: [C++] Fix extract_regex output after non-matching values
    
    Closes #10287 from pitrou/ARROW-12670-extract-regex-nulls
    
    Authored-by: Antoine Pitrou <an...@python.org>
    Signed-off-by: Benjamin Kietzman <be...@gmail.com>
---
 cpp/src/arrow/compute/kernels/scalar_string.cc      | 9 ++-------
 cpp/src/arrow/compute/kernels/scalar_string_test.cc | 4 ++++
 2 files changed, 6 insertions(+), 7 deletions(-)

diff --git a/cpp/src/arrow/compute/kernels/scalar_string.cc b/cpp/src/arrow/compute/kernels/scalar_string.cc
index d547374..82ae6fa 100644
--- a/cpp/src/arrow/compute/kernels/scalar_string.cc
+++ b/cpp/src/arrow/compute/kernels/scalar_string.cc
@@ -1622,12 +1622,7 @@ struct ExtractRegex : public ExtractRegexBase {
             checked_cast<BuilderType*>(struct_builder->field_builder(i)));
       }
 
-      auto visit_null = [&]() {
-        for (int i = 0; i < group_count; i++) {
-          RETURN_NOT_OK(field_builders[i]->AppendEmptyValue());
-        }
-        return struct_builder->AppendNull();
-      };
+      auto visit_null = [&]() { return struct_builder->AppendNull(); };
       auto visit_value = [&](util::string_view s) {
         if (Match(s)) {
           for (int i = 0; i < group_count; i++) {
@@ -1635,7 +1630,7 @@ struct ExtractRegex : public ExtractRegexBase {
           }
           return struct_builder->Append();
         } else {
-          return visit_null();
+          return struct_builder->AppendNull();
         }
       };
       const ArrayData& input = *batch[0].array();
diff --git a/cpp/src/arrow/compute/kernels/scalar_string_test.cc b/cpp/src/arrow/compute/kernels/scalar_string_test.cc
index 5774939..cb74b14 100644
--- a/cpp/src/arrow/compute/kernels/scalar_string_test.cc
+++ b/cpp/src/arrow/compute/kernels/scalar_string_test.cc
@@ -539,6 +539,10 @@ TYPED_TEST(TestStringKernels, ExtractRegex) {
       "extract_regex", R"(["a1", "b2", "c3", null])", type,
       R"([{"letter": "a", "digit": "1"}, {"letter": "b", "digit": "2"}, null, null])",
       &options);
+  this->CheckUnary(
+      "extract_regex", R"(["a1", "c3", null, "b2"])", type,
+      R"([{"letter": "a", "digit": "1"}, null, null, {"letter": "b", "digit": "2"}])",
+      &options);
   this->CheckUnary("extract_regex", R"(["a1", "b2"])", type,
                    R"([{"letter": "a", "digit": "1"}, {"letter": "b", "digit": "2"}])",
                    &options);