Skip to content

[58_maintenance] fix(arrow-array): preserve type params in PrimitiveArray::into_builder - #11765

Merged
alamb merged 2 commits into
apache:58_maintenancefrom
Jefffrey:backport_11310_11321_58
Oct 21, 2026
Merged

alamb merged 2 commits into
apache:58_maintenancefrom
Jefffrey:backport_11310_11321_58

Conversation

@Jefffrey

Copy link
Copy Markdown
Contributor

…apache#11310)

# 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.
…er` (apache#11321)

# Which issue does this PR close?

- Follow-on to apache#11310

# Rationale for this change

apache#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).
@Jefffrey Jefffrey added the bug Squash those bugs label Oct 21, 2026
@github-actions github-actions Bot added the arrow-core Core crates related to representing arrow data label Oct 21, 2026
@Jefffrey
Jefffrey marked this pull request as ready for review October 21, 2026 12:09
@alamb

alamb commented Oct 21, 2026

Copy link
Copy Markdown
Contributor

Merging as MSRV failure is unrelated. I will fix in this PR

@alamb
alamb merged commit 473171d into apache:58_maintenance Oct 21, 2026
26 of 27 checks passed
@Jefffrey
Jefffrey deleted the backport_11310_11321_58 branch October 21, 2026 23:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

arrow-core Core crates related to representing arrow data bug Squash those bugs

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants