-
Notifications
You must be signed in to change notification settings - Fork 3.9k
GH-48206 Fix Statistics logic to enable Parquet DB support on s390x #48207
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
Vishwanatha-HD
wants to merge
1
commit into
apache:main
Choose a base branch
from
Vishwanatha-HD:fixStatistics
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.
+73
−0
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 |
|---|---|---|
|
|
@@ -30,6 +30,7 @@ | |
| #include "arrow/type_traits.h" | ||
| #include "arrow/util/bit_run_reader.h" | ||
| #include "arrow/util/checked_cast.h" | ||
| #include "arrow/util/endian.h" | ||
| #include "arrow/util/float16.h" | ||
| #include "arrow/util/logging_internal.h" | ||
| #include "arrow/util/ubsan.h" | ||
|
|
@@ -925,22 +926,94 @@ void TypedStatisticsImpl<DType>::UpdateSpaced(const T* values, const uint8_t* va | |
|
|
||
| template <typename DType> | ||
| void TypedStatisticsImpl<DType>::PlainEncode(const T& src, std::string* dst) const { | ||
| #if ARROW_LITTLE_ENDIAN | ||
| auto encoder = MakeTypedEncoder<DType>(Encoding::PLAIN, false, descr_, pool_); | ||
| encoder->Put(&src, 1); | ||
| auto buffer = encoder->FlushValues(); | ||
| auto ptr = reinterpret_cast<const char*>(buffer->data()); | ||
| dst->assign(ptr, static_cast<size_t>(buffer->size())); | ||
| #else | ||
| // For fixed-width numeric types, write explicit little-endian bytes per spec | ||
| if constexpr (std::is_same_v<DType, Int32Type>) { | ||
| uint32_t u; | ||
| std::memcpy(&u, &src, sizeof(u)); | ||
| u = ::arrow::bit_util::ToLittleEndian(u); | ||
| dst->assign(reinterpret_cast<const char*>(&u), sizeof(u)); | ||
| return; | ||
| } else if constexpr (std::is_same_v<DType, Int64Type>) { | ||
| uint64_t u; | ||
| std::memcpy(&u, &src, sizeof(u)); | ||
| u = ::arrow::bit_util::ToLittleEndian(u); | ||
| dst->assign(reinterpret_cast<const char*>(&u), sizeof(u)); | ||
| return; | ||
| } else if constexpr (std::is_same_v<DType, FloatType>) { | ||
| uint32_t u; | ||
| static_assert(sizeof(u) == sizeof(float), "size"); | ||
| std::memcpy(&u, &src, sizeof(u)); | ||
| u = ::arrow::bit_util::ToLittleEndian(u); | ||
| dst->assign(reinterpret_cast<const char*>(&u), sizeof(u)); | ||
| return; | ||
| } else if constexpr (std::is_same_v<DType, DoubleType>) { | ||
| uint64_t u; | ||
| static_assert(sizeof(u) == sizeof(double), "size"); | ||
| std::memcpy(&u, &src, sizeof(u)); | ||
| u = ::arrow::bit_util::ToLittleEndian(u); | ||
| dst->assign(reinterpret_cast<const char*>(&u), sizeof(u)); | ||
| return; | ||
| } | ||
| // Fallback: use encoder for other types | ||
| auto encoder = MakeTypedEncoder<DType>(Encoding::PLAIN, false, descr_, pool_); | ||
| encoder->Put(&src, 1); | ||
| auto buffer = encoder->FlushValues(); | ||
| dst->assign(reinterpret_cast<const char*>(buffer->data()), | ||
| static_cast<size_t>(buffer->size())); | ||
|
Comment on lines
+964
to
+969
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. Can we reuse the implementation in #if !ARROW_LITTLE_ENDIAN
if constexprt (...) {
...
} else if ... {
...
}
#endif
auto encoder = MakeTypedEncoder<DType>(Encoding::PLAIN, false, descr_, pool_);
encoder->Put(&src, 1);
auto buffer = encoder->FlushValues();
auto ptr = reinterpret_cast<const char*>(buffer->data());
dst->assign(ptr, static_cast<size_t>(buffer->size())); |
||
| #endif | ||
| } | ||
|
|
||
| template <typename DType> | ||
| void TypedStatisticsImpl<DType>::PlainDecode(const std::string& src, T* dst) const { | ||
| #if ARROW_LITTLE_ENDIAN | ||
| auto decoder = MakeTypedDecoder<DType>(Encoding::PLAIN, descr_); | ||
| decoder->SetData(1, reinterpret_cast<const uint8_t*>(src.c_str()), | ||
| static_cast<int>(src.size())); | ||
| int decoded_values = decoder->Decode(dst, 1); | ||
| if (decoded_values != 1) { | ||
| throw ParquetException("Failed to decode statistic value from plain encoded string"); | ||
| } | ||
| #else | ||
| if constexpr (std::is_same_v<DType, Int32Type>) { | ||
| uint32_t u = 0; | ||
| std::memcpy(&u, src.data(), std::min(src.size(), sizeof(u))); | ||
| u = ::arrow::bit_util::FromLittleEndian(u); | ||
| std::memcpy(dst, &u, sizeof(u)); | ||
| return; | ||
| } else if constexpr (std::is_same_v<DType, Int64Type>) { | ||
| uint64_t u = 0; | ||
| std::memcpy(&u, src.data(), std::min(src.size(), sizeof(u))); | ||
| u = ::arrow::bit_util::FromLittleEndian(u); | ||
| std::memcpy(dst, &u, sizeof(u)); | ||
| return; | ||
| } else if constexpr (std::is_same_v<DType, FloatType>) { | ||
| uint32_t u = 0; | ||
| std::memcpy(&u, src.data(), std::min(src.size(), sizeof(u))); | ||
| u = ::arrow::bit_util::FromLittleEndian(u); | ||
| std::memcpy(dst, &u, sizeof(u)); | ||
| return; | ||
| } else if constexpr (std::is_same_v<DType, DoubleType>) { | ||
| uint64_t u = 0; | ||
| std::memcpy(&u, src.data(), std::min(src.size(), sizeof(u))); | ||
| u = ::arrow::bit_util::FromLittleEndian(u); | ||
| std::memcpy(dst, &u, sizeof(u)); | ||
| return; | ||
| } | ||
| auto decoder = MakeTypedDecoder<DType>(Encoding::PLAIN, descr_); | ||
| decoder->SetData(1, reinterpret_cast<const uint8_t*>(src.c_str()), | ||
| static_cast<int>(src.size())); | ||
| int decoded_values = decoder->Decode(dst, 1); | ||
| if (decoded_values != 1) { | ||
| throw ParquetException("Failed to decode statistic value from plain encoded string"); | ||
| } | ||
| #endif | ||
| } | ||
|
|
||
| template <> | ||
|
|
||
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.
Can we do this in
XXXEncoder::Put()instead of here?