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

Add Vec-inspired APIs to BufferBuilder #1850

Closed
tustvold opened this issue Jun 11, 2022 · 0 comments · Fixed by #1860
Closed

Add Vec-inspired APIs to BufferBuilder #1850

tustvold opened this issue Jun 11, 2022 · 0 comments · Fixed by #1860
Assignees
Labels
arrow Changes to the arrow crate enhancement Any new improvement worthy of a entry in the changelog

Comments

@tustvold
Copy link
Contributor

Is your feature request related to a problem or challenge? Please describe what you are trying to do.

BufferBuilder is effectively a Vec<T: ArrowNativeType> that can be converted to Buffer without needing to copy. This is an incredibly useful abstraction for incrementally building and mutating data in place, prior to freezing it for hand-off to other systems.

Unfortunately it is currently lacking some relatively minor functionality to enable this use-case. In particular access to the data that has been already written. The parquet crate currently rolls its own ScalarBuffer to work around this, but as described in #1849 it would be nice to avoid this duplication.

Describe the solution you'd like

Add the following APIs to BufferBuilder

fn as_slice(&self) -> &[T] {
    unsafe { std::slice::from_raw_parts(self.buffer.as_ptr(), self.len) }
}

fn as_slice_mut(&mut self) -> &mut [T] {
    unsafe { std::slice::from_raw_parts_mut(self.buffer.as_ptr_mut(), self.len) }
}

fn truncate(&mut self, len: usize) {}

fn extend_zeroed(&mut self, len: usize) {}

Describe alternatives you've considered

We could not do this

Additional context

@tustvold tustvold added the enhancement Any new improvement worthy of a entry in the changelog label Jun 11, 2022
@tustvold tustvold self-assigned this Jun 11, 2022
tustvold added a commit to tustvold/arrow-rs that referenced this issue Jun 13, 2022
tustvold added a commit to tustvold/arrow-rs that referenced this issue Jun 13, 2022
tustvold added a commit to tustvold/arrow-rs that referenced this issue Jun 13, 2022
@alamb alamb changed the title Add Vec-inspired APIs to BufferBuilder Add Vec-inspired APIs to BufferBuilder Jun 23, 2022
@alamb alamb changed the title Add Vec-inspired APIs to BufferBuilder Add Vec-inspired APIs to BufferBuilder Jun 23, 2022
@alamb alamb added the arrow Changes to the arrow crate label Jun 23, 2022
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 enhancement Any new improvement worthy of a entry in the changelog
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants