Skip to content

Commit

Permalink
ARROW-12670: [C++] Fix extract_regex output after non-matching values
Browse files Browse the repository at this point in the history
Closes #10287 from pitrou/ARROW-12670-extract-regex-nulls

Authored-by: Antoine Pitrou <antoine@python.org>
Signed-off-by: Benjamin Kietzman <bengilgit@gmail.com>
  • Loading branch information
pitrou authored and kszucs committed May 17, 2021
1 parent 6a2915e commit af476c6
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 7 deletions.
9 changes: 2 additions & 7 deletions cpp/src/arrow/compute/kernels/scalar_string.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1622,20 +1622,15 @@ 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++) {
RETURN_NOT_OK(field_builders[i]->Append(ToStringView(found_values[i])));
}
return struct_builder->Append();
} else {
return visit_null();
return struct_builder->AppendNull();
}
};
const ArrayData& input = *batch[0].array();
Expand Down
4 changes: 4 additions & 0 deletions cpp/src/arrow/compute/kernels/scalar_string_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit af476c6

Please sign in to comment.