Repository navigation
GH-45010: [C++] Error out in unique/value_counts when unified dictionary overflows the index type #55253
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
ViderStar
wants to merge
2
commits into
apache:main
Choose a base branch
from
ViderStar:GH-45010-dict-unique-index-overflow
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.
Open
GH-45010: [C++] Error out in unique/value_counts when unified dictionary overflows the index type #55253
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
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 |
|---|---|---|
|
|
@@ -21,6 +21,7 @@ | |
| #include <functional> | ||
| #include <locale> | ||
| #include <memory> | ||
| #include <numeric> | ||
| #include <stdexcept> | ||
| #include <string> | ||
| #include <utility> | ||
|
|
@@ -764,6 +765,35 @@ TEST_F(TestHashKernel, DictionaryUniqueAndValueCounts) { | |
| } | ||
| } | ||
|
|
||
| TEST_F(TestHashKernel, DictionaryUniqueAndValueCountsIndexOverflow) { | ||
| // GH-45010: unifying the chunk dictionaries can produce more entries than the | ||
| // index type can address | ||
| auto dict_ty = dictionary(int8(), int64()); | ||
| auto make_chunk = [&](int64_t first_value, int64_t dict_length) { | ||
| std::vector<int64_t> values(dict_length); | ||
| std::iota(values.begin(), values.end(), first_value); | ||
| std::shared_ptr<Array> dict; | ||
| ArrayFromVector<Int64Type, int64_t>(values, &dict); | ||
| auto indices = ArrayFromJSON(int8(), "[" + std::to_string(dict_length - 1) + "]"); | ||
| return std::make_shared<DictionaryArray>(dict_ty, indices, dict); | ||
| }; | ||
|
|
||
| // 64 + 64 = 128 unified entries still fit in int8: the highest index is 127 | ||
| auto fits = *ChunkedArray::Make({make_chunk(0, 64), make_chunk(100, 64)}, dict_ty); | ||
| ASSERT_OK_AND_ASSIGN(auto uniques, Unique(fits)); | ||
| ASSERT_OK(uniques->ValidateFull()); | ||
| ASSERT_EQ(checked_cast<const DictionaryArray&>(*uniques).dictionary()->length(), 128); | ||
| ASSERT_OK_AND_ASSIGN(auto counts, ValueCounts(fits)); | ||
| ASSERT_OK(counts->ValidateFull()); | ||
|
Contributor
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. Validate result values and counts ( |
||
|
|
||
| // 64 + 65 = 129 unified entries do not | ||
| auto overflows = *ChunkedArray::Make({make_chunk(0, 64), make_chunk(100, 65)}, dict_ty); | ||
| EXPECT_RAISES_WITH_MESSAGE_THAT(Invalid, ::testing::HasSubstr("larger index type"), | ||
| Unique(overflows)); | ||
| EXPECT_RAISES_WITH_MESSAGE_THAT(Invalid, ::testing::HasSubstr("larger index type"), | ||
| ValueCounts(overflows)); | ||
| } | ||
|
|
||
| /* TODO(ARROW-4124): Determine if we want to do something that is reproducible with | ||
| * floats. | ||
| TEST_F(TestHashKernel, ValueCountsFloat) { | ||
|
|
||
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.
Check the indices we use instead of the dictionary size perhaps?
Counter example with
int8indices:Also check the used non-null indices before narrowing them and add this test for both functions.
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.
I independently reproduced the valid-input regression Dmitry described. A unified dictionary can contain 129 entries while the only used indices are 0 and 64, which still fit in int8.
Could we check the used non-null transposed indices before narrowing, and add this valid-input case for both unique and value_counts alongside the existing boundary tests? Please also assert the actual result values and counts, rather than relying only on ValidateFull().