You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@arrow.apache.org by "raulcd (via GitHub)" <gi...@apache.org> on 2025/09/01 10:11:06 UTC
[PR] GH-47449: [C++][Parquet] Do not drop all Statistics if SortOrder is UNKNOWN [arrow]
raulcd opened a new pull request, #47466:
URL: https://github.com/apache/arrow/pull/47466
### Rationale for this change
Currently we drop all statistics if `SortOrder` is `UNKNOWN`. This seems too broad and there are some statistics, like `null_count` that could be maintained.
https://github.com/apache/arrow/blob/6f6138b7eedece0841b04f4e235e3bedf5a3ee29/cpp/src/parquet/metadata.cc#L330-L335
Clearing `min/max` but allowing to keep `null_count` when `SortOrder` is `UNKNOWN` would allow users to use them.
### What changes are included in this PR?
Maintain Statistics when reading them if `SortOrder::UNKNOWK` but clear min/max
### Are these changes tested?
Yes, there is a file on parquet-testing which allows us to validate this exact scenario.
### Are there any user-facing changes?
No changes to APIs, users will be able to read statistics on this case.
--
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-47449: [C++][Parquet] Do not drop all Statistics if SortOrder is UNKNOWN [arrow]
Posted by "pitrou (via GitHub)" <gi...@apache.org>.
pitrou commented on code in PR #47466:
URL: https://github.com/apache/arrow/pull/47466#discussion_r2348052271
##########
cpp/src/parquet/statistics.cc:
##########
@@ -573,7 +578,11 @@ class TypedStatisticsImpl : public TypedStatistics<DType> {
min_buffer_(AllocateBuffer(pool_, 0)),
max_buffer_(AllocateBuffer(pool_, 0)),
logical_type_(LogicalTypeId(descr_)) {
- comparator_ = MakeComparator<DType>(descr);
+ try {
+ comparator_ = MakeComparator<DType>(descr);
Review Comment:
Instead of trying and catching, how about just not calling `MakeComparator` if the sort order is Unknown?
(sorry, I realize I suggested try/catch above; both are ok to me, by the way)
--
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-47449: [C++][Parquet] Do not drop all Statistics if SortOrder is UNKNOWN [arrow]
Posted by "pitrou (via GitHub)" <gi...@apache.org>.
pitrou merged PR #47466:
URL: https://github.com/apache/arrow/pull/47466
--
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-47449: [C++][Parquet] Do not drop all Statistics if SortOrder is UNKNOWN [arrow]
Posted by "raulcd (via GitHub)" <gi...@apache.org>.
raulcd commented on code in PR #47466:
URL: https://github.com/apache/arrow/pull/47466#discussion_r2348441438
##########
cpp/src/parquet/statistics.cc:
##########
@@ -573,7 +578,11 @@ class TypedStatisticsImpl : public TypedStatistics<DType> {
min_buffer_(AllocateBuffer(pool_, 0)),
max_buffer_(AllocateBuffer(pool_, 0)),
logical_type_(LogicalTypeId(descr_)) {
- comparator_ = MakeComparator<DType>(descr);
+ try {
+ comparator_ = MakeComparator<DType>(descr);
Review Comment:
maybe the early check is better and more explicit when reading the code, otherwise we might want to add the comment. I'll change it.
--
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-47449: [C++][Parquet] Do not drop all Statistics if SortOrder is UNKNOWN [arrow]
Posted by "conbench-apache-arrow[bot] (via GitHub)" <gi...@apache.org>.
conbench-apache-arrow[bot] commented on PR #47466:
URL: https://github.com/apache/arrow/pull/47466#issuecomment-3308012354
After merging your PR, Conbench analyzed the 4 benchmarking runs that have been run so far on merge-commit cbd36b817fc77812f8df1a15bf24314de3b27f29.
There were no benchmark performance regressions. 🎉
The [full Conbench report](https://github.com/apache/arrow/runs/50702901983) has more details. It also includes information about 28 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-47449: [C++][Parquet] Do not drop all Statistics if SortOrder is UNKNOWN [arrow]
Posted by "raulcd (via GitHub)" <gi...@apache.org>.
raulcd commented on code in PR #47466:
URL: https://github.com/apache/arrow/pull/47466#discussion_r2316113887
##########
cpp/src/parquet/statistics.cc:
##########
@@ -991,6 +996,8 @@ std::shared_ptr<Comparator> DoMakeComparator(Type::type physical_type,
default:
ParquetException::NYI("Unsigned Compare not implemented");
}
+ } else if (SortOrder::UNKNOWN == sort_order) {
+ return nullptr;
Review Comment:
This does not seem right because we were previously returning an Exception. The problem is that if `ApplicationVersion::HasCorrectStatistics` returns true when `SortOrder::UNKNOWN` if we want to generate the Typed Statistics a call to `DoMakeComparator` is expected to return and not raise an Exception as is currently happening.
Apart from ideas on what could be the best approach about that, this open the question of the writer too. Should we also write Statistics for columns with `SortOrder::UNKNOWN` but not compute min/max? Maybe as a different issue is it worth it?
@pitrou what are your thoughts?
--
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-47449: [C++][Parquet] Do not drop all Statistics if SortOrder is UNKNOWN [arrow]
Posted by "pitrou (via GitHub)" <gi...@apache.org>.
pitrou commented on code in PR #47466:
URL: https://github.com/apache/arrow/pull/47466#discussion_r2348052271
##########
cpp/src/parquet/statistics.cc:
##########
@@ -573,7 +578,11 @@ class TypedStatisticsImpl : public TypedStatistics<DType> {
min_buffer_(AllocateBuffer(pool_, 0)),
max_buffer_(AllocateBuffer(pool_, 0)),
logical_type_(LogicalTypeId(descr_)) {
- comparator_ = MakeComparator<DType>(descr);
+ try {
+ comparator_ = MakeComparator<DType>(descr);
Review Comment:
Instead of trying and catching, how about just not calling `MakeComparator` if the sort order is Unknown?
--
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-47449: [C++][Parquet] Do not drop all Statistics if SortOrder is UNKNOWN [arrow]
Posted by "pitrou (via GitHub)" <gi...@apache.org>.
pitrou commented on code in PR #47466:
URL: https://github.com/apache/arrow/pull/47466#discussion_r2348055399
##########
cpp/src/parquet/statistics.cc:
##########
@@ -834,7 +844,7 @@ class TypedStatisticsImpl : public TypedStatistics<DType> {
void SetMinMaxPair(std::pair<T, T> min_max) {
// CleanStatistic can return a nullopt in case of erroneous values, e.g. NaN
auto maybe_min_max = CleanStatistic(min_max, logical_type_);
- if (!maybe_min_max) return;
+ if (!maybe_min_max || comparator_ == nullptr) return;
Review Comment:
We can check `comparator_` *before* calling `CleanStatistic`.
--
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-47449: [C++][Parquet] Do not drop all Statistics if SortOrder is UNKNOWN [arrow]
Posted by "pitrou (via GitHub)" <gi...@apache.org>.
pitrou commented on code in PR #47466:
URL: https://github.com/apache/arrow/pull/47466#discussion_r2322567210
##########
cpp/src/parquet/statistics.cc:
##########
@@ -991,6 +996,8 @@ std::shared_ptr<Comparator> DoMakeComparator(Type::type physical_type,
default:
ParquetException::NYI("Unsigned Compare not implemented");
}
+ } else if (SortOrder::UNKNOWN == sort_order) {
+ return nullptr;
Review Comment:
Ok, I looked at this and am coming to the following suggestion:
1. `DoMakeComparator` should keep throwing an exception instead of returning `nullptr`
2. `TypedStatisticsImpl` should catch the error when calling `MakeComparator` and then simply set the comparator to `nullptr` (methods using the comparator should be changed to be no-ops when that happens)
3. Also, `TypedStatisticsImpl` only uses the comparator when updating/writing statistics, so it could be probably be created lazily, not in the constructor? (but this is more of an improvement and not strictly necessary)
--
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-47449: [C++][Parquet] Do not drop all Statistics if SortOrder is UNKNOWN [arrow]
Posted by "wgtmac (via GitHub)" <gi...@apache.org>.
wgtmac commented on code in PR #47466:
URL: https://github.com/apache/arrow/pull/47466#discussion_r2343361251
##########
cpp/src/parquet/statistics.cc:
##########
@@ -336,6 +336,11 @@ CleanStatistic(std::pair<T, T> min_max, LogicalType::Type::type) {
return min_max;
}
+optional<std::pair<Int96, Int96>> CleanStatistic(std::pair<Int96, Int96> min_max,
Review Comment:
```suggestion
std::optional<std::pair<Int96, Int96>> CleanStatistic(std::pair<Int96, Int96> min_max,
```
##########
cpp/src/parquet/statistics.cc:
##########
@@ -573,7 +578,11 @@ class TypedStatisticsImpl : public TypedStatistics<DType> {
min_buffer_(AllocateBuffer(pool_, 0)),
max_buffer_(AllocateBuffer(pool_, 0)),
logical_type_(LogicalTypeId(descr_)) {
- comparator_ = MakeComparator<DType>(descr);
+ try {
+ comparator_ = MakeComparator<DType>(descr);
Review Comment:
When will it throw?
##########
cpp/src/parquet/statistics.cc:
##########
@@ -573,7 +578,11 @@ class TypedStatisticsImpl : public TypedStatistics<DType> {
min_buffer_(AllocateBuffer(pool_, 0)),
max_buffer_(AllocateBuffer(pool_, 0)),
logical_type_(LogicalTypeId(descr_)) {
- comparator_ = MakeComparator<DType>(descr);
+ try {
+ comparator_ = MakeComparator<DType>(descr);
+ } catch (const ParquetException&) {
+ comparator_ = nullptr;
Review Comment:
nit: add an error log?
--
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-47449: [C++][Parquet] Do not drop all Statistics if SortOrder is UNKNOWN [arrow]
Posted by "raulcd (via GitHub)" <gi...@apache.org>.
raulcd commented on code in PR #47466:
URL: https://github.com/apache/arrow/pull/47466#discussion_r2344337940
##########
cpp/src/parquet/statistics.cc:
##########
@@ -573,7 +578,11 @@ class TypedStatisticsImpl : public TypedStatistics<DType> {
min_buffer_(AllocateBuffer(pool_, 0)),
max_buffer_(AllocateBuffer(pool_, 0)),
logical_type_(LogicalTypeId(descr_)) {
- comparator_ = MakeComparator<DType>(descr);
+ try {
+ comparator_ = MakeComparator<DType>(descr);
Review Comment:
This will throw when generating typed statistics if `SortOrder::UNKNOWN` but we still want statistics to be generated except min/max. I can add a comment for that case.
--
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-47449: [C++][Parquet] Do not drop all Statistics if SortOrder is UNKNOWN [arrow]
Posted by "raulcd (via GitHub)" <gi...@apache.org>.
raulcd commented on code in PR #47466:
URL: https://github.com/apache/arrow/pull/47466#discussion_r2344356883
##########
cpp/src/parquet/statistics.cc:
##########
@@ -573,7 +578,11 @@ class TypedStatisticsImpl : public TypedStatistics<DType> {
min_buffer_(AllocateBuffer(pool_, 0)),
max_buffer_(AllocateBuffer(pool_, 0)),
logical_type_(LogicalTypeId(descr_)) {
- comparator_ = MakeComparator<DType>(descr);
+ try {
+ comparator_ = MakeComparator<DType>(descr);
+ } catch (const ParquetException&) {
+ comparator_ = nullptr;
Review Comment:
I am unsure we want to add an error log as, yes, it is an error building the comparator, because SortOrder is UNKNOWN and we can't build a comparator but it will be a valid use case of generating statistics (we will just not set min/max) so I don't think we want to add an error log. What do you think?
See the `DoMakeComparator` function:
https://github.com/apache/arrow/blob/d2dace9e46c278e7da5f9bfe9d07a58e6d0d2326/cpp/src/parquet/statistics.cc#L950-L998
--
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-47449: [C++][Parquet] Do not drop all Statistics if SortOrder is UNKNOWN [arrow]
Posted by "wgtmac (via GitHub)" <gi...@apache.org>.
wgtmac commented on PR #47466:
URL: https://github.com/apache/arrow/pull/47466#issuecomment-3306701318
> LGTM, thank you @raulcd . @wgtmac Do you want to take a last look?
Sorry for missing the message. This looks good!
--
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