You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@arrow.apache.org by GitBox <gi...@apache.org> on 2023/01/20 14:15:13 UTC
[GitHub] [arrow] js8544 opened a new pull request, #33806: GH-33723: [C++] re2::RE2::RE2() result must be checked
js8544 opened a new pull request, #33806:
URL: https://github.com/apache/arrow/pull/33806
<!--
Thanks for opening a pull request!
If this is your first pull request you can find detailed information on how
to contribute here:
* [New Contributor's Guide](https://arrow.apache.org/docs/dev/developers/guide/step_by_step/pr_lifecycle.html#reviews-and-merge-of-the-pull-request)
* [Contributing Overview](https://arrow.apache.org/docs/dev/developers/overview.html)
If this is not a [minor PR](https://github.com/apache/arrow/blob/master/CONTRIBUTING.md#Minor-Fixes). Could you open an issue for this pull request on GitHub? https://github.com/apache/arrow/issues/new/choose
Opening GitHub issues ahead of time contributes to the [Openness](http://theapacheway.com/open/#:~:text=Openness%20allows%20new%20users%20the,must%20happen%20in%20the%20open.) of the Apache Arrow project.
Then could you also rename the pull request title in the following format?
GH-${GITHUB_ISSUE_ID}: [${COMPONENT}] ${SUMMARY}
or
MINOR: [${COMPONENT}] ${SUMMARY}
In the case of PARQUET issues on JIRA the title also supports:
PARQUET-${JIRA_ISSUE_ID}: [${COMPONENT}] ${SUMMARY}
-->
### Rationale for this change
<!--
Why are you proposing this change? If this is already explained clearly in the issue then this section is not needed.
Explaining clearly why changes are proposed helps reviewers understand your changes and offer better suggestions for fixes.
-->
RE2 construction needs to be checked.
### What changes are included in this PR?
<!--
There is no need to duplicate the description in the issue here but it is sometimes worth providing a summary of the individual changes in this PR.
-->
Check all RE2 object status.
### Are these changes tested?
<!--
We typically require tests for all PRs in order to:
1. Prevent the code from being accidentally broken by subsequent changes
2. Serve as another way to document the expected behavior of the code
If tests are not included in your PR, please explain why (for example, are they covered by existing tests)?
-->
Tested with existing tests.
### Are there any user-facing changes?
<!--
If there are user-facing changes then we may require documentation to be updated before approving the PR.
-->
<!--
If there are any breaking changes to public APIs, please add the `breaking-change` label.
-->
No.
--
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: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [arrow] js8544 commented on a diff in pull request #33806: GH-33723: [C++] re2::RE2::RE2() result must be checked
Posted by GitBox <gi...@apache.org>.
js8544 commented on code in PR #33806:
URL: https://github.com/apache/arrow/pull/33806#discussion_r1082609589
##########
cpp/src/arrow/compute/kernels/scalar_string_ascii.cc:
##########
@@ -1505,6 +1508,13 @@ struct MatchLike {
static const RE2 kLikePatternIsStartsWith(R"(([^%_]*[^\\%_])?%+)", kRE2Options);
// A LIKE pattern matching this regex can be translated into a suffix search.
static const RE2 kLikePatternIsEndsWith(R"(%+([^%_]*))", kRE2Options);
+ static bool global_checked = false;
+ if (ARROW_PREDICT_FALSE(!global_checked)) {
+ RETURN_NOT_OK(RegexStatus(kLikePatternIsSubstringMatch));
+ RETURN_NOT_OK(RegexStatus(kLikePatternIsStartsWith));
+ RETURN_NOT_OK(RegexStatus(kLikePatternIsEndsWith));
+ global_checked = true;
+ }
Review Comment:
Are there better ways to check global RE2 objects?
##########
cpp/src/gandiva/regex_functions_holder.cc:
##########
@@ -34,27 +31,44 @@ std::string& RemovePatternEscapeChars(const FunctionNode& node, std::string& pat
// Short-circuit pattern matches for the following common sub cases :
// - starts_with, ends_with and is_substr
const FunctionNode LikeHolder::TryOptimize(const FunctionNode& node) {
+ // NOTE: avoid making those constants global to avoid compiling regexes at startup
+ // pre-compiled pattern for matching starts_with
+ static const RE2 starts_with_regex(R"(([^\.\*])*\.\*)");
+ // pre-compiled pattern for matching ends_with
+ static const RE2 ends_with_regex(R"(\.\*([^\.\*])*)");
+ // pre-compiled pattern for matching is_substr
+ static const RE2 is_substr_regex(R"(\.\*([^\.\*])*\.\*)");
+
+ static bool global_checked = false;
+ if (ARROW_PREDICT_FALSE(!global_checked)) {
+ if (ARROW_PREDICT_FALSE(
+ !(starts_with_regex.ok() && ends_with_regex.ok() && is_substr_regex.ok()))) {
+ return node;
+ }
+ global_checked = true;
+ }
Review Comment:
Are there better ways to check global RE2 objects?
--
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: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [arrow] westonpace commented on a diff in pull request #33806: GH-33723: [C++] re2::RE2::RE2() result must be checked
Posted by "westonpace (via GitHub)" <gi...@apache.org>.
westonpace commented on code in PR #33806:
URL: https://github.com/apache/arrow/pull/33806#discussion_r1083390389
##########
cpp/src/arrow/compute/kernels/scalar_string_test.cc:
##########
@@ -19,6 +19,7 @@
#include <string>
#include <utility>
#include <vector>
+#include "arrow/compute/exec.h"
Review Comment:
Can you keep the includes grouped together?
##########
cpp/src/gandiva/regex_functions_holder.cc:
##########
@@ -17,15 +17,12 @@
#include "gandiva/regex_functions_holder.h"
#include <regex>
+#include "arrow/util/macros.h"
Review Comment:
I am not very familiar with the gandiva code base. Is it ok/normal to use Arrow macros here? I assume so.
--
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: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [arrow] js8544 commented on a diff in pull request #33806: GH-33723: [C++] re2::RE2::RE2() result must be checked
Posted by "js8544 (via GitHub)" <gi...@apache.org>.
js8544 commented on code in PR #33806:
URL: https://github.com/apache/arrow/pull/33806#discussion_r1083265094
##########
cpp/src/arrow/compute/kernels/scalar_string_ascii.cc:
##########
@@ -1505,6 +1508,13 @@ struct MatchLike {
static const RE2 kLikePatternIsStartsWith(R"(([^%_]*[^\\%_])?%+)", kRE2Options);
// A LIKE pattern matching this regex can be translated into a suffix search.
static const RE2 kLikePatternIsEndsWith(R"(%+([^%_]*))", kRE2Options);
+ static bool global_checked = false;
+ if (ARROW_PREDICT_FALSE(!global_checked)) {
+ RETURN_NOT_OK(RegexStatus(kLikePatternIsSubstringMatch));
+ RETURN_NOT_OK(RegexStatus(kLikePatternIsStartsWith));
+ RETURN_NOT_OK(RegexStatus(kLikePatternIsEndsWith));
Review Comment:
I think it does though. `global_checked` is set to true only if all three patterns are ok.
##########
cpp/src/arrow/compute/kernels/scalar_string_ascii.cc:
##########
@@ -1505,6 +1508,13 @@ struct MatchLike {
static const RE2 kLikePatternIsStartsWith(R"(([^%_]*[^\\%_])?%+)", kRE2Options);
// A LIKE pattern matching this regex can be translated into a suffix search.
static const RE2 kLikePatternIsEndsWith(R"(%+([^%_]*))", kRE2Options);
+ static bool global_checked = false;
Review Comment:
I also feel like a static boolean is enough for our case. As it avoids false positives, i.e., erroneous regexes are always checked.
##########
cpp/src/arrow/compute/kernels/scalar_string_ascii.cc:
##########
@@ -1505,6 +1508,13 @@ struct MatchLike {
static const RE2 kLikePatternIsStartsWith(R"(([^%_]*[^\\%_])?%+)", kRE2Options);
// A LIKE pattern matching this regex can be translated into a suffix search.
static const RE2 kLikePatternIsEndsWith(R"(%+([^%_]*))", kRE2Options);
+ static bool global_checked = false;
Review Comment:
I thought about using `std::call_once` but the only solution I can come up with uses exceptions:
```cpp
static std::once_flag global_checked;
try {
std::call_once(global_checked, [] {
auto check_global = [] {
RETURN_NOT_OK(RegexStatus(kLikePatternIsSubstringMatch));
RETURN_NOT_OK(RegexStatus(kLikePatternIsStartsWith));
RETURN_NOT_OK(RegexStatus(kLikePatternIsEndsWith));
};
auto status = check_global();
if (!status.ok()) { // throw an exception so that once_flag is not set
throw std::invalid_argument(status.ToString());
}
});
} catch (const std::invalid_argument& e) {
return Status::Invalid(e.what());
}
```
I couldn't find a more elegant solution. WDYT?
--
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: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [arrow] github-actions[bot] commented on pull request #33806: GH-33723: [C++] re2::RE2::RE2() result must be checked
Posted by GitBox <gi...@apache.org>.
github-actions[bot] commented on PR #33806:
URL: https://github.com/apache/arrow/pull/33806#issuecomment-1398454575
* Closes: #33723
--
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: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [arrow] kou commented on a diff in pull request #33806: GH-33723: [C++] re2::RE2::RE2() result must be checked
Posted by "kou (via GitHub)" <gi...@apache.org>.
kou commented on code in PR #33806:
URL: https://github.com/apache/arrow/pull/33806#discussion_r1083228638
##########
cpp/src/arrow/compute/kernels/scalar_string_ascii.cc:
##########
@@ -1505,6 +1508,13 @@ struct MatchLike {
static const RE2 kLikePatternIsStartsWith(R"(([^%_]*[^\\%_])?%+)", kRE2Options);
// A LIKE pattern matching this regex can be translated into a suffix search.
static const RE2 kLikePatternIsEndsWith(R"(%+([^%_]*))", kRE2Options);
+ static bool global_checked = false;
Review Comment:
Can we use `std::once_flag`?
##########
cpp/src/arrow/compute/kernels/scalar_string_ascii.cc:
##########
@@ -1505,6 +1508,13 @@ struct MatchLike {
static const RE2 kLikePatternIsStartsWith(R"(([^%_]*[^\\%_])?%+)", kRE2Options);
// A LIKE pattern matching this regex can be translated into a suffix search.
static const RE2 kLikePatternIsEndsWith(R"(%+([^%_]*))", kRE2Options);
+ static bool global_checked = false;
+ if (ARROW_PREDICT_FALSE(!global_checked)) {
+ RETURN_NOT_OK(RegexStatus(kLikePatternIsSubstringMatch));
+ RETURN_NOT_OK(RegexStatus(kLikePatternIsStartsWith));
+ RETURN_NOT_OK(RegexStatus(kLikePatternIsEndsWith));
Review Comment:
If we have an error in these patterns, does this code report an error on the second call? (It seems that this code reports an error only on the first call.)
--
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: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [arrow] kou commented on a diff in pull request #33806: GH-33723: [C++] re2::RE2::RE2() result must be checked
Posted by "kou (via GitHub)" <gi...@apache.org>.
kou commented on code in PR #33806:
URL: https://github.com/apache/arrow/pull/33806#discussion_r1083334566
##########
cpp/src/arrow/compute/kernels/scalar_string_ascii.cc:
##########
@@ -1505,6 +1508,13 @@ struct MatchLike {
static const RE2 kLikePatternIsStartsWith(R"(([^%_]*[^\\%_])?%+)", kRE2Options);
// A LIKE pattern matching this regex can be translated into a suffix search.
static const RE2 kLikePatternIsEndsWith(R"(%+([^%_]*))", kRE2Options);
+ static bool global_checked = false;
+ if (ARROW_PREDICT_FALSE(!global_checked)) {
+ RETURN_NOT_OK(RegexStatus(kLikePatternIsSubstringMatch));
+ RETURN_NOT_OK(RegexStatus(kLikePatternIsStartsWith));
+ RETURN_NOT_OK(RegexStatus(kLikePatternIsEndsWith));
Review Comment:
I see. Thanks.
##########
cpp/src/arrow/compute/kernels/scalar_string_ascii.cc:
##########
@@ -1505,6 +1508,13 @@ struct MatchLike {
static const RE2 kLikePatternIsStartsWith(R"(([^%_]*[^\\%_])?%+)", kRE2Options);
// A LIKE pattern matching this regex can be translated into a suffix search.
static const RE2 kLikePatternIsEndsWith(R"(%+([^%_]*))", kRE2Options);
+ static bool global_checked = false;
Review Comment:
Ah, I see. `std::call_once` isn't suitable here.
--
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: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [arrow] westonpace commented on a diff in pull request #33806: GH-33723: [C++] re2::RE2::RE2() result must be checked
Posted by "westonpace (via GitHub)" <gi...@apache.org>.
westonpace commented on code in PR #33806:
URL: https://github.com/apache/arrow/pull/33806#discussion_r1083298939
##########
cpp/src/arrow/compute/kernels/scalar_string_ascii.cc:
##########
@@ -1505,6 +1508,13 @@ struct MatchLike {
static const RE2 kLikePatternIsStartsWith(R"(([^%_]*[^\\%_])?%+)", kRE2Options);
// A LIKE pattern matching this regex can be translated into a suffix search.
static const RE2 kLikePatternIsEndsWith(R"(%+([^%_]*))", kRE2Options);
+ static bool global_checked = false;
Review Comment:
Given that these are constants it seems pretty unlikely that they would fail. You could probably just DCHECK_OK or abort if they fail. That being said, I agree this is probably a fine solution as well. You could also do something like...
```
template <typename StringType>
struct LikePatterns {
RE2::Options kRE2Options = ...
RE2 kLikePatternIsSubstringMatch(...);
RE2 kLikePatternIsStartsWith(...);
RE2 kLikePatternIsEndsWith(...);
static Result<LikePatterns> Make() {
RETURN_NOT_OK(...)
}
};
template <typename StringType>
struct MatchLike {
static Status Exec(KernelContext* ctx, const ExecSpan& batch, ExecResult* out) {
static const Result<LikePatterns> kLikePatterns = LikePatterns::Make();
RETURN_NOT_OK(kLikePatterns);
...
```
--
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: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [arrow] js8544 commented on a diff in pull request #33806: GH-33723: [C++] re2::RE2::RE2() result must be checked
Posted by "js8544 (via GitHub)" <gi...@apache.org>.
js8544 commented on code in PR #33806:
URL: https://github.com/apache/arrow/pull/33806#discussion_r1083394402
##########
cpp/src/arrow/compute/kernels/scalar_string_test.cc:
##########
@@ -19,6 +19,7 @@
#include <string>
#include <utility>
#include <vector>
+#include "arrow/compute/exec.h"
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: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [arrow] js8544 commented on a diff in pull request #33806: GH-33723: [C++] re2::RE2::RE2() result must be checked
Posted by "js8544 (via GitHub)" <gi...@apache.org>.
js8544 commented on code in PR #33806:
URL: https://github.com/apache/arrow/pull/33806#discussion_r1083394498
##########
cpp/src/gandiva/regex_functions_holder.cc:
##########
@@ -17,15 +17,12 @@
#include "gandiva/regex_functions_holder.h"
#include <regex>
+#include "arrow/util/macros.h"
Review Comment:
Yep. Gandiva uses various headers from the arrow/util directory.
--
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: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [arrow] js8544 commented on pull request #33806: GH-33723: [C++] re2::RE2::RE2() result must be checked
Posted by GitBox <gi...@apache.org>.
js8544 commented on PR #33806:
URL: https://github.com/apache/arrow/pull/33806#issuecomment-1398468161
cc @kou
--
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: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [arrow] js8544 commented on pull request #33806: GH-33723: [C++] re2::RE2::RE2() result must be checked
Posted by "js8544 (via GitHub)" <gi...@apache.org>.
js8544 commented on PR #33806:
URL: https://github.com/apache/arrow/pull/33806#issuecomment-1399245413
> Could you also add tests for error pattern cases?
Added a TestBaseBinaryKernels: FindSubstringRegexWrongPattern 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: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [arrow] kou merged pull request #33806: GH-33723: [C++] re2::RE2::RE2() result must be checked
Posted by "kou (via GitHub)" <gi...@apache.org>.
kou merged PR #33806:
URL: https://github.com/apache/arrow/pull/33806
--
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: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [arrow] js8544 commented on a diff in pull request #33806: GH-33723: [C++] re2::RE2::RE2() result must be checked
Posted by "js8544 (via GitHub)" <gi...@apache.org>.
js8544 commented on code in PR #33806:
URL: https://github.com/apache/arrow/pull/33806#discussion_r1083394498
##########
cpp/src/gandiva/regex_functions_holder.cc:
##########
@@ -17,15 +17,12 @@
#include "gandiva/regex_functions_holder.h"
#include <regex>
+#include "arrow/util/macros.h"
Review Comment:
Yep. Gandiva uses various headers in the arrow/util directory.
--
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: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [arrow] ursabot commented on pull request #33806: GH-33723: [C++] re2::RE2::RE2() result must be checked
Posted by "ursabot (via GitHub)" <gi...@apache.org>.
ursabot commented on PR #33806:
URL: https://github.com/apache/arrow/pull/33806#issuecomment-1399435957
Benchmark runs are scheduled for baseline = 63967ac00dbf788a2309a70f949e13f3d3e93f24 and contender = cb0f0178dacd922f355255a16c85820fb4e390c8. cb0f0178dacd922f355255a16c85820fb4e390c8 is a master commit associated with this PR. Results will be available as each benchmark for each run completes.
Conbench compare runs links:
[Failed] [ec2-t3-xlarge-us-east-2](https://conbench.ursa.dev/compare/runs/3b09faa4c9f942b78859575deeeb64c9...41303748427d42e292d09d8addb6b3f6/)
[Failed] [test-mac-arm](https://conbench.ursa.dev/compare/runs/858374060f774c598fb08fa1243b239b...bb774d28590c4afb824829ecb8f1067e/)
[Failed] [ursa-i9-9960x](https://conbench.ursa.dev/compare/runs/cd4f5a6fbb95455588fc754191622d90...d661ad3fc1464abc9840dea0492596d3/)
[Failed] [ursa-thinkcentre-m75q](https://conbench.ursa.dev/compare/runs/ad7d0c5b5e0c46edb70b15873c074e1e...9ef29354d0b342a28b6c9330e26eb054/)
Buildkite builds:
[Failed] [`cb0f0178` ec2-t3-xlarge-us-east-2](https://buildkite.com/apache-arrow/arrow-bci-benchmark-on-ec2-t3-xlarge-us-east-2/builds/2245)
[Failed] [`cb0f0178` test-mac-arm](https://buildkite.com/apache-arrow/arrow-bci-benchmark-on-test-mac-arm/builds/2270)
[Failed] [`cb0f0178` ursa-i9-9960x](https://buildkite.com/apache-arrow/arrow-bci-benchmark-on-ursa-i9-9960x/builds/2240)
[Failed] [`cb0f0178` ursa-thinkcentre-m75q](https://buildkite.com/apache-arrow/arrow-bci-benchmark-on-ursa-thinkcentre-m75q/builds/2263)
[Failed] [`63967ac0` ec2-t3-xlarge-us-east-2](https://buildkite.com/apache-arrow/arrow-bci-benchmark-on-ec2-t3-xlarge-us-east-2/builds/2244)
[Failed] [`63967ac0` test-mac-arm](https://buildkite.com/apache-arrow/arrow-bci-benchmark-on-test-mac-arm/builds/2269)
[Failed] [`63967ac0` ursa-i9-9960x](https://buildkite.com/apache-arrow/arrow-bci-benchmark-on-ursa-i9-9960x/builds/2239)
[Failed] [`63967ac0` ursa-thinkcentre-m75q](https://buildkite.com/apache-arrow/arrow-bci-benchmark-on-ursa-thinkcentre-m75q/builds/2262)
Supported benchmarks:
ec2-t3-xlarge-us-east-2: Supported benchmark langs: Python, R. Runs only benchmarks with cloud = True
test-mac-arm: Supported benchmark langs: C++, Python, R
ursa-i9-9960x: Supported benchmark langs: Python, R, JavaScript
ursa-thinkcentre-m75q: Supported benchmark langs: C++, Java
--
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: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org