Skip to content

fix(arrow-array): preserve type params in PrimitiveArray::into_builder - #11321

Merged
Jefffrey merged 1 commit into
apache:mainfrom
neilconway:neilc/fix-primitive-into-builder-keeps-type
Oct 2, 2026
Merged

Jefffrey merged 1 commit into
apache:mainfrom
neilconway:neilc/fix-primitive-into-builder-keeps-type

Conversation

@neilconway

@neilconway neilconway commented Oct 1, 2026 •

Copy link
Copy Markdown
Contributor

Which issue does this PR close?

Rationale for this change

#11310 made the Err path of PrimitiveArray::into_builder return the array with its original data type. Looking closer, the Ok path still built the builder with PrimitiveBuilder::new_from_buffer, which uses T::DATA_TYPE, so into_builder()?.finish() lost type parameters.

These public APIs use PrimitiveArray::into_builder and will now behave correctly:

  • PrimitiveArray::unary_mut and try_unary_mut
  • binary_mut and try_binary_mut in arrow-arith
  • DictionaryArray::unary_mut and into_primitive_dict_builder
  • PrimitiveRunBuilder::finish_cloned

What changes are included in this PR?

  • Ensure success path of PrimitiveArray::into_builder also preserves type parameters
  • Update unit tests
  • Add new unit tests for some of the public APIs above, where the behavior is non-trivial

Are 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).

…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.
@neilconway

Copy link
Copy Markdown
Contributor Author

cc @Jefffrey

@github-actions github-actions Bot added arrow Changes to the arrow crate arrow-array labels Oct 1, 2026
@Jefffrey Jefffrey added the bug Squash those bugs label Oct 2, 2026
@Jefffrey
Jefffrey merged commit 38054b7 into apache:main Oct 2, 2026
42 checks passed
@Jefffrey

Jefffrey commented Oct 2, 2026

Copy link
Copy Markdown
Contributor

thanks @neilconway

alamb pushed a commit that referenced this pull request Oct 8, 2026
…Array::into_builder` (#11448)

- Backport #11310 and #11321
- For inclusion in #11352

Cherry-pick of
2f3cd82
and
38054b7

These are combined into a single PR since the fixes work on the same
function

---------

Co-authored-by: Neil Conway <[email protected]>
alamb pushed a commit that referenced this pull request Oct 21, 2026
…Array::into_builder` (#11765)

- Backport #11310 and #11321
- For inclusion in #11665

Cherry-pick of
2f3cd82
and
38054b7

These are combined into a single PR since the fixes work on the same
function

---------

Co-authored-by: Neil Conway <[email protected]>
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.
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 arrow-array bug Squash those bugs

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants