pitrou commented on code in PR #50616:
URL: https://github.com/apache/arrow/pull/50616#discussion_r3655550514
##########
cpp/src/arrow/compute/kernels/scalar_string_ascii.cc:
##########
@@ -1500,27 +1495,59 @@ std::string MakeLikeRegex(const MatchSubstringOptions&
options) {
return like_pattern;
}
+struct MatchLikeConstants {
+ // NOTE: avoid making those constants global to avoid compiling regexes at
startup
+ RE2::Options regex_options;
+ // A LIKE pattern matching this regex can be translated into a substring
search.
+ RE2 like_pattern_is_substring_match;
+ // A LIKE pattern matching this regex can be translated into a prefix search.
+ RE2 like_pattern_is_starts_with;
+ // A LIKE pattern matching this regex can be translated into a suffix search.
+ RE2 like_pattern_is_ends_with;
+ Status init_status;
+
+ static Result<const MatchLikeConstants*> Instance(bool is_utf8) {
+ static const auto constants = MakeAll();
+ return constants[is_utf8].Map([](const auto& ptr) { return ptr.get(); });
+ }
+
+ private:
+ static Result<std::unique_ptr<MatchLikeConstants>> Make(bool is_utf8) {
+ auto constants = std::unique_ptr<MatchLikeConstants>(new
MatchLikeConstants(is_utf8));
+ if (constants->init_status.ok()) {
+ return constants;
+ } else {
+ return constants->init_status;
+ }
+ }
+
+ static std::array<Result<std::unique_ptr<MatchLikeConstants>>, 2> MakeAll() {
+ return {Make(false), Make(true)};
+ }
+
+ explicit MatchLikeConstants(bool is_utf8)
+ : regex_options(MakeRE2Options(is_utf8)),
+ like_pattern_is_substring_match(R"(%+([^%_]*[^\\%_])?%+)",
regex_options),
Review Comment:
Done.
##########
cpp/src/arrow/compute/kernels/scalar_string_ascii.cc:
##########
@@ -1500,27 +1495,59 @@ std::string MakeLikeRegex(const MatchSubstringOptions&
options) {
return like_pattern;
}
+struct MatchLikeConstants {
+ // NOTE: avoid making those constants global to avoid compiling regexes at
startup
+ RE2::Options regex_options;
+ // A LIKE pattern matching this regex can be translated into a substring
search.
+ RE2 like_pattern_is_substring_match;
+ // A LIKE pattern matching this regex can be translated into a prefix search.
+ RE2 like_pattern_is_starts_with;
+ // A LIKE pattern matching this regex can be translated into a suffix search.
+ RE2 like_pattern_is_ends_with;
+ Status init_status;
Review Comment:
Done.
--
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]