-
Notifications
You must be signed in to change notification settings - Fork 823
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
Encapsulate View
logic for GenericByteViewArray
#5619
Closed
Closed
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,7 +19,7 @@ use crate::builder::ArrayBuilder; | |
use crate::types::{BinaryViewType, ByteViewType, StringViewType}; | ||
use crate::{ArrayRef, GenericByteViewArray}; | ||
use arrow_buffer::{Buffer, BufferBuilder, NullBufferBuilder, ScalarBuffer}; | ||
use arrow_data::ByteView; | ||
use arrow_data::{OffsetViewBuilder, OwnedView}; | ||
|
||
use std::any::Any; | ||
use std::marker::PhantomData; | ||
|
@@ -72,35 +72,28 @@ impl<T: ByteViewType + ?Sized> GenericByteViewBuilder<T> { | |
#[inline] | ||
pub fn append_value(&mut self, value: impl AsRef<T::Native>) { | ||
let v: &[u8] = value.as_ref().as_ref(); | ||
let length: u32 = v.len().try_into().unwrap(); | ||
if length <= 12 { | ||
let mut view_buffer = [0; 16]; | ||
view_buffer[0..4].copy_from_slice(&length.to_le_bytes()); | ||
view_buffer[4..4 + v.len()].copy_from_slice(v); | ||
self.views_builder.append(u128::from_le_bytes(view_buffer)); | ||
self.null_buffer_builder.append_non_null(); | ||
return; | ||
} | ||
|
||
let required_cap = self.in_progress.len() + v.len(); | ||
if self.in_progress.capacity() < required_cap { | ||
let in_progress = Vec::with_capacity(v.len().max(self.block_size as usize)); | ||
let flushed = std::mem::replace(&mut self.in_progress, in_progress); | ||
if !flushed.is_empty() { | ||
assert!(self.completed.len() < u32::MAX as usize); | ||
self.completed.push(flushed.into()); | ||
let view: u128 = match OwnedView::from(v) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think the construction is now much clearer and encapsulated -- the bit manipulation is handled by |
||
OwnedView::Inline(view) => view, | ||
OwnedView::Offset(view) => { | ||
let required_cap = self.in_progress.len() + v.len(); | ||
if self.in_progress.capacity() < required_cap { | ||
let in_progress = Vec::with_capacity(v.len().max(self.block_size as usize)); | ||
let flushed = std::mem::replace(&mut self.in_progress, in_progress); | ||
if !flushed.is_empty() { | ||
assert!(self.completed.len() < u32::MAX as usize); | ||
self.completed.push(flushed.into()); | ||
} | ||
}; | ||
let builder = OffsetViewBuilder::from(view) | ||
.with_offset(self.in_progress.len() as u32) | ||
.with_buffer_index(self.completed.len() as u32); | ||
// copy the actual data into the in_progress buffer | ||
self.in_progress.extend_from_slice(v); | ||
builder.into() | ||
} | ||
}; | ||
let offset = self.in_progress.len() as u32; | ||
self.in_progress.extend_from_slice(v); | ||
|
||
let view = ByteView { | ||
length, | ||
prefix: u32::from_le_bytes(v[0..4].try_into().unwrap()), | ||
buffer_index: self.completed.len() as u32, | ||
offset, | ||
}; | ||
self.views_builder.append(view.into()); | ||
self.views_builder.append(view); | ||
self.null_buffer_builder.append_non_null(); | ||
} | ||
|
||
|
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
moved to
View