Repository navigation
fix(arrow-data): don't panic on dictionary key overflow in interleave/concat - #10675
Conversation
|
Also probably related to #10553 |
|
@Jefffrey could you review this one please? |
Rich-T-kid
left a comment
There was a problem hiding this comment.
This looks good to me. left a couple nits about the comments.
MutableArrayData::new / with_capacities unconditionally concatenate dictionaries whose values aren't the same underlying buffer, and .expect() the result. When the combined dictionary genuinely exceeds the key type's range (e.g. merging independently dictionary-encoded partitions with UInt16 keys), this panics instead of surfacing a catchable error. The same construction is used recursively for dictionaries nested inside List/FixedSizeList/Struct/RunEndEncoded/ Union children, so the panic isn't limited to top-level dictionary arrays. Add fallible try_new / try_with_capacities that return Err(ArrowError::DictionaryKeyOverflowError) instead of panicking, and switch arrow-select's interleave_fallback and concat_fallback (the paths reached for dictionary arrays that can't/shouldn't be merged), including their recursive descent into nested children, to use them. new()/with_capacities() keep their existing panicking behavior for all other callers.
07b9336 to
bad60bc
Compare
| /// Unlike [MutableArrayData::new], this does not panic when merging dictionary | ||
| /// arrays whose combined values would overflow the dictionary key type. Instead, | ||
| /// it returns an error, letting callers (e.g. [`interleave`](crate) / `concat`) | ||
| /// surface it as a normal error. |
There was a problem hiding this comment.
this is sufficient for this PR, but in a followup we'll likely need to modify try_with_capacities() to return errors for all its other panicking behaviour and adjust this doc to be less specific toward the dictionary overflow behaviour
| /// of `arrays`. Or when a [Capacities] variant is not yet supported. | ||
| /// of `arrays`. Or when a [Capacities] variant is not yet supported. Or when | ||
| /// merging dictionary arrays whose combined values overflow the dictionary key | ||
| /// type — see [MutableArrayData::try_with_capacities] for a fallible variant. |
There was a problem hiding this comment.
can list as bullet points instead of chaining or's
/// # Panics
///
/// * if given `capacities` don't match the data type of `arrays`
/// * if a `Capacities` variant is not yet supported
/// * when merging dictionary arrays whose combined values overflow the dictionary key type
| // Two independently-built `Dictionary<UInt8, Utf8View>` arrays, each within | ||
| // the u8 key range on its own, but whose *combined* distinct values overflow | ||
| // it (analogous to per-partition dictionary-encoded columns being merged). | ||
| let values_a: StringViewArray = (0..200).map(|i| Some(format!("a{i}"))).collect(); | ||
| let keys_a = UInt8Array::from_iter_values(0..200); | ||
| let dict_a = DictionaryArray::<UInt8Type>::new(keys_a, Arc::new(values_a)); | ||
|
|
||
| let values_b: StringViewArray = (0..200).map(|i| Some(format!("b{i}"))).collect(); | ||
| let keys_b = UInt8Array::from_iter_values(0..200); | ||
| let dict_b = DictionaryArray::<UInt8Type>::new(keys_b, Arc::new(values_b)); | ||
|
|
||
| // Must not panic: the key type genuinely cannot address 400 distinct values, | ||
| // so this should surface as a normal, catchable error. | ||
| let err = concat(&[&dict_a, &dict_b]).unwrap_err(); | ||
| assert!(matches!(err, ArrowError::DictionaryKeyOverflowError)); |
There was a problem hiding this comment.
| // Two independently-built `Dictionary<UInt8, Utf8View>` arrays, each within | |
| // the u8 key range on its own, but whose *combined* distinct values overflow | |
| // it (analogous to per-partition dictionary-encoded columns being merged). | |
| let values_a: StringViewArray = (0..200).map(|i| Some(format!("a{i}"))).collect(); | |
| let keys_a = UInt8Array::from_iter_values(0..200); | |
| let dict_a = DictionaryArray::<UInt8Type>::new(keys_a, Arc::new(values_a)); | |
| let values_b: StringViewArray = (0..200).map(|i| Some(format!("b{i}"))).collect(); | |
| let keys_b = UInt8Array::from_iter_values(0..200); | |
| let dict_b = DictionaryArray::<UInt8Type>::new(keys_b, Arc::new(values_b)); | |
| // Must not panic: the key type genuinely cannot address 400 distinct values, | |
| // so this should surface as a normal, catchable error. | |
| let err = concat(&[&dict_a, &dict_b]).unwrap_err(); | |
| assert!(matches!(err, ArrowError::DictionaryKeyOverflowError)); | |
| // concatenating dictionaries which results in overflowing the key type should | |
| // surface an error not a panic | |
| let values_a: StringViewArray = (0..200).map(|i| Some(format!("a{i}"))).collect(); | |
| let keys_a = UInt8Array::from_iter_values(0..200); | |
| let dict_a = DictionaryArray::<UInt8Type>::new(keys_a, Arc::new(values_a)); | |
| let values_b: StringViewArray = (0..200).map(|i| Some(format!("b{i}"))).collect(); | |
| let keys_b = UInt8Array::from_iter_values(0..200); | |
| let dict_b = DictionaryArray::<UInt8Type>::new(keys_b, Arc::new(values_b)); | |
| let err = concat(&[&dict_a, &dict_b]).unwrap_err(); | |
| assert!(matches!(err, ArrowError::DictionaryKeyOverflowError)); |
we can cut down the verbosity of the comments; same for the other tests below
- MutableArrayData::with_capacities's # Panics doc: bullet points instead of chained "or" sentences. - Cut the verbose per-test explanatory comments down to one line each, matching the style of the surrounding tests.
|
run benchmarks concatenate_kernel interleave_kernels |
This comment was marked as duplicate.
This comment was marked as duplicate.
This comment was marked as duplicate.
This comment was marked as duplicate.
|
🤖 Arrow criterion benchmark completed (GKE) | trigger Instance: Comparing fix-dictionary-key-overflow-panic (5f53130) to 3abbc04 (merge-base) diff Run configurationrun benchmark concatenate_kernelCPU Details (lscpu)Details
Resource Usagebase (merge-base)
branch
File an issue against this benchmark runner |
|
🤖 Arrow criterion benchmark completed (GKE) | trigger Instance: Comparing fix-dictionary-key-overflow-panic (5f53130) to 3abbc04 (merge-base) diff Run configurationrun benchmark interleave_kernelsCPU Details (lscpu)Details
Resource Usagebase (merge-base)
branch
File an issue against this benchmark runner |
|
So, it can be merged now? |
|
thanks @okhsunrog & @Rich-T-kid |
`MutableArrayData::try_with_capacities` arrived with apache#10675. It only turns the dictionary key overflow into an error, and still panics for the other cases, so say so under a heading the lint recognises. Co-Authored-By: Claude Opus 5 <[email protected]>
…/concat (apache#10675) # Which issue does this PR close? - Closes apache#10674. # Rationale for this change `interleave()` and `concat()` document a `Result` return type, but for `Dictionary<K, Utf8View>`/`Dictionary<K, BinaryView>` arrays (top-level or nested inside a `List`/`FixedSizeList`/`Struct`/`RunEndEncoded`/`Union`), a genuine dictionary key overflow currently panics instead of returning `Err`. This happens because the fallback path builds a `MutableArrayData` directly and `.expect()`s the dictionary-concat result, and `MutableArrayData::new`/`with_capacities` have no fallible variant. See apache#10674 for the full analysis and a minimal repro. # What changes are included in this PR? - Add `MutableArrayData::try_new` / `try_with_capacities`, fallible variants of `new` / `with_capacities` that return `Err(ArrowError::DictionaryKeyOverflowError)` instead of panicking on dictionary key overflow. `new()`/`with_capacities()` keep their existing panicking behavior (now implemented as `try_with_capacities(..).expect(..)`) for the many existing callers that rely on infallibility. - Recursive child construction inside `try_with_capacities` (for `List`/`LargeList`/`Map`/`ListView`/`LargeListView`/`FixedSizeList`/`Struct`/`RunEndEncoded`/`Union`) also uses the fallible variants and propagates errors with `?`, so dictionaries nested inside container types are covered, not just top-level dictionary arrays. - Switch `arrow-select`'s `interleave_fallback` and `concat_fallback` (the paths reached for dictionary arrays whose values can't/shouldn't be merged) to the fallible constructors. # Are these changes tested? Yes: - `concat_string_view_dictionary_overflow_returns_err` / `test_interleave_string_view_dictionary_overflow_returns_err`: top-level `Dictionary<UInt8, Utf8View>` overflow returns `Err` instead of panicking. - `concat_nested_dictionary_overflow_returns_err` / `test_interleave_nested_dictionary_overflow_returns_err`: same overflow nested inside a `FixedSizeList`, exercising the recursive child construction. Full `arrow-data`/`arrow-select` test suites pass (410 tests), `cargo fmt --check` and `cargo clippy --all-targets -- -D warnings` are clean for both crates. # Are there any user-facing changes? No breaking changes. `MutableArrayData::new`/`with_capacities` keep their documented panicking behavior and signatures. Two new public fallible methods are added (`try_new`, `try_with_capacities`). `interleave()`/`concat()` keep their existing `Result` signature -- the only visible change is that a specific previously-panicking input (genuine dictionary key overflow on `Utf8View`/`BinaryView` dictionaries) now returns `Err(ArrowError::DictionaryKeyOverflowError)` instead. --------- Co-authored-by: Jeffrey Vo <[email protected]>
…/concat (apache#10675) # Which issue does this PR close? - Closes apache#10674. # Rationale for this change `interleave()` and `concat()` document a `Result` return type, but for `Dictionary<K, Utf8View>`/`Dictionary<K, BinaryView>` arrays (top-level or nested inside a `List`/`FixedSizeList`/`Struct`/`RunEndEncoded`/`Union`), a genuine dictionary key overflow currently panics instead of returning `Err`. This happens because the fallback path builds a `MutableArrayData` directly and `.expect()`s the dictionary-concat result, and `MutableArrayData::new`/`with_capacities` have no fallible variant. See apache#10674 for the full analysis and a minimal repro. # What changes are included in this PR? - Add `MutableArrayData::try_new` / `try_with_capacities`, fallible variants of `new` / `with_capacities` that return `Err(ArrowError::DictionaryKeyOverflowError)` instead of panicking on dictionary key overflow. `new()`/`with_capacities()` keep their existing panicking behavior (now implemented as `try_with_capacities(..).expect(..)`) for the many existing callers that rely on infallibility. - Recursive child construction inside `try_with_capacities` (for `List`/`LargeList`/`Map`/`ListView`/`LargeListView`/`FixedSizeList`/`Struct`/`RunEndEncoded`/`Union`) also uses the fallible variants and propagates errors with `?`, so dictionaries nested inside container types are covered, not just top-level dictionary arrays. - Switch `arrow-select`'s `interleave_fallback` and `concat_fallback` (the paths reached for dictionary arrays whose values can't/shouldn't be merged) to the fallible constructors. # Are these changes tested? Yes: - `concat_string_view_dictionary_overflow_returns_err` / `test_interleave_string_view_dictionary_overflow_returns_err`: top-level `Dictionary<UInt8, Utf8View>` overflow returns `Err` instead of panicking. - `concat_nested_dictionary_overflow_returns_err` / `test_interleave_nested_dictionary_overflow_returns_err`: same overflow nested inside a `FixedSizeList`, exercising the recursive child construction. Full `arrow-data`/`arrow-select` test suites pass (410 tests), `cargo fmt --check` and `cargo clippy --all-targets -- -D warnings` are clean for both crates. # Are there any user-facing changes? No breaking changes. `MutableArrayData::new`/`with_capacities` keep their documented panicking behavior and signatures. Two new public fallible methods are added (`try_new`, `try_with_capacities`). `interleave()`/`concat()` keep their existing `Result` signature -- the only visible change is that a specific previously-panicking input (genuine dictionary key overflow on `Utf8View`/`BinaryView` dictionaries) now returns `Err(ArrowError::DictionaryKeyOverflowError)` instead. --------- Co-authored-by: Jeffrey Vo <[email protected]>
…/concat (apache#10675) # Which issue does this PR close? - Closes apache#10674. # Rationale for this change `interleave()` and `concat()` document a `Result` return type, but for `Dictionary<K, Utf8View>`/`Dictionary<K, BinaryView>` arrays (top-level or nested inside a `List`/`FixedSizeList`/`Struct`/`RunEndEncoded`/`Union`), a genuine dictionary key overflow currently panics instead of returning `Err`. This happens because the fallback path builds a `MutableArrayData` directly and `.expect()`s the dictionary-concat result, and `MutableArrayData::new`/`with_capacities` have no fallible variant. See apache#10674 for the full analysis and a minimal repro. # What changes are included in this PR? - Add `MutableArrayData::try_new` / `try_with_capacities`, fallible variants of `new` / `with_capacities` that return `Err(ArrowError::DictionaryKeyOverflowError)` instead of panicking on dictionary key overflow. `new()`/`with_capacities()` keep their existing panicking behavior (now implemented as `try_with_capacities(..).expect(..)`) for the many existing callers that rely on infallibility. - Recursive child construction inside `try_with_capacities` (for `List`/`LargeList`/`Map`/`ListView`/`LargeListView`/`FixedSizeList`/`Struct`/`RunEndEncoded`/`Union`) also uses the fallible variants and propagates errors with `?`, so dictionaries nested inside container types are covered, not just top-level dictionary arrays. - Switch `arrow-select`'s `interleave_fallback` and `concat_fallback` (the paths reached for dictionary arrays whose values can't/shouldn't be merged) to the fallible constructors. # Are these changes tested? Yes: - `concat_string_view_dictionary_overflow_returns_err` / `test_interleave_string_view_dictionary_overflow_returns_err`: top-level `Dictionary<UInt8, Utf8View>` overflow returns `Err` instead of panicking. - `concat_nested_dictionary_overflow_returns_err` / `test_interleave_nested_dictionary_overflow_returns_err`: same overflow nested inside a `FixedSizeList`, exercising the recursive child construction. Full `arrow-data`/`arrow-select` test suites pass (410 tests), `cargo fmt --check` and `cargo clippy --all-targets -- -D warnings` are clean for both crates. # Are there any user-facing changes? No breaking changes. `MutableArrayData::new`/`with_capacities` keep their documented panicking behavior and signatures. Two new public fallible methods are added (`try_new`, `try_with_capacities`). `interleave()`/`concat()` keep their existing `Result` signature -- the only visible change is that a specific previously-panicking input (genuine dictionary key overflow on `Utf8View`/`BinaryView` dictionaries) now returns `Err(ArrowError::DictionaryKeyOverflowError)` instead. --------- Co-authored-by: Jeffrey Vo <[email protected]>
…/concat (apache#10675) # Which issue does this PR close? - Closes apache#10674. # Rationale for this change `interleave()` and `concat()` document a `Result` return type, but for `Dictionary<K, Utf8View>`/`Dictionary<K, BinaryView>` arrays (top-level or nested inside a `List`/`FixedSizeList`/`Struct`/`RunEndEncoded`/`Union`), a genuine dictionary key overflow currently panics instead of returning `Err`. This happens because the fallback path builds a `MutableArrayData` directly and `.expect()`s the dictionary-concat result, and `MutableArrayData::new`/`with_capacities` have no fallible variant. See apache#10674 for the full analysis and a minimal repro. # What changes are included in this PR? - Add `MutableArrayData::try_new` / `try_with_capacities`, fallible variants of `new` / `with_capacities` that return `Err(ArrowError::DictionaryKeyOverflowError)` instead of panicking on dictionary key overflow. `new()`/`with_capacities()` keep their existing panicking behavior (now implemented as `try_with_capacities(..).expect(..)`) for the many existing callers that rely on infallibility. - Recursive child construction inside `try_with_capacities` (for `List`/`LargeList`/`Map`/`ListView`/`LargeListView`/`FixedSizeList`/`Struct`/`RunEndEncoded`/`Union`) also uses the fallible variants and propagates errors with `?`, so dictionaries nested inside container types are covered, not just top-level dictionary arrays. - Switch `arrow-select`'s `interleave_fallback` and `concat_fallback` (the paths reached for dictionary arrays whose values can't/shouldn't be merged) to the fallible constructors. # Are these changes tested? Yes: - `concat_string_view_dictionary_overflow_returns_err` / `test_interleave_string_view_dictionary_overflow_returns_err`: top-level `Dictionary<UInt8, Utf8View>` overflow returns `Err` instead of panicking. - `concat_nested_dictionary_overflow_returns_err` / `test_interleave_nested_dictionary_overflow_returns_err`: same overflow nested inside a `FixedSizeList`, exercising the recursive child construction. Full `arrow-data`/`arrow-select` test suites pass (410 tests), `cargo fmt --check` and `cargo clippy --all-targets -- -D warnings` are clean for both crates. # Are there any user-facing changes? No breaking changes. `MutableArrayData::new`/`with_capacities` keep their documented panicking behavior and signatures. Two new public fallible methods are added (`try_new`, `try_with_capacities`). `interleave()`/`concat()` keep their existing `Result` signature -- the only visible change is that a specific previously-panicking input (genuine dictionary key overflow on `Utf8View`/`BinaryView` dictionaries) now returns `Err(ArrowError::DictionaryKeyOverflowError)` instead. --------- Co-authored-by: Jeffrey Vo <[email protected]>
…/concat (apache#10675) # Which issue does this PR close? - Closes apache#10674. # Rationale for this change `interleave()` and `concat()` document a `Result` return type, but for `Dictionary<K, Utf8View>`/`Dictionary<K, BinaryView>` arrays (top-level or nested inside a `List`/`FixedSizeList`/`Struct`/`RunEndEncoded`/`Union`), a genuine dictionary key overflow currently panics instead of returning `Err`. This happens because the fallback path builds a `MutableArrayData` directly and `.expect()`s the dictionary-concat result, and `MutableArrayData::new`/`with_capacities` have no fallible variant. See apache#10674 for the full analysis and a minimal repro. # What changes are included in this PR? - Add `MutableArrayData::try_new` / `try_with_capacities`, fallible variants of `new` / `with_capacities` that return `Err(ArrowError::DictionaryKeyOverflowError)` instead of panicking on dictionary key overflow. `new()`/`with_capacities()` keep their existing panicking behavior (now implemented as `try_with_capacities(..).expect(..)`) for the many existing callers that rely on infallibility. - Recursive child construction inside `try_with_capacities` (for `List`/`LargeList`/`Map`/`ListView`/`LargeListView`/`FixedSizeList`/`Struct`/`RunEndEncoded`/`Union`) also uses the fallible variants and propagates errors with `?`, so dictionaries nested inside container types are covered, not just top-level dictionary arrays. - Switch `arrow-select`'s `interleave_fallback` and `concat_fallback` (the paths reached for dictionary arrays whose values can't/shouldn't be merged) to the fallible constructors. # Are these changes tested? Yes: - `concat_string_view_dictionary_overflow_returns_err` / `test_interleave_string_view_dictionary_overflow_returns_err`: top-level `Dictionary<UInt8, Utf8View>` overflow returns `Err` instead of panicking. - `concat_nested_dictionary_overflow_returns_err` / `test_interleave_nested_dictionary_overflow_returns_err`: same overflow nested inside a `FixedSizeList`, exercising the recursive child construction. Full `arrow-data`/`arrow-select` test suites pass (410 tests), `cargo fmt --check` and `cargo clippy --all-targets -- -D warnings` are clean for both crates. # Are there any user-facing changes? No breaking changes. `MutableArrayData::new`/`with_capacities` keep their documented panicking behavior and signatures. Two new public fallible methods are added (`try_new`, `try_with_capacities`). `interleave()`/`concat()` keep their existing `Result` signature -- the only visible change is that a specific previously-panicking input (genuine dictionary key overflow on `Utf8View`/`BinaryView` dictionaries) now returns `Err(ArrowError::DictionaryKeyOverflowError)` instead. --------- Co-authored-by: Jeffrey Vo <[email protected]>
…/concat (apache#10675) # Which issue does this PR close? - Closes apache#10674. # Rationale for this change `interleave()` and `concat()` document a `Result` return type, but for `Dictionary<K, Utf8View>`/`Dictionary<K, BinaryView>` arrays (top-level or nested inside a `List`/`FixedSizeList`/`Struct`/`RunEndEncoded`/`Union`), a genuine dictionary key overflow currently panics instead of returning `Err`. This happens because the fallback path builds a `MutableArrayData` directly and `.expect()`s the dictionary-concat result, and `MutableArrayData::new`/`with_capacities` have no fallible variant. See apache#10674 for the full analysis and a minimal repro. # What changes are included in this PR? - Add `MutableArrayData::try_new` / `try_with_capacities`, fallible variants of `new` / `with_capacities` that return `Err(ArrowError::DictionaryKeyOverflowError)` instead of panicking on dictionary key overflow. `new()`/`with_capacities()` keep their existing panicking behavior (now implemented as `try_with_capacities(..).expect(..)`) for the many existing callers that rely on infallibility. - Recursive child construction inside `try_with_capacities` (for `List`/`LargeList`/`Map`/`ListView`/`LargeListView`/`FixedSizeList`/`Struct`/`RunEndEncoded`/`Union`) also uses the fallible variants and propagates errors with `?`, so dictionaries nested inside container types are covered, not just top-level dictionary arrays. - Switch `arrow-select`'s `interleave_fallback` and `concat_fallback` (the paths reached for dictionary arrays whose values can't/shouldn't be merged) to the fallible constructors. # Are these changes tested? Yes: - `concat_string_view_dictionary_overflow_returns_err` / `test_interleave_string_view_dictionary_overflow_returns_err`: top-level `Dictionary<UInt8, Utf8View>` overflow returns `Err` instead of panicking. - `concat_nested_dictionary_overflow_returns_err` / `test_interleave_nested_dictionary_overflow_returns_err`: same overflow nested inside a `FixedSizeList`, exercising the recursive child construction. Full `arrow-data`/`arrow-select` test suites pass (410 tests), `cargo fmt --check` and `cargo clippy --all-targets -- -D warnings` are clean for both crates. # Are there any user-facing changes? No breaking changes. `MutableArrayData::new`/`with_capacities` keep their documented panicking behavior and signatures. Two new public fallible methods are added (`try_new`, `try_with_capacities`). `interleave()`/`concat()` keep their existing `Result` signature -- the only visible change is that a specific previously-panicking input (genuine dictionary key overflow on `Utf8View`/`BinaryView` dictionaries) now returns `Err(ArrowError::DictionaryKeyOverflowError)` instead. --------- Co-authored-by: Jeffrey Vo <[email protected]>
Which issue does this PR close?
Rationale for this change
interleave()andconcat()document aResultreturn type, but forDictionary<K, Utf8View>/Dictionary<K, BinaryView>arrays (top-level or nested inside aList/FixedSizeList/Struct/RunEndEncoded/Union), a genuine dictionary key overflow currently panics instead of returningErr. This happens because the fallback path builds aMutableArrayDatadirectly and.expect()s the dictionary-concat result, andMutableArrayData::new/with_capacitieshave no fallible variant. See #10674 for the full analysis and a minimal repro.What changes are included in this PR?
MutableArrayData::try_new/try_with_capacities, fallible variants ofnew/with_capacitiesthat returnErr(ArrowError::DictionaryKeyOverflowError)instead of panicking on dictionary key overflow.new()/with_capacities()keep their existing panicking behavior (now implemented astry_with_capacities(..).expect(..)) for the many existing callers that rely on infallibility.try_with_capacities(forList/LargeList/Map/ListView/LargeListView/FixedSizeList/Struct/RunEndEncoded/Union) also uses the fallible variants and propagates errors with?, so dictionaries nested inside container types are covered, not just top-level dictionary arrays.arrow-select'sinterleave_fallbackandconcat_fallback(the paths reached for dictionary arrays whose values can't/shouldn't be merged) to the fallible constructors.Are these changes tested?
Yes:
concat_string_view_dictionary_overflow_returns_err/test_interleave_string_view_dictionary_overflow_returns_err: top-levelDictionary<UInt8, Utf8View>overflow returnsErrinstead of panicking.concat_nested_dictionary_overflow_returns_err/test_interleave_nested_dictionary_overflow_returns_err: same overflow nested inside aFixedSizeList, exercising the recursive child construction.Full
arrow-data/arrow-selecttest suites pass (410 tests),cargo fmt --checkandcargo clippy --all-targets -- -D warningsare clean for both crates.Are there any user-facing changes?
No breaking changes.
MutableArrayData::new/with_capacitieskeep their documented panicking behavior and signatures. Two new public fallible methods are added (try_new,try_with_capacities).interleave()/concat()keep their existingResultsignature -- the only visible change is that a specific previously-panicking input (genuine dictionary key overflow onUtf8View/BinaryViewdictionaries) now returnsErr(ArrowError::DictionaryKeyOverflowError)instead.