Skip to content

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

Merged
alamb merged 4 commits into
apache:57_maintenancefrom
Jefffrey:backport_11310_11321_57
Oct 22, 2026
Merged

alamb merged 4 commits into
apache:57_maintenancefrom
Jefffrey:backport_11310_11321_57

Conversation

@Jefffrey

Copy link
Copy Markdown
Contributor

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

neilconway and others added 3 commits October 22, 2026 22:31
…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.
…taType (apache#9473)

This enables setting a timezone or precision & scale on parameterized
DataType values.

Note: I think the panic is unfortunate, and a try_with_data_type() would
be sensible.

# Which issue does this PR close?

- Closes apache#8042.

# Are these changes tested?

Yes

# Are there any user-facing changes?

- Adds `PrimitiveRunBuilder::with_data_type`.
…er` (apache#11321)

- Follow-on to apache#11310

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`

* 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

Yes; existing tests pass, new test added.

No, aside from the bug fix.

Developed with Claude Code (Fable 5.1).
@Jefffrey Jefffrey added the bug Squash those bugs label Oct 22, 2026
@github-actions github-actions Bot added the arrow-core Core crates related to representing arrow data label Oct 22, 2026
@Jefffrey
Jefffrey marked this pull request as ready for review October 22, 2026 12:23
/// # Panics
///
/// This method panics if `values_builder` rejects `data_type`.
pub fn with_data_type(mut self, data_type: arrow_schema::DataType) -> Self {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

…310_11321_57

# Conflicts:
#	arrow-array/src/builder/primitive_run_builder.rs
@alamb
alamb merged commit fadd9ee into apache:57_maintenance Oct 22, 2026
25 checks passed
@Jefffrey
Jefffrey deleted the backport_11310_11321_57 branch October 22, 2026 21:49
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.

4 participants