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

Support list_view_array & large_list_view layout and basic construction #5576

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1,256 changes: 1,256 additions & 0 deletions arrow-array/src/array/list_view_array.rs

Large diffs are not rendered by default.

37 changes: 35 additions & 2 deletions arrow-array/src/array/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,13 +65,14 @@ mod union_array;
pub use union_array::*;

mod run_array;

pub use run_array::*;

mod byte_view_array;

pub use byte_view_array::*;

mod list_view_array;
pub use list_view_array::*;

/// An array in the [arrow columnar format](https://arrow.apache.org/docs/format/Columnar.html)
pub trait Array: std::fmt::Debug + Send + Sync {
/// Returns the array as [`Any`] so that it can be
Expand Down Expand Up @@ -519,6 +520,12 @@ impl<OffsetSize: OffsetSizeTrait> PartialEq for GenericListArray<OffsetSize> {
}
}

impl<OffsetSize: OffsetSizeTrait> PartialEq for GenericListViewArray<OffsetSize> {
fn eq(&self, other: &Self) -> bool {
self.to_data().eq(&other.to_data())
}
}

impl PartialEq for MapArray {
fn eq(&self, other: &Self) -> bool {
self.to_data().eq(&other.to_data())
Expand Down Expand Up @@ -606,7 +613,9 @@ pub fn make_array(data: ArrayData) -> ArrayRef {
DataType::LargeUtf8 => Arc::new(LargeStringArray::from(data)) as ArrayRef,
DataType::Utf8View => Arc::new(StringViewArray::from(data)) as ArrayRef,
DataType::List(_) => Arc::new(ListArray::from(data)) as ArrayRef,
DataType::ListView(_) => Arc::new(ListViewArray::from(data)) as ArrayRef,
DataType::LargeList(_) => Arc::new(LargeListArray::from(data)) as ArrayRef,
DataType::LargeListView(_) => Arc::new(LargeListViewArray::from(data)) as ArrayRef,
DataType::Struct(_) => Arc::new(StructArray::from(data)) as ArrayRef,
DataType::Map(_, _) => Arc::new(MapArray::from(data)) as ArrayRef,
DataType::Union(_, _) => Arc::new(UnionArray::from(data)) as ArrayRef,
Expand Down Expand Up @@ -687,6 +696,30 @@ unsafe fn get_offsets<O: ArrowNativeType>(data: &ArrayData) -> OffsetBuffer<O> {
}
}

/// Helper function that gets list view offset from an [`ArrayData`]
///
/// # Safety
///
/// ArrayData must contain a valid [`ScalarBuffer`] as its first buffer
fn get_view_offsets<O: ArrowNativeType>(data: &ArrayData) -> ScalarBuffer<O> {
match data.is_empty() && data.buffers()[0].is_empty() {
true => ScalarBuffer::new_empty(),
false => ScalarBuffer::new(data.buffers()[0].clone(), data.offset(), data.len() + 1),
}
}

/// Helper function that gets list view size from an [`ArrayData`]
///
/// # Safety
///
/// ArrayData must contain a valid [`ScalarBuffer`] as its second buffer
fn get_view_sizes<O: ArrowNativeType>(data: &ArrayData) -> ScalarBuffer<O> {
match data.is_empty() && data.buffers()[1].is_empty() {
true => ScalarBuffer::new_empty(),
false => ScalarBuffer::new(data.buffers()[1].clone(), data.offset(), data.len()),
}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

These methods aren't necessary, get_offsets exists because OffsetBuffer must be non-empty


/// Helper function for printing potentially long arrays.
fn print_long_array<A, F>(array: &A, f: &mut std::fmt::Formatter, print_item: F) -> std::fmt::Result
where
Expand Down
2 changes: 1 addition & 1 deletion arrow-array/src/builder/generic_list_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -548,7 +548,7 @@ mod tests {
}

#[test]
fn test_boxed_primitive_aray_builder() {
fn test_boxed_primitive_array_builder() {
let values_builder = make_builder(&DataType::Int32, 5);
let mut builder = ListBuilder::new(values_builder);

Expand Down
Loading
Loading