-
Notifications
You must be signed in to change notification settings - Fork 4k
GH-47995: [C++][Parquet] Fix empty string min/max statistics being lost during merge #48717
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
rynewang
wants to merge
1
commit into
apache:main
Choose a base branch
from
rynewang:fix-empty-string-statistics-merge
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+260
−2
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -55,6 +55,12 @@ namespace { | |
| constexpr int value_length(int value_length, const ByteArray& value) { return value.len; } | ||
| constexpr int value_length(int type_length, const FLBA& value) { return type_length; } | ||
|
|
||
| // Sentinel pointer to mark "no value" for ByteArray statistics. | ||
| // Distinct from nullptr, which is valid for empty strings. | ||
| // See: https://github.com/apache/arrow/issues/47995 | ||
| inline constexpr uint8_t kNoValueSentinelBytes[1] = {0}; | ||
| inline constexpr const uint8_t* kNoValueSentinel = kNoValueSentinelBytes; | ||
|
|
||
| // Static "constants" for normalizing float16 min/max values. These need to be expressed | ||
| // as pointers because `Float16LogicalType` represents an FLBA. | ||
| struct Float16Constants { | ||
|
|
@@ -290,7 +296,26 @@ struct BinaryLikeCompareHelperBase { | |
|
|
||
| template <bool is_signed> | ||
| struct CompareHelper<ByteArrayType, is_signed> | ||
| : public BinaryLikeCompareHelperBase<ByteArrayType, is_signed> {}; | ||
| : public BinaryLikeCompareHelperBase<ByteArrayType, is_signed> { | ||
| using Base = BinaryLikeCompareHelperBase<ByteArrayType, is_signed>; | ||
| using T = ByteArray; | ||
|
|
||
| // Use kNoValueSentinel instead of nullptr to distinguish "no value" from empty string. | ||
| static T DefaultMin() { return T{0, kNoValueSentinel}; } | ||
| static T DefaultMax() { return T{0, kNoValueSentinel}; } | ||
|
Comment on lines
+304
to
+305
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think these could just return |
||
|
|
||
| static T Min(int type_length, const T& a, const T& b) { | ||
| if (a.ptr == kNoValueSentinel) return b; | ||
rynewang marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| if (b.ptr == kNoValueSentinel) return a; | ||
| return Base::Compare(type_length, a, b) ? a : b; | ||
| } | ||
|
|
||
| static T Max(int type_length, const T& a, const T& b) { | ||
| if (a.ptr == kNoValueSentinel) return b; | ||
| if (b.ptr == kNoValueSentinel) return a; | ||
| return Base::Compare(type_length, a, b) ? b : a; | ||
| } | ||
| }; | ||
|
|
||
| template <bool is_signed> | ||
| struct CompareHelper<FLBAType, is_signed> | ||
|
|
@@ -412,7 +437,9 @@ optional<std::pair<FLBA, FLBA>> CleanStatistic(std::pair<FLBA, FLBA> min_max, | |
|
|
||
| optional<std::pair<ByteArray, ByteArray>> CleanStatistic( | ||
| std::pair<ByteArray, ByteArray> min_max, LogicalType::Type::type) { | ||
| if (min_max.first.ptr == nullptr || min_max.second.ptr == nullptr) { | ||
| // Check for kNoValueSentinel (not nullptr) because nullptr is valid for empty strings. | ||
| // See: https://github.com/apache/arrow/issues/47995 | ||
| if (min_max.first.ptr == kNoValueSentinel || min_max.second.ptr == kNoValueSentinel) { | ||
| return ::std::nullopt; | ||
| } | ||
| return min_max; | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is rather confusing, why not do the reverse? i.e. have nullptr mean a missing statistic, while a non-null empty string would mean an empty statistic.