Skip to content

Commit d133028

Browse files
committed
fixup
1 parent 62433f0 commit d133028

File tree

6 files changed

+38
-22
lines changed

6 files changed

+38
-22
lines changed

vortex-duckdb/src/convert/array/mod.rs

+27-17
Original file line numberDiff line numberDiff line change
@@ -4,54 +4,64 @@ use duckdb::vtab::arrow::{
44
};
55
use vortex_array::arrays::StructArray;
66
use vortex_array::arrow::{FromArrowArray, IntoArrowArray};
7-
use vortex_array::builders::ArrayBuilder;
87
use vortex_array::validity::Validity;
9-
use vortex_array::{Array, ArrayRef, Canonical};
10-
use vortex_error::VortexResult;
8+
use vortex_array::{Array, ArrayRef};
9+
use vortex_dtype::FieldNames;
10+
use vortex_error::{VortexResult, vortex_err};
1111

1212
pub trait ToDuckDB {
1313
fn to_duckdb(&self, chunk: &mut dyn WritableVector) -> VortexResult<()>;
1414
}
1515

1616
impl ToDuckDB for ArrayRef {
1717
fn to_duckdb(&self, chunk: &mut dyn WritableVector) -> VortexResult<()> {
18-
write_arrow_array_to_vector(&self.clone().into_arrow_preferred()?, chunk)?;
18+
write_arrow_array_to_vector(&self.clone().into_arrow_preferred()?, chunk)
19+
.map_err(|e| vortex_err!("Failed to convert vrotex duckdb array: {}", e.to_string()))
1920
}
2021
}
2122

22-
struct SizedFlatVector<'a> {
23-
pub vector: &'a FlatVector,
23+
struct NamedDataChunk<'a> {
24+
pub chunk: &'a DataChunkHandle,
25+
pub names: FieldNames,
26+
}
27+
28+
struct SizedFlatVector {
29+
pub vector: FlatVector,
2430
pub len: usize,
2531
}
2632

2733
pub trait FromDuckDB<V> {
28-
fn from_duckdb(vector: &V) -> VortexResult<ArrayRef>;
34+
fn from_duckdb(vector: V) -> VortexResult<ArrayRef>;
2935
}
3036

31-
impl FromDuckDB<DataChunkHandle> for ArrayRef {
32-
fn from_duckdb(chunk: &DataChunkHandle) -> VortexResult<ArrayRef> {
37+
impl<'a> FromDuckDB<&'a NamedDataChunk<'a>> for ArrayRef {
38+
fn from_duckdb(named_chunk: &'a NamedDataChunk<'a>) -> VortexResult<ArrayRef> {
39+
let chunk = &named_chunk.chunk;
40+
let names = &named_chunk.names;
3341
let len = chunk.len();
3442

3543
let columns = (0..chunk.num_columns())
3644
.map(|i| {
3745
let vector = chunk.flat_vector(i);
38-
ArrayRef::from_duckdb(&SizedFlatVector {
39-
vector: &vector,
40-
len,
41-
})
46+
let array = ArrayRef::from_duckdb(SizedFlatVector { vector, len })?;
47+
// Figure out the column names
48+
Ok((names[i].clone(), array))
4249
})
4350
.collect::<VortexResult<Vec<_>>>()?;
4451

45-
let (names, arrays) = columns.iter().unzip();
52+
let (names, arrays): (Vec<_>, Vec<_>) = columns.into_iter().unzip();
4653

4754
// TODO(joe): extract validity
48-
StructArray::try_new(names, arrays, len, Validity::AllValid).map(StructArray::to_array)
55+
StructArray::try_new(names.into(), arrays, len, Validity::AllValid)
56+
.map(StructArray::into_array)
4957
}
5058
}
5159

5260
impl FromDuckDB<SizedFlatVector> for ArrayRef {
53-
fn from_duckdb(vector: &SizedFlatVector) -> VortexResult<ArrayRef> {
54-
let arrow_arr = flat_vector_to_arrow_array(&mut vector.vector.clone(), vector.len)?;
61+
fn from_duckdb(mut sized_vector: SizedFlatVector) -> VortexResult<ArrayRef> {
62+
let len = sized_vector.len;
63+
let arrow_arr = flat_vector_to_arrow_array(&mut sized_vector.vector, len)
64+
.map_err(|e| vortex_err!("Failed to convert duckdb array to vortex: {}", e))?;
5565
Ok(ArrayRef::from_arrow(arrow_arr, true))
5666
}
5767
}

vortex-duckdb/src/convert/mod.rs

+3
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,5 @@
11
mod array;
22
mod types;
3+
4+
pub use array::{FromDuckDB, ToDuckDB};
5+
pub use types::{FromDuckDBType, ToDuckDBType};

vortex-duckdb/src/convert/types/from.rs

+2-4
Original file line numberDiff line numberDiff line change
@@ -55,14 +55,12 @@ fn from_duckdb_list(list: LogicalTypeHandle) -> DType {
5555
}
5656

5757
fn from_duckdb_struct(struct_: LogicalTypeHandle) -> StructDType {
58-
struct_
59-
.num_children()
60-
.into_iter()
58+
(0..struct_.num_children())
6159
.map(|i| {
6260
// TODO: is there struct field nullability
6361
let child_nullability = Nullable;
6462
let child_name = struct_.child_name(i);
65-
let child_type = FromDuckDBType::from_duckdb(struct_.child(i), child_nullability);
63+
let child_type = DType::from_duckdb(struct_.child(i), child_nullability);
6664
(child_name, child_type)
6765
})
6866
.collect()
+3
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,5 @@
11
mod from;
22
mod to;
3+
4+
pub use from::FromDuckDBType;
5+
pub use to::ToDuckDBType;

vortex-duckdb/src/convert/types/to.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use duckdb::core::{LogicalTypeHandle, LogicalTypeId};
22
use vortex_dtype::{DType, PType};
3-
use vortex_error::{VortexResult, vortex_bail, vortex_err};
3+
use vortex_error::{VortexResult, vortex_bail};
44

55
pub trait ToDuckDBType {
66
fn to_duckdb_type(&self) -> VortexResult<LogicalTypeHandle>;

vortex-duckdb/src/lib.rs

+2
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
11
mod convert;
2+
3+
pub use convert::{FromDuckDB, FromDuckDBType, ToDuckDB, ToDuckDBType};

0 commit comments

Comments
 (0)