Skip to content

fix(arrow-data): allow full dictionary key range when concatenating - #10323

Merged
Jefffrey merged 1 commit into
apache:mainfrom
raphaelroshan:fix/dict-concat-key-overflow-9366
Jul 15, 2026
Merged

Jefffrey merged 1 commit into
apache:mainfrom
raphaelroshan:fix/dict-concat-key-overflow-9366

Conversation

@raphaelroshan

Copy link
Copy Markdown
Contributor

Which issue does this PR close?

Closes #9366.

Rationale for this change

Concatenating dictionary arrays whose merged dictionary length is exactly the key type's maximum value + 1 (e.g. 256 distinct values with u8 keys) panics with DictionaryKeyOverflowError. The largest key index is length - 1, so 256 values use keys 0..=255, which fit in u8 — the overflow check was off by one.

What changes are included in this PR?

build_extend_dictionary now checks that the key type can hold max - 1 (the largest index) rather than max (the length).

Are these changes tested?

Yes — added test_dict_overflow_9366, which concatenates two Dictionary<u8, _> arrays totaling 256 values and asserts it succeeds (panics before this change).

Are there any user-facing changes?

No API change; a previously-panicking concat now succeeds.

@github-actions github-actions Bot added the arrow Changes to the arrow crate label Jul 11, 2026

@Rich-T-kid Rich-T-kid left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

It may be worth adding test to cover other key types.

// `max` is the merged dictionary length; the largest key index is
// `max - 1`, so the key type only needs to hold `max - 1` (e.g. 256
// values use keys 0..=255, which fit in u8).
let _: $dt = max.saturating_sub(1).try_into().ok()?;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice catch

Concatenating dictionary arrays whose merged dictionary length exactly
equals the key type's max value + 1 (e.g. 256 values with u8 keys)
panicked with DictionaryKeyOverflowError. The largest key index is
length - 1, so check that instead of the length.

Closes apache#9366.
@raphaelroshan
raphaelroshan force-pushed the fix/dict-concat-key-overflow-9366 branch from e2fe6a1 to dc8f1e5 Compare July 13, 2026 03:48
@Jefffrey
Jefffrey merged commit 2edc0a0 into apache:main Jul 15, 2026
30 checks passed
@Jefffrey

Copy link
Copy Markdown
Contributor

thanks @raphaelroshan & @Rich-T-kid

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

arrow Changes to the arrow crate bug Squash those bugs

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Panic when concatenating some dictionary arrays with u8 keys and 256 total values

3 participants