Skip to content

Commit 94b0d4f

Browse files
committed
handle deeper list nesting
1 parent fe81583 commit 94b0d4f

File tree

1 file changed

+20
-30
lines changed

1 file changed

+20
-30
lines changed

kernel/src/engine/arrow_utils.rs

+20-30
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,14 @@ impl ReorderIndex {
4747
}
4848
}
4949

50+
fn set_index(&mut self, target_index: usize) {
51+
match self {
52+
ReorderIndex::Child { ref mut index, .. } => *index = target_index,
53+
ReorderIndex::Index { ref mut index } => *index = target_index,
54+
ReorderIndex::Null { ref mut index, .. } => *index = target_index,
55+
}
56+
}
57+
5058
/// check if this indexing is ordered. an `Index` variant is ordered by definition. a `Null`
5159
/// variant is not because if we have a `Null` variant we need to do work in
5260
/// reorder_struct_array to insert the null col
@@ -153,37 +161,19 @@ fn get_indices(
153161
// see comment above in struct match arm
154162
parquet_offset += parquet_advance - 1;
155163
found_fields.insert(requested_field.name());
156-
// we have to recurse to find the type, but for reordering a list we
157-
// only need a child reordering if the inner type is a struct
158-
if let ArrowDataType::Struct(_) = list_field.data_type() {
159-
if children.len() != 1 {
160-
return Err(
161-
Error::generic(
162-
"List call should not have generated more than one reorder index"
163-
)
164-
);
165-
}
166-
// safety, checked that we have 1 element
167-
let mut children = children.into_iter().next().unwrap();
168-
// the index is wrong though, as it's the index from the inner
169-
// schema. Adjust it to be our index
170-
if let ReorderIndex::Child {
171-
index: ref mut child_index,
172-
..
173-
} = children
174-
{
175-
*child_index = index;
176-
} else {
177-
return Err(
178-
Error::generic(
179-
"List call should have returned a ReorderIndex::Child variant"
180-
)
181-
);
182-
}
183-
reorder_indices.push(children);
184-
} else {
185-
reorder_indices.push(ReorderIndex::Index { index });
164+
if children.len() != 1 {
165+
return Err(
166+
Error::generic(
167+
"List call should not have generated more than one reorder index"
168+
)
169+
);
186170
}
171+
// safety, checked that we have 1 element
172+
let mut children = children.into_iter().next().unwrap();
173+
// the index is wrong, as it's the index from the inner schema. Adjust
174+
// it to be our index
175+
children.set_index(index);
176+
reorder_indices.push(children);
187177
}
188178
_ => {
189179
return Err(Error::unexpected_column_type(list_field.name()));

0 commit comments

Comments
 (0)