Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Simplify Validation/Alignment APIs of ArrayDataBuilder: validate and align #6966

Merged
merged 5 commits into from
Jan 13, 2025

Conversation

alamb
Copy link
Contributor

@alamb alamb commented Jan 10, 2025

Which issue does this PR close?

Rationale for this change

ArrayDataBuilder has two options today:

  1. Validate the data
  2. Ensure buffer alignment

There are three methods today:

  1. build() that does validates but does not ensure alignment
  2. build_unchecked() that neither validates nor ensures alignment
  3. build_aligned() that validates and ensures alignment

@totoroyyb proposed to add the other combination (no validation but aligned) in #6938 as a fourth function build_aligned_unchecked

Instead of a fourth function I think we can use builder flags for a better API

What changes are included in this PR?

  1. Add validate and align fields to ArrayBuilder
  2. Add getters/setters for those fields
  3. Deprecate build_aligned in favor of those flags

Note I chose not to deprecate build_unchecked as that is used in more places in the code so deprecating it would be more API churn

Are there any user-facing changes?

New APIs and deprecated APIs in ArrayDataBuilder

@github-actions github-actions bot added the arrow Changes to the arrow crate label Jan 10, 2025
arrow-data/src/data.rs Outdated Show resolved Hide resolved
Copy link
Contributor

@tustvold tustvold left a comment

Choose a reason for hiding this comment

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

Just some minor nits, the use of an unsafe flag does have the unfortunate property of disconnecting the point of unsafe ""entry" from its "usage", but in this case it is probably fine, and this is really an issue with unsafe in general.

Maybe one day we'll get unsafe fields and that'll make this easier to track.

arrow-data/src/data.rs Outdated Show resolved Hide resolved
arrow-data/src/data.rs Outdated Show resolved Hide resolved
@alamb
Copy link
Contributor Author

alamb commented Jan 11, 2025

Just some minor nits, the use of an unsafe flag does have the unfortunate property of disconnecting the point of unsafe ""entry" from its "usage", but in this case it is probably fine, and this is really an issue with unsafe in general.

Yes I agree this is unforutnate. I will add some comments to make this as explicit as I can (namely that setting the flag to true incorrectly results in undefined behavior)

@@ -1786,6 +1790,10 @@ pub struct ArrayDataBuilder {
offset: usize,
buffers: Vec<Buffer>,
child_data: Vec<ArrayData>,
/// Should buffers be realigned (copying if necessary)? Defaults to false.
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is the point of this PR -- to add these flags to the builder directly and then check them during calls to build()

Ok(data)
}

/// Creates an array data, validating all inputs, and aligning any buffers
#[deprecated(since = "54.1.0", note = "Use ArrayData::with_align_buffers instead")]
Copy link
Contributor Author

Choose a reason for hiding this comment

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

deprecated one API in favor of setting a flag

@tustvold tustvold merged commit 8327493 into apache:main Jan 13, 2025
26 checks passed
svencowart pushed a commit to elastiflow/arrow-rs that referenced this pull request Jan 14, 2025
…d align (apache#6966)

* Simplify ArrayDataBuilder API for validation and alignment

* Update arrow-data/src/data.rs

Co-authored-by: Raphael Taylor-Davies <[email protected]>

* Rename functions for consistency

* Improve documentation

---------

Co-authored-by: Raphael Taylor-Davies <[email protected]>
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.

2 participants