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

Handle offset consistently for StructArray (#1750) #2085

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all 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
2 changes: 1 addition & 1 deletion arrow/src/array/array_struct.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ impl From<ArrayData> for StructArray {
let boxed_fields = data
.child_data()
.iter()
.map(|cd| make_array(cd.clone()))
.map(|cd| make_array(cd.slice(data.offset(), data.len())))
.collect();

Self { data, boxed_fields }
Expand Down
33 changes: 6 additions & 27 deletions arrow/src/array/data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -493,36 +493,15 @@ impl ArrayData {
pub fn slice(&self, offset: usize, length: usize) -> ArrayData {
assert!((offset + length) <= self.len());

if let DataType::Struct(_) = self.data_type() {
// Slice into children
let new_offset = self.offset + offset;
let new_data = ArrayData {
data_type: self.data_type().clone(),
len: length,
null_count: count_nulls(self.null_buffer(), new_offset, length),
offset: new_offset,
buffers: self.buffers.clone(),
// Slice child data, to propagate offsets down to them
child_data: self
.child_data()
.iter()
.map(|data| data.slice(offset, length))
.collect(),
null_bitmap: self.null_bitmap().cloned(),
};

new_data
} else {
let mut new_data = self.clone();
let mut new_data = self.clone();

new_data.len = length;
new_data.offset = offset + self.offset;
new_data.len = length;
new_data.offset = offset + self.offset;

new_data.null_count =
count_nulls(new_data.null_buffer(), new_data.offset, new_data.len);
new_data.null_count =
count_nulls(new_data.null_buffer(), new_data.offset, new_data.len);

new_data
}
new_data
}

/// Returns the `buffer` as a slice of type `T` starting at self.offset
Expand Down
8 changes: 7 additions & 1 deletion arrow/src/array/equal/structure.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,13 @@ fn equal_child_values(
.iter()
.zip(rhs.child_data())
.all(|(lhs_values, rhs_values)| {
equal_range(lhs_values, rhs_values, lhs_start, rhs_start, len)
equal_range(
lhs_values,
rhs_values,
lhs_start + lhs.offset(),
rhs_start + rhs.offset(),
len,
)
})
}

Expand Down
15 changes: 7 additions & 8 deletions arrow/src/array/transform/structure.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,16 @@ use crate::array::ArrayData;
use super::{Extend, _MutableArrayData};

pub(super) fn build_extend(array: &ArrayData) -> Extend {
let offset = array.offset();
if array.null_count() == 0 {
Box::new(
move |mutable: &mut _MutableArrayData,
index: usize,
start: usize,
len: usize| {
mutable
.child_data
.iter_mut()
.for_each(|child| child.extend(index, start, start + len))
mutable.child_data.iter_mut().for_each(|child| {
child.extend(index, offset + start, offset + start + len)
})
},
)
} else {
Expand All @@ -40,10 +40,9 @@ pub(super) fn build_extend(array: &ArrayData) -> Extend {
len: usize| {
(start..start + len).for_each(|i| {
if array.is_valid(i) {
mutable
.child_data
.iter_mut()
.for_each(|child| child.extend(index, i, i + 1))
mutable.child_data.iter_mut().for_each(|child| {
child.extend(index, offset + i, offset + i + 1)
})
} else {
mutable
.child_data
Expand Down