Skip to content

fix: Avoid dropping type parameters in PrimitiveArray::into_builder - #11310

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

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

Conversation

@neilconway

Copy link
Copy Markdown
Contributor

Which issue does this PR close?

  • N/A

Rationale for this change

If PrimitiveArray::into_builder fails to convert the array into the builder, we are supposed to return the input array unchanged. The previous implementation rebuilt the array with T::DATA_TYPE, which doesn't preserve type parameters (like the scale/precision of a decimal, or the timezone of a timestamp).

What changes are included in this PR?

  • Fix bug
  • Add unit test

Are these changes tested?

Yes; existing tests pass, new test added.

Are there any user-facing changes?

No.

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

Jefffrey commented Oct 1, 2026

Copy link
Copy Markdown
Contributor

thanks, nice spot

Jefffrey pushed a commit that referenced this pull request Oct 2, 2026
…er` (#11321)

# Which issue does this PR close?

- Follow-on to #11310

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