You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@arrow.apache.org by "zanmato1984 (via GitHub)" <gi...@apache.org> on 2024/04/22 07:12:27 UTC
[PR] GH-41329: [C++][Gandiva] Fix gandiva cache size env var [arrow]
zanmato1984 opened a new pull request, #41330:
URL: https://github.com/apache/arrow/pull/41330
<!--
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/main/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
See #41329.
<!--
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.
-->
### What changes are included in this PR?
1. Fix checking gandiva cache size env var.
2. Make cache size static so it only gets evaluated once.
3. Add test cases.
4. Enrich the description in the document about this env var.
<!--
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.
-->
### Are these changes tested?
UT included.
<!--
We typically require tests for all PRs in order to:
1. Prevent the code from being accidentally broken by subsequent changes
5. 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)?
-->
### Are there any user-facing changes?
None.
<!--
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 uncomment the line below and explain which changes are breaking.
-->
<!-- **This PR includes breaking changes to public APIs.** -->
<!--
Please uncomment the line below (and provide explanation) if the changes fix either (a) a security vulnerability, (b) a bug that caused incorrect or invalid data to be produced, or (c) a bug that causes a crash (even when the API contract is upheld). We use this to highlight fixes to issues that may affect users without their knowledge. For this reason, fixing bugs that cause errors don't count, since those are usually obvious.
-->
<!-- **This PR contains a "Critical Fix".** -->
--
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
Re: [PR] GH-41329: [C++][Gandiva] Fix gandiva cache size env var [arrow]
Posted by "conbench-apache-arrow[bot] (via GitHub)" <gi...@apache.org>.
conbench-apache-arrow[bot] commented on PR #41330:
URL: https://github.com/apache/arrow/pull/41330#issuecomment-2110774891
After merging your PR, Conbench analyzed the 7 benchmarking runs that have been run so far on merge-commit e6ab174e20137d62b33e4373f5fbd3c435948036.
There were no benchmark performance regressions. 🎉
The [full Conbench report](https://github.com/apache/arrow/runs/24963036224) has more details. It also includes information about 11 possible false positives for unstable benchmarks that are known to sometimes produce them.
--
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
Re: [PR] GH-41329: [C++][Gandiva] Fix gandiva cache size env var [arrow]
Posted by "zanmato1984 (via GitHub)" <gi...@apache.org>.
zanmato1984 commented on code in PR #41330:
URL: https://github.com/apache/arrow/pull/41330#discussion_r1574529527
##########
cpp/src/gandiva/cache.cc:
##########
@@ -23,23 +23,38 @@
namespace gandiva {
-static const size_t DEFAULT_CACHE_SIZE = 5000;
+static const int DEFAULT_CACHE_SIZE = 5000;
-int GetCapacity() {
- size_t capacity = DEFAULT_CACHE_SIZE;
- auto maybe_env_cache_size = ::arrow::internal::GetEnvVar("GANDIVA_CACHE_SIZE");
- if (maybe_env_cache_size.ok()) {
- const auto env_cache_size = *std::move(maybe_env_cache_size);
- if (!env_cache_size.empty()) {
- capacity = std::atol(env_cache_size.c_str());
- if (capacity <= 0) {
- ARROW_LOG(WARNING) << "Invalid cache size provided in GANDIVA_CACHE_SIZE. "
- << "Using default cache size: " << DEFAULT_CACHE_SIZE;
- capacity = DEFAULT_CACHE_SIZE;
- }
- }
+namespace internal {
+int GetCapacityFromEnvVar() {
+ auto maybe_env_value = ::arrow::internal::GetEnvVar("GANDIVA_CACHE_SIZE");
+ if (!maybe_env_value.ok()) {
+ return DEFAULT_CACHE_SIZE;
+ }
+ const auto env_value = *std::move(maybe_env_value);
+ if (env_value.empty()) {
+ return DEFAULT_CACHE_SIZE;
+ }
+ int capacity = 0;
+ size_t length = 0;
+ bool exception = false;
+ try {
+ capacity = std::stoi(env_value.c_str(), &length);
Review Comment:
C++ standard says that the result is undefined for `std::atol` to parse an value out of the containing type's range. So replace it with `std::stoi` which has a defined behavior in such circumstances (throwing `std::out_of_range`).
--
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
Re: [PR] GH-41329: [C++][Gandiva] Fix gandiva cache size env var [arrow]
Posted by "zanmato1984 (via GitHub)" <gi...@apache.org>.
zanmato1984 commented on code in PR #41330:
URL: https://github.com/apache/arrow/pull/41330#discussion_r1574529527
##########
cpp/src/gandiva/cache.cc:
##########
@@ -23,23 +23,38 @@
namespace gandiva {
-static const size_t DEFAULT_CACHE_SIZE = 5000;
+static const int DEFAULT_CACHE_SIZE = 5000;
-int GetCapacity() {
- size_t capacity = DEFAULT_CACHE_SIZE;
- auto maybe_env_cache_size = ::arrow::internal::GetEnvVar("GANDIVA_CACHE_SIZE");
- if (maybe_env_cache_size.ok()) {
- const auto env_cache_size = *std::move(maybe_env_cache_size);
- if (!env_cache_size.empty()) {
- capacity = std::atol(env_cache_size.c_str());
- if (capacity <= 0) {
- ARROW_LOG(WARNING) << "Invalid cache size provided in GANDIVA_CACHE_SIZE. "
- << "Using default cache size: " << DEFAULT_CACHE_SIZE;
- capacity = DEFAULT_CACHE_SIZE;
- }
- }
+namespace internal {
+int GetCapacityFromEnvVar() {
+ auto maybe_env_value = ::arrow::internal::GetEnvVar("GANDIVA_CACHE_SIZE");
+ if (!maybe_env_value.ok()) {
+ return DEFAULT_CACHE_SIZE;
+ }
+ const auto env_value = *std::move(maybe_env_value);
+ if (env_value.empty()) {
+ return DEFAULT_CACHE_SIZE;
+ }
+ int capacity = 0;
+ size_t length = 0;
+ bool exception = false;
+ try {
+ capacity = std::stoi(env_value.c_str(), &length);
Review Comment:
C++ standard says that the result is undefined for `std::atol` to parse a value out of the containing type's range. So replace it with `std::stoi` which has a defined behavior in such circumstances (throwing `std::out_of_range`).
--
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
Re: [PR] GH-41329: [C++][Gandiva] Fix gandiva cache size env var [arrow]
Posted by "pitrou (via GitHub)" <gi...@apache.org>.
pitrou commented on code in PR #41330:
URL: https://github.com/apache/arrow/pull/41330#discussion_r1587900890
##########
cpp/src/gandiva/cache.cc:
##########
@@ -20,26 +20,41 @@
#include "arrow/result.h"
#include "arrow/util/io_util.h"
#include "arrow/util/logging.h"
+#include "arrow/util/value_parsing.h"
namespace gandiva {
-static const size_t DEFAULT_CACHE_SIZE = 5000;
-
-int GetCapacity() {
- size_t capacity = DEFAULT_CACHE_SIZE;
- auto maybe_env_cache_size = ::arrow::internal::GetEnvVar("GANDIVA_CACHE_SIZE");
- if (maybe_env_cache_size.ok()) {
- const auto env_cache_size = *std::move(maybe_env_cache_size);
- if (!env_cache_size.empty()) {
- capacity = std::atol(env_cache_size.c_str());
- if (capacity <= 0) {
- ARROW_LOG(WARNING) << "Invalid cache size provided in GANDIVA_CACHE_SIZE. "
- << "Using default cache size: " << DEFAULT_CACHE_SIZE;
- capacity = DEFAULT_CACHE_SIZE;
- }
- }
+constexpr auto kCacheCapacityEnvVar = "GANDIVA_CACHE_SIZE";
+constexpr auto kDefaultCacheSize = 5000;
+
+namespace internal {
+int GetCacheCapacityFromEnvVar() {
+ auto maybe_env_value = ::arrow::internal::GetEnvVar(kCacheCapacityEnvVar);
+ if (!maybe_env_value.ok()) {
+ return kDefaultCacheSize;
+ }
+ const auto env_value = *std::move(maybe_env_value);
+ if (env_value.empty()) {
+ return kDefaultCacheSize;
+ }
+ int capacity = 0;
+ bool ok = ::arrow::internal::ParseValue<::arrow::Int32Type>(
+ env_value.c_str(), env_value.size(), &capacity);
+ if (!ok || capacity <= 0) {
+ ARROW_LOG(WARNING) << "Invalid cache size provided in " << kCacheCapacityEnvVar
+ << "Using default cache size: " << kDefaultCacheSize;
Review Comment:
Nit: add spacing/punctuation
```suggestion
ARROW_LOG(WARNING) << "Invalid cache size provided in " << kCacheCapacityEnvVar
<< ". Using default cache size: " << kDefaultCacheSize;
```
--
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
Re: [PR] GH-41329: [C++][Gandiva] Fix gandiva cache size env var [arrow]
Posted by "zanmato1984 (via GitHub)" <gi...@apache.org>.
zanmato1984 commented on PR #41330:
URL: https://github.com/apache/arrow/pull/41330#issuecomment-2068650385
cc @pitrou
--
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
Re: [PR] GH-41329: [C++][Gandiva] Fix gandiva cache size env var [arrow]
Posted by "zanmato1984 (via GitHub)" <gi...@apache.org>.
zanmato1984 commented on code in PR #41330:
URL: https://github.com/apache/arrow/pull/41330#discussion_r1574249283
##########
cpp/src/gandiva/cache.h:
##########
@@ -25,6 +25,13 @@
namespace gandiva {
+namespace internal {
+// Only called once by GetCapacity().
+// Do the actual work of getting the capacity from env var.
+// Also makes the testing easier.
Review Comment:
It is not possible in google test to re-initialize a static variable. So have this dedicated function to do the actual work eagerly, then we can test it instead of `GetCapacity` (which contains the static variable).
--
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
Re: [PR] GH-41329: [C++][Gandiva] Fix gandiva cache size env var [arrow]
Posted by "zanmato1984 (via GitHub)" <gi...@apache.org>.
zanmato1984 commented on code in PR #41330:
URL: https://github.com/apache/arrow/pull/41330#discussion_r1587852667
##########
cpp/src/gandiva/cache.h:
##########
@@ -25,6 +25,14 @@
namespace gandiva {
+namespace internal {
+// Only called once by GetCapacity().
+// Do the actual work of getting the capacity from env var.
+// Also makes the testing easier.
+GANDIVA_EXPORT
+int GetCapacityFromEnvVar();
+} // namespace internal
+
GANDIVA_EXPORT
int GetCapacity();
Review Comment:
Yes, it can. But is this public API?
--
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
Re: [PR] GH-41329: [C++][Gandiva] Fix gandiva cache size env var [arrow]
Posted by "pitrou (via GitHub)" <gi...@apache.org>.
pitrou commented on PR #41330:
URL: https://github.com/apache/arrow/pull/41330#issuecomment-2110052962
Sorry for forgetting about this PR. I've rebased and will merge if CI is green.
--
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
Re: [PR] GH-41329: [C++][Gandiva] Fix gandiva cache size env var [arrow]
Posted by "zanmato1984 (via GitHub)" <gi...@apache.org>.
zanmato1984 commented on PR #41330:
URL: https://github.com/apache/arrow/pull/41330#issuecomment-2108590249
Shall we move on with this? @pitrou
--
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
Re: [PR] GH-41329: [C++][Gandiva] Fix gandiva cache size env var [arrow]
Posted by "zanmato1984 (via GitHub)" <gi...@apache.org>.
zanmato1984 commented on code in PR #41330:
URL: https://github.com/apache/arrow/pull/41330#discussion_r1587853471
##########
cpp/src/gandiva/cache_test.cc:
##########
@@ -38,5 +42,77 @@ TEST(TestCache, TestGetPut) {
ASSERT_EQ(cache.GetObjectCode(TestCacheKey(2)), "world");
}
-TEST(TestCache, TestGetCacheCapacity) { ASSERT_EQ(GetCapacity(), 5000); }
+namespace {
+constexpr auto capacity_env_var = "GANDIVA_CACHE_SIZE";
+constexpr auto default_capacity = 5000;
+} // namespace
+
+TEST(TestCache, TestGetCacheCapacityDefault) {
+ ASSERT_EQ(GetCapacity(), default_capacity);
+}
+
+TEST(TestCache, TestGetCacheCapacityEnvVar) {
+ // Uncleared env var may have side-effect to subsequent tests. Use a structure to help
+ // clearing the env var when leaving the scope.
+ struct ScopedEnvVar {
Review Comment:
Ah, that's great to know. Will do. Thank you!
--
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
Re: [PR] GH-41329: [C++][Gandiva] Fix gandiva cache size env var [arrow]
Posted by "zanmato1984 (via GitHub)" <gi...@apache.org>.
zanmato1984 commented on code in PR #41330:
URL: https://github.com/apache/arrow/pull/41330#discussion_r1587890798
##########
cpp/src/gandiva/cache.h:
##########
@@ -25,6 +25,14 @@
namespace gandiva {
+namespace internal {
+// Only called once by GetCapacity().
+// Do the actual work of getting the capacity from env var.
+// Also makes the testing easier.
+GANDIVA_EXPORT
+int GetCapacityFromEnvVar();
+} // namespace internal
+
GANDIVA_EXPORT
int GetCapacity();
Review Comment:
Addressed with deprecating old API and adding renamed one.
--
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
Re: [PR] GH-41329: [C++][Gandiva] Fix gandiva cache size env var [arrow]
Posted by "pitrou (via GitHub)" <gi...@apache.org>.
pitrou merged PR #41330:
URL: https://github.com/apache/arrow/pull/41330
--
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
Re: [PR] GH-41329: [C++][Gandiva] Fix gandiva cache size env var [arrow]
Posted by "pitrou (via GitHub)" <gi...@apache.org>.
pitrou commented on code in PR #41330:
URL: https://github.com/apache/arrow/pull/41330#discussion_r1587792048
##########
cpp/src/gandiva/cache_test.cc:
##########
@@ -38,5 +42,77 @@ TEST(TestCache, TestGetPut) {
ASSERT_EQ(cache.GetObjectCode(TestCacheKey(2)), "world");
}
-TEST(TestCache, TestGetCacheCapacity) { ASSERT_EQ(GetCapacity(), 5000); }
+namespace {
+constexpr auto capacity_env_var = "GANDIVA_CACHE_SIZE";
+constexpr auto default_capacity = 5000;
+} // namespace
+
+TEST(TestCache, TestGetCacheCapacityDefault) {
+ ASSERT_EQ(GetCapacity(), default_capacity);
+}
+
+TEST(TestCache, TestGetCacheCapacityEnvVar) {
+ // Uncleared env var may have side-effect to subsequent tests. Use a structure to help
+ // clearing the env var when leaving the scope.
+ struct ScopedEnvVar {
Review Comment:
Can use the existing `EnvVarGuard` from our testing utilities.
##########
cpp/src/gandiva/cache.h:
##########
@@ -25,6 +25,14 @@
namespace gandiva {
+namespace internal {
+// Only called once by GetCapacity().
+// Do the actual work of getting the capacity from env var.
+// Also makes the testing easier.
+GANDIVA_EXPORT
+int GetCapacityFromEnvVar();
+} // namespace internal
+
GANDIVA_EXPORT
int GetCapacity();
Review Comment:
Can this be called `GetCacheCapacity`? The current name is too imprecise.
--
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
Re: [PR] GH-41329: [C++][Gandiva] Fix gandiva cache size env var [arrow]
Posted by "zanmato1984 (via GitHub)" <gi...@apache.org>.
zanmato1984 commented on code in PR #41330:
URL: https://github.com/apache/arrow/pull/41330#discussion_r1574529527
##########
cpp/src/gandiva/cache.cc:
##########
@@ -23,23 +23,38 @@
namespace gandiva {
-static const size_t DEFAULT_CACHE_SIZE = 5000;
+static const int DEFAULT_CACHE_SIZE = 5000;
-int GetCapacity() {
- size_t capacity = DEFAULT_CACHE_SIZE;
- auto maybe_env_cache_size = ::arrow::internal::GetEnvVar("GANDIVA_CACHE_SIZE");
- if (maybe_env_cache_size.ok()) {
- const auto env_cache_size = *std::move(maybe_env_cache_size);
- if (!env_cache_size.empty()) {
- capacity = std::atol(env_cache_size.c_str());
- if (capacity <= 0) {
- ARROW_LOG(WARNING) << "Invalid cache size provided in GANDIVA_CACHE_SIZE. "
- << "Using default cache size: " << DEFAULT_CACHE_SIZE;
- capacity = DEFAULT_CACHE_SIZE;
- }
- }
+namespace internal {
+int GetCapacityFromEnvVar() {
+ auto maybe_env_value = ::arrow::internal::GetEnvVar("GANDIVA_CACHE_SIZE");
+ if (!maybe_env_value.ok()) {
+ return DEFAULT_CACHE_SIZE;
+ }
+ const auto env_value = *std::move(maybe_env_value);
+ if (env_value.empty()) {
+ return DEFAULT_CACHE_SIZE;
+ }
+ int capacity = 0;
+ size_t length = 0;
+ bool exception = false;
+ try {
+ capacity = std::stoi(env_value.c_str(), &length);
Review Comment:
Replace `std::atol` with `std::stoi` to have better error handling.
--
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
Re: [PR] GH-41329: [C++][Gandiva] Fix gandiva cache size env var [arrow]
Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] commented on PR #41330:
URL: https://github.com/apache/arrow/pull/41330#issuecomment-2068650745
:warning: GitHub issue #41329 **has been automatically assigned in GitHub** to PR creator.
--
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
Re: [PR] GH-41329: [C++][Gandiva] Fix gandiva cache size env var [arrow]
Posted by "pitrou (via GitHub)" <gi...@apache.org>.
pitrou commented on code in PR #41330:
URL: https://github.com/apache/arrow/pull/41330#discussion_r1587854844
##########
cpp/src/gandiva/cache.h:
##########
@@ -25,6 +25,14 @@
namespace gandiva {
+namespace internal {
+// Only called once by GetCapacity().
+// Do the actual work of getting the capacity from env var.
+// Also makes the testing easier.
+GANDIVA_EXPORT
+int GetCapacityFromEnvVar();
+} // namespace internal
+
GANDIVA_EXPORT
int GetCapacity();
Review Comment:
I have no idea :-) You could deprecate the old API if we want to ensure a smoother migration.
--
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
Re: [PR] GH-41329: [C++][Gandiva] Fix gandiva cache size env var [arrow]
Posted by "zanmato1984 (via GitHub)" <gi...@apache.org>.
zanmato1984 commented on code in PR #41330:
URL: https://github.com/apache/arrow/pull/41330#discussion_r1587894985
##########
cpp/src/gandiva/cache.cc:
##########
@@ -20,26 +20,41 @@
#include "arrow/result.h"
#include "arrow/util/io_util.h"
#include "arrow/util/logging.h"
+#include "arrow/util/value_parsing.h"
namespace gandiva {
-static const size_t DEFAULT_CACHE_SIZE = 5000;
-
-int GetCapacity() {
- size_t capacity = DEFAULT_CACHE_SIZE;
- auto maybe_env_cache_size = ::arrow::internal::GetEnvVar("GANDIVA_CACHE_SIZE");
- if (maybe_env_cache_size.ok()) {
- const auto env_cache_size = *std::move(maybe_env_cache_size);
- if (!env_cache_size.empty()) {
- capacity = std::atol(env_cache_size.c_str());
- if (capacity <= 0) {
- ARROW_LOG(WARNING) << "Invalid cache size provided in GANDIVA_CACHE_SIZE. "
- << "Using default cache size: " << DEFAULT_CACHE_SIZE;
- capacity = DEFAULT_CACHE_SIZE;
- }
- }
+constexpr auto kCacheCapacityEnvVar = "GANDIVA_CACHE_SIZE";
+constexpr auto kDefaultCacheSize = 5000;
+
+namespace internal {
+int GetCacheCapacityFromEnvVar() {
+ auto maybe_env_value = ::arrow::internal::GetEnvVar(kCacheCapacityEnvVar);
+ if (!maybe_env_value.ok()) {
+ return kDefaultCacheSize;
+ }
+ const auto env_value = *std::move(maybe_env_value);
+ if (env_value.empty()) {
+ return kDefaultCacheSize;
+ }
+ int capacity = 0;
+ bool ok = ::arrow::internal::ParseValue<::arrow::Int32Type>(
+ env_value.c_str(), env_value.size(), &capacity);
Review Comment:
Updated the parsing according to the recommendation from https://github.com/apache/arrow/pull/41335#discussion_r1581117184
--
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