arashandishgar commented on code in PR #45577:
URL: https://github.com/apache/arrow/pull/45577#discussion_r1983817091
##########
cpp/src/arrow/compute/kernels/scalar_string_test.cc:
##########
@@ -1958,6 +1960,47 @@ TYPED_TEST(TestBaseBinaryKernels, ExtractRegex) {
R"([{"letter": "a", "digit": "1"}, {"letter": "b", "digit":
"3"}])",
&options);
}
+TYPED_TEST(TestBaseBinaryKernels, ExtractRegexSpan) {
+ ExtractRegexSpanOptions options{"(?P<letter>[ab])(?P<digit>\\d)"};
+ auto type_fixe_size_list = is_binary_like(this->type()->id()) ? int32() :
int64();
+ auto out_type = struct_({field("letter",
fixed_size_list(type_fixe_size_list, 2)),
+ field("digit", fixed_size_list(type_fixe_size_list,
2))});
+ this->CheckUnary("extract_regex_span", R"([])", out_type, R"([])", &options);
+ this->CheckUnary(
+ "extract_regex_span", R"(["a1", "b2", "c3", null])", out_type,
+ R"([{"letter":[0,1], "digit":[1,1]}, {"letter":[0,1], "digit":[1,1]},
null, null])",
+ &options);
+ this->CheckUnary(
+ "extract_regex_span", R"(["a1", "c3", null, "b2"])", out_type,
+ R"([{"letter":[0,1], "digit": [1,1]}, null, null, {"letter":[0,1],
"digit":[1,1]}])",
+ &options);
+ this->CheckUnary(
+ "extract_regex_span", R"(["a1", "b2"])", out_type,
+ R"([{"letter": [0,1], "digit": [1,1]}, {"letter": [0,1], "digit":
[1,1]}])",
+ &options);
+ this->CheckUnary(
+ "extract_regex_span", R"(["a1", "zb3z"])", out_type,
+ R"([{"letter": [0,1], "digit": [1,1]}, {"letter": [1,1], "digit":
[2,1]}])",
+ &options);
+}
+TYPED_TEST(TestBaseBinaryKernels, ExtractRegexSpanCaptureOption) {
+ ExtractRegexSpanOptions options{"(?P<foo>foo)?(?P<digit>\\d+)?"};
+ auto type_fixe_size_list = is_binary_like(this->type()->id()) ? int32() :
int64();
+ auto out_type = struct_({field("foo", fixed_size_list(type_fixe_size_list,
2)),
+ field("digit", fixed_size_list(type_fixe_size_list,
2))});
+ this->CheckUnary("extract_regex_span", R"([])", out_type, R"([])", &options);
+ this->CheckUnary("extract_regex_span", R"(["abcfoo"])", out_type,
+ R"([{"foo":null,"digit":null}])", &options);
+ options = ExtractRegexSpanOptions{"(?P<foo>foo)(?P<digit>\\d+)?"};
+ this->CheckUnary("extract_regex_span",
R"(["foo123","foo","123","abc","abcfoo"])",
+ out_type,
+ R"([{"foo":[0,3],"digit":[3,3]},
+ {"foo":[0,3],"digit":null},
+ null,
+ null,
+ {"foo":[3,3],"digit":null}])",
+ &options);
+}
Review Comment:
> Could you make the tests less trivial and use examples with
variable-length captures?
>
> For example have the regex be: `(?P<letter>[ab]+)(?P<digit>\\d+)`
>
> and then test with "abb12", "abc13", etc.
I write a separate test case for that. If it is not enough,let me inform to
write more test
--
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]