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

Return Buffers from ArrayData::buffers instead of slice (#1799) #3783

Merged
merged 2 commits into from
Mar 2, 2023

Conversation

tustvold
Copy link
Contributor

@tustvold tustvold commented Mar 1, 2023

Which issue does this PR close?

Part of #1799
Relates to #1176

Rationale for this change

Currently ArrayData stores a Vec<Buffer> and this allows it to return &[Buffer]. As we move to structured array data (#1799) implementations will no longer store a contiguous array of Buffer instead storing a selection of ScalarBuffer. This PR adds a new Buffers struct to smooth over this transition, and allow code to be slowly migrated.

What changes are included in this PR?

Are there any user-facing changes?

@tustvold tustvold added the api-change Changes to the arrow API label Mar 1, 2023
@github-actions github-actions bot added the arrow Changes to the arrow crate label Mar 1, 2023
type Output = &'a Buffer;

#[inline]
fn index(&self, index: usize) -> &Self::Output {
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 somewhat unfortunate, having to return &&Buffer but we need to return a borrow with a 'a lifetime otherwise the following code doesn't compile.

let buffer = array.data().buffers()[0];

Copy link
Member

Choose a reason for hiding this comment

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

I tried changing it to type Output = Buffer and got tons of errors. The one you mentioned can be fixed by introducing a temp variable for array.data().buffers() (very verbose...). But I don't know how to fix it if something else references buffer...

So I'm ok with &&Buffer here. Not sure if it's the only way but it does make other things easier (to me).

type Output = &'a Buffer;

#[inline]
fn index(&self, index: usize) -> &Self::Output {
Copy link
Member

Choose a reason for hiding this comment

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

I tried changing it to type Output = Buffer and got tons of errors. The one you mentioned can be fixed by introducing a temp variable for array.data().buffers() (very verbose...). But I don't know how to fix it if something else references buffer...

So I'm ok with &&Buffer here. Not sure if it's the only way but it does make other things easier (to me).

Copy link
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.

Seems reasonable to me. Thank you @waynexia for the review as well

pub struct Buffers<'a>([Option<&'a Buffer>; 2]);

impl<'a> Buffers<'a> {
/// Temporary will be removed once ArrayData does not store `Vec<Buffer>` directly (#3769)
Copy link
Contributor

Choose a reason for hiding this comment

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

Will this whole struct be temporary or just this method?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Just this method

@tustvold tustvold merged commit 231ae9b into apache:master Mar 2, 2023
@ursabot
Copy link

ursabot commented Mar 2, 2023

Benchmark runs are scheduled for baseline = eff058f and contender = 231ae9b. 231ae9b is a master commit associated with this PR. Results will be available as each benchmark for each run completes.
Conbench compare runs links:
[Skipped ⚠️ Benchmarking of arrow-rs-commits is not supported on ec2-t3-xlarge-us-east-2] ec2-t3-xlarge-us-east-2
[Skipped ⚠️ Benchmarking of arrow-rs-commits is not supported on test-mac-arm] test-mac-arm
[Skipped ⚠️ Benchmarking of arrow-rs-commits is not supported on ursa-i9-9960x] ursa-i9-9960x
[Skipped ⚠️ Benchmarking of arrow-rs-commits is not supported on ursa-thinkcentre-m75q] ursa-thinkcentre-m75q
Buildkite builds:
Supported benchmarks:
ec2-t3-xlarge-us-east-2: Supported benchmark langs: Python, R. Runs only benchmarks with cloud = True
test-mac-arm: Supported benchmark langs: C++, Python, R
ursa-i9-9960x: Supported benchmark langs: Python, R, JavaScript
ursa-thinkcentre-m75q: Supported benchmark langs: C++, Java

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api-change Changes to the arrow API arrow Changes to the arrow crate
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants