Skip to content

Commit 4b02a60

Browse files
committed
Add more arrow execution
Signed-off-by: Nicholas Gates <[email protected]>
1 parent d991be9 commit 4b02a60

File tree

5 files changed

+42
-33
lines changed

5 files changed

+42
-33
lines changed

vortex-array/src/array/mod.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
mod visitor;
55

66
use std::any::Any;
7-
use std::any::type_name;
87
use std::fmt::Debug;
98
use std::fmt::Formatter;
109
use std::hash::Hash;

vortex-array/src/arrays/struct_/array.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -344,6 +344,10 @@ impl StructArray {
344344
Ok(unsafe { Self::new_unchecked(fields, dtype, length, validity) })
345345
}
346346

347+
pub fn into_fields(self) -> Vec<ArrayRef> {
348+
self.fields.to_vec()
349+
}
350+
347351
pub fn from_fields<N: AsRef<str>>(items: &[(N, ArrayRef)]) -> VortexResult<Self> {
348352
Self::try_from_iter(items.iter().map(|(a, b)| (a, b.to_array())))
349353
}

vortex-array/src/arrow/executor/list.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ fn list_to_list<O: OffsetSizeTrait + NativePType>(
8484

8585
let elements = array
8686
.elements()
87+
.clone()
8788
.execute_arrow(elements_field.data_type(), session)?;
8889
vortex_ensure!(
8990
elements_field.is_nullable() || elements.null_count() == 0,

vortex-array/src/arrow/executor/struct_.rs

Lines changed: 34 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ use vortex_error::VortexResult;
1111
use vortex_error::vortex_ensure;
1212
use vortex_session::VortexSession;
1313

14+
use crate::Array;
1415
use crate::ArrayRef;
1516
use crate::arrays::StructVTable;
1617
use crate::arrow::ArrowArrayExecutor;
@@ -25,36 +26,40 @@ pub(super) fn to_arrow_struct(
2526
let validity = array.validity_mask();
2627

2728
let mut field_arrays = Vec::with_capacity(fields.len());
28-
if let Some(array) = array.as_opt::<StructVTable>() {
29-
// If the array is already a struct type, then we can convert each field.
30-
for (field, child) in fields.iter().zip_eq(array.fields().iter()) {
31-
let field_array = child.execute_arrow(field.data_type(), session)?;
32-
vortex_ensure!(
33-
field.is_nullable() || field_array.null_count() == 0,
34-
"Cannot convert field '{}' to non-nullable Arrow field because it contains nulls",
35-
field.name()
36-
);
37-
field_arrays.push(field_array);
29+
30+
match array.try_into::<StructVTable>() {
31+
Ok(array) => {
32+
// If the array is already a struct type, then we can convert each field.
33+
for (field, child) in fields.iter().zip_eq(array.into_fields().into_iter()) {
34+
let field_array = child.execute_arrow(field.data_type(), session)?;
35+
vortex_ensure!(
36+
field.is_nullable() || field_array.null_count() == 0,
37+
"Cannot convert field '{}' to non-nullable Arrow field because it contains nulls",
38+
field.name()
39+
);
40+
field_arrays.push(field_array);
41+
}
3842
}
39-
} else {
40-
// Otherwise, we have some options:
41-
// 1. Use get_item expression to extract each field? This is a bit sad because get_item
42-
// will perform the validity masking again.
43-
// 2. Execute a full struct vector. But this may do unnecessary work on fields that may
44-
// have a more direct conversion to the desired Arrow field type.
45-
// 3. Something else?
46-
//
47-
// For now, we go with option 1. Although we really ought to figure out CSE for this.
48-
for field in fields.iter() {
49-
let field_array = array
50-
.get_item(field.name().as_str())?
51-
.execute_arrow(field.data_type(), session)?;
52-
vortex_ensure!(
53-
field.is_nullable() || field_array.null_count() == 0,
54-
"Cannot convert field '{}' to non-nullable Arrow field because it contains nulls",
55-
field.name()
56-
);
57-
field_arrays.push(field_array);
43+
Err(array) => {
44+
// Otherwise, we have some options:
45+
// 1. Use get_item expression to extract each field? This is a bit sad because get_item
46+
// will perform the validity masking again.
47+
// 2. Execute a full struct vector. But this may do unnecessary work on fields that may
48+
// have a more direct conversion to the desired Arrow field type.
49+
// 3. Something else?
50+
//
51+
// For now, we go with option 1. Although we really ought to figure out CSE for this.
52+
for field in fields.iter() {
53+
let field_array = array
54+
.get_item(field.name().as_str())?
55+
.execute_arrow(field.data_type(), session)?;
56+
vortex_ensure!(
57+
field.is_nullable() || field_array.null_count() == 0,
58+
"Cannot convert field '{}' to non-nullable Arrow field because it contains nulls",
59+
field.name()
60+
);
61+
field_arrays.push(field_array);
62+
}
5863
}
5964
}
6065

vortex-array/src/arrow/executor/temporal.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ pub(super) fn to_arrow_temporal(
9797
}
9898

9999
fn to_temporal<T: ArrowTemporalType>(
100-
array: &ArrayRef,
100+
array: ArrayRef,
101101
session: &VortexSession,
102102
) -> VortexResult<ArrowArrayRef>
103103
where
@@ -108,7 +108,7 @@ where
108108
}
109109

110110
fn to_arrow_timestamp<T: ArrowTimestampType>(
111-
array: &ArrayRef,
111+
array: ArrayRef,
112112
arrow_tz: &Option<Arc<str>>,
113113
session: &VortexSession,
114114
) -> VortexResult<ArrowArrayRef>
@@ -121,7 +121,7 @@ where
121121
}
122122

123123
fn to_arrow_temporal_primitive<T: ArrowTemporalType>(
124-
array: &ArrayRef,
124+
array: ArrayRef,
125125
session: &VortexSession,
126126
) -> VortexResult<ArrowPrimitiveArray<T>>
127127
where

0 commit comments

Comments
 (0)