Repository navigation
fix(arrow-array): preserve type params in PrimitiveArray::into_builder - #11321
Merged
Jefffrey merged 1 commit intoOct 2, 2026
Merged
Conversation
…lder` succeeds apache#11310 made the `Err` path of `PrimitiveArray::into_builder` return the array with its original data type. The `Ok` path still built the builder with `PrimitiveBuilder::new_from_buffer`, which uses `T::DATA_TYPE`, so `into_builder()?.finish()` lost type parameters: a `Decimal128(10, 2)` array came back as `Decimal128(38, 10)`, which changes its values (1.00 becomes 0.0000000100), and a timestamp lost its timezone. These public APIs go through the `Ok` path and returned the wrong type: - `PrimitiveArray::unary_mut` and `try_unary_mut` - `binary_mut` and `try_binary_mut` in arrow-arith - `DictionaryArray::unary_mut` and `into_primitive_dict_builder`. When the keys are shared, the `Err` value returned in place of the input was also rebuilt with the default value type. - `PrimitiveRunBuilder::finish_cloned` while a run is open, which ignored `with_data_type` The builder now gets the array's data type.
Contributor
Author
|
cc @Jefffrey |
Jefffrey
approved these changes
Oct 2, 2026
Contributor
|
thanks @neilconway |
This was referenced Oct 3, 2026
alamb
added a commit
that referenced
this pull request
Oct 22, 2026
…Array::into_builder` (#11807) - Backport #11310 and #11321 - For inclusion in #11666 Cherry-pick of 2f3cd82 and 38054b7 These are combined into a single PR since the fixes work on the same function ## NOTE We also backport #9473 183f8c1 since we needed it for a test, and I think fix makes more sense with this in mind. It was introduced in 58 so only 57 needs this extra backport --------- Co-authored-by: Neil Conway <[email protected]> Co-authored-by: Bruno <[email protected]> Co-authored-by: Andrew Lamb <[email protected]>
gafiatulin
pushed a commit
to gafiatulin/arrow-rs
that referenced
this pull request
Nov 14, 2026
…ion (apache#12242) # Which issue does this PR close? - Closes apache#11300 # Rationale for this change `null_if_overflow_precision` returned the default type of the decimal width instead of the input's type. A `Decimal128(2, 1)` holding `9.9` came back as `Decimal128(38, 10)` and read as `0.0000000099`. All four decimal widths behave this way, because the result is built through `unary_opt`, which uses `T::DATA_TYPE`. apache#11310 and apache#11321 fixed the same kind of bug. # What changes are included in this PR? - Set the input's data type on the `unary_opt` result with `.with_data_type(self.data_type().clone())`, as `into_builder` does since apache#11321. # Are these changes tested? Yes. `test_null_if_overflow_precision_keeps_data_type` covers Decimal32/64/128/256 at `(2, 1)`. Without the fix it fails with `Decimal32(9, 2)` vs `Decimal32(2, 1)`. # Are there any significant user-facing changes? The output data type now matches the input, including precision and scale. Which values get nulled is unchanged. Callers that re-applied the type afterwards (for example with `.with_precision_and_scale(..)`) keep working. # AI usage disclosure The patch and test were written with an AI coding agent (Claude Code). It reproduced the issue on main, ran fmt, clippy, the arrow-array tests (including release mode) and typos, and a separate agent session re-checked the fix against all four decimal widths, nulls, slices and the precision bounds before I submitted it.
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Which issue does this PR close?
PrimitiveArray::into_builder#11310Rationale for this change
#11310 made the
Errpath ofPrimitiveArray::into_builderreturn the array with its original data type. Looking closer, theOkpath still built the builder withPrimitiveBuilder::new_from_buffer, which usesT::DATA_TYPE, sointo_builder()?.finish()lost type parameters.These public APIs use
PrimitiveArray::into_builderand will now behave correctly:PrimitiveArray::unary_mutandtry_unary_mutbinary_mutandtry_binary_mutin arrow-arithDictionaryArray::unary_mutandinto_primitive_dict_builderPrimitiveRunBuilder::finish_clonedWhat changes are included in this PR?
PrimitiveArray::into_builderalso preserves type parametersAre these changes tested?
Yes; existing tests pass, new test added.
Are there any user-facing changes?
No, aside from the bug fix.
AI usage
Developed with Claude Code (Fable 5.1).