Skip to content

Add finish_preserve_values to ArrayBuilder trait#9601

Merged
alamb merged 1 commit into
apache:mainfrom
adamreichold:finish-preserve-values
Apr 13, 2026
Merged

Add finish_preserve_values to ArrayBuilder trait#9601
alamb merged 1 commit into
apache:mainfrom
adamreichold:finish-preserve-values

Conversation

@adamreichold
Copy link
Copy Markdown
Contributor

Which issue does this PR close?

Rationale for this change

Delta dictionaries require user code to call finish_preserve_values instead of finish on the dictionary builders. But this is generally not possible if those builders are nested within composite builders like lists, maps or structs. Using the new trait method, user code can call this generically which has no effect on e.g. primitive builders due to the default implementation but forwards to this method for composite ones.

What changes are included in this PR?

Adds a new method finish_preserve_values to ArrayBuilder with a default implementation that forwards to finish.

Implements this method for dictionary and composite builders.

Are these changes tested?

Adds tests where new finish_preserve_values inherent methods were created to check that the correct method on the constituent builders is called using a shared mock builder PreserveValuesMock.

Are there any user-facing changes?

This adds a new method finish_preserve_values to the central ArrayBuilder trait, but it has a default implementation so this should be backwards compatible.

@github-actions github-actions Bot added the arrow Changes to the arrow crate label Mar 22, 2026
@alamb
Copy link
Copy Markdown
Contributor

alamb commented Mar 27, 2026

@albertlockett I wonder if you might have some time to review this PR and offer an opinion?

@adamreichold adamreichold force-pushed the finish-preserve-values branch from 7e1df01 to 9248def Compare March 28, 2026 06:45
Copy link
Copy Markdown
Contributor

@albertlockett albertlockett left a comment

Choose a reason for hiding this comment

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

LGTM, this look the right approach. Thanks for the contribution @adamreichold !

@adamreichold
Copy link
Copy Markdown
Contributor Author

Friendly ping. With the positive feedback on the basic approach, I would be happy to fix any remaining technicalities so our project can make use of this via the planned 58.2.0 or 59.0.0 release. Thanks!

@alamb alamb changed the title Wire finish_preserve_values through ArrayBuilder trait Add finish_preserve_values to ArrayBuilder trait Apr 11, 2026
Copy link
Copy Markdown
Contributor

@alamb alamb left a comment

Choose a reason for hiding this comment

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

Thank you @adamreichold and @albertlockett

I took a look and this PR makes sense to me and seems well tested

It is a little unfortnuate that now we end up with three versions of build for all arrays, but I don't have any good suggestion for this other than to make a more generic version that can pass an options struct Array::finish_opts(&self, opts: FinishOptions)

If we find we wand to pass more options to finish in the future, perhaps then we can deprecate finish_preserve_values and add something more like finsh_opt

@adamreichold
Copy link
Copy Markdown
Contributor Author

make a more generic version that can pass an options struct Array::finish_opts(&self, opts: FinishOptions)

The main issue I see here is that the receiver also depends on the options, i.e. &mut self for the consuming modes and &self for the cloning ones.

grafik

Will fix the intra doc links and push if the CI finds no other issues.

To support delta dictionaries for nested builders, this adds a new
method finish_preserve_values to the ArrayBuilder trait and wires
it through to the relevant dictionary and composite builders.
@adamreichold adamreichold force-pushed the finish-preserve-values branch from 9248def to e44dddb Compare April 11, 2026 12:19
@adamreichold
Copy link
Copy Markdown
Contributor Author

Will fix the intra doc links and push if the CI finds no other issues.

Pushed a rebase and the intra doc link fix.

@alamb
Copy link
Copy Markdown
Contributor

alamb commented Apr 13, 2026

The main issue I see here is that the receiver also depends on the options, i.e. &mut self for the consuming modes and &self for the cloning ones.

Yeah, it would be trickey

@alamb alamb merged commit 8b159ad into apache:main Apr 13, 2026
26 checks passed
@alamb
Copy link
Copy Markdown
Contributor

alamb commented Apr 13, 2026

🚀

Rich-T-kid pushed a commit to Rich-T-kid/arrow-rs that referenced this pull request Jun 2, 2026
# Which issue does this PR close?

- Closes apache#9600.

# Rationale for this change

Delta dictionaries require user code to call `finish_preserve_values`
instead of `finish` on the dictionary builders. But this is generally
not possible if those builders are nested within composite builders like
lists, maps or structs. Using the new trait method, user code can call
this generically which has no effect on e.g. primitive builders due to
the default implementation but forwards to this method for composite
ones.

# What changes are included in this PR?

Adds a new method `finish_preserve_values` to `ArrayBuilder` with a
default implementation that forwards to `finish`.

Implements this method for dictionary and composite builders.

# Are these changes tested?

Adds tests where new `finish_preserve_values` inherent methods were
created to check that the correct method on the constituent builders is
called using a shared mock builder `PreserveValuesMock`.

# Are there any user-facing changes?

This adds a new method `finish_preserve_values` to the central
`ArrayBuilder` trait, but it has a default implementation so this should
be backwards compatible.
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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

How to handle delta dictionaries and finish_preserve_values with nested builders

3 participants