-
Notifications
You must be signed in to change notification settings - Fork 3.6k
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
GH-37939: [C++] Use signed arithmetic for frame of reference when encoding DELTA_BINARY_PACKED #37940
Merged
Merged
GH-37939: [C++] Use signed arithmetic for frame of reference when encoding DELTA_BINARY_PACKED #37940
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 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
This file contains 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 |
---|---|---|
|
@@ -1634,6 +1634,70 @@ TYPED_TEST(TestDeltaBitPackEncoding, NonZeroPaddedMiniblockBitWidth) { | |
} | ||
} | ||
|
||
// Test that the DELTA_BINARY_PACKED encoding works properply in the presence of values | ||
// that will cause integer overflow (see GH-37939). | ||
TYPED_TEST(TestDeltaBitPackEncoding, DeltaBitPackedWrapping) { | ||
using T = typename TypeParam::c_type; | ||
|
||
// Values that should wrap when converted to deltas, and then when converted to the | ||
// frame of reference. | ||
std::vector<T> int_values = {std::numeric_limits<T>::min(), | ||
std::numeric_limits<T>::max(), | ||
std::numeric_limits<T>::min(), | ||
std::numeric_limits<T>::max(), | ||
0, | ||
-1, | ||
0, | ||
1, | ||
-1, | ||
1}; | ||
const int num_values = static_cast<int>(int_values.size()); | ||
|
||
auto const encoder = MakeTypedEncoder<TypeParam>( | ||
Encoding::DELTA_BINARY_PACKED, /*use_dictionary=*/false, this->descr_.get()); | ||
encoder->Put(int_values, num_values); | ||
auto const encoded = encoder->FlushValues(); | ||
|
||
auto const decoder = | ||
MakeTypedDecoder<TypeParam>(Encoding::DELTA_BINARY_PACKED, this->descr_.get()); | ||
|
||
std::vector<T> decoded(num_values); | ||
decoder->SetData(num_values, encoded->data(), static_cast<int>(encoded->size())); | ||
|
||
const int values_decoded = decoder->Decode(decoded.data(), num_values); | ||
|
||
ASSERT_EQ(num_values, values_decoded); | ||
ASSERT_NO_FATAL_FAILURE( | ||
VerifyResults<T>(decoded.data(), int_values.data(), num_values)); | ||
} | ||
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. Since this PR also fixes the encoded data size, can you add a test for that? For example check that the encoded buffer size is equal to a certain value given data that would have triggered the bug, such as the data in #37939 (comment) |
||
|
||
// Test that the DELTA_BINARY_PACKED encoding does not use more bits to encode than | ||
// necessary (see GH-37939). | ||
TYPED_TEST(TestDeltaBitPackEncoding, DeltaBitPackedSize) { | ||
using T = typename TypeParam::c_type; | ||
constexpr int num_values = 128; | ||
// 128 values should be <= 1 block of values encoded with 2 bits | ||
// delta header should be 0x8001|0x8002 0x04 0x8001 0x02 (6 bytes) | ||
// mini-block header should be 0x01 0x02020202 (5 bytes) | ||
constexpr int encoded_size = 2 * num_values / 8 + 6 + 5; | ||
|
||
// Create a run of {1, 0, -1, 0, 1, 0, ...}. | ||
// min_delta is -1, max_delta is 1, max_delta - min_delta is 2, so this requires 2 bits | ||
// to encode. | ||
std::vector<T> int_values(num_values); | ||
std::iota(int_values.begin(), int_values.end(), 0); | ||
std::transform(int_values.begin(), int_values.end(), int_values.begin(), [](T idx) { | ||
return (idx % 2) == 1 ? 0 : (idx % 4) == 0 ? 1 : -1; | ||
}); | ||
|
||
auto const encoder = MakeTypedEncoder<TypeParam>( | ||
Encoding::DELTA_BINARY_PACKED, /*use_dictionary=*/false, this->descr_.get()); | ||
encoder->Put(int_values, num_values); | ||
auto const encoded = encoder->FlushValues(); | ||
|
||
ASSERT_EQ(encoded->size(), encoded_size); | ||
} | ||
|
||
// ---------------------------------------------------------------------- | ||
// Rle for Boolean encode/decode tests. | ||
|
||
|
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 you add a comment refering to the GH issue?