-
Notifications
You must be signed in to change notification settings - Fork 34
/
Copy pathdata_chunk_adaptor.rs
77 lines (66 loc) · 2.05 KB
/
data_chunk_adaptor.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
use duckdb::core::{ArrayVector, DataChunkHandle, FlatVector, ListVector, StructVector};
use duckdb::vtab::arrow::WritableVector;
use vortex_dtype::FieldNames;
pub struct DataChunkHandleSlice<'a> {
chunk: &'a mut DataChunkHandle,
column_index: usize,
}
/// A wrapper around a [`DataChunkHandle`] that extra info to create a vortex array
pub struct NamedDataChunk<'a> {
pub chunk: &'a DataChunkHandle,
pub nullable: Option<&'a [bool]>,
pub names: Option<FieldNames>,
}
/// Since duckdb vectors only have a capacity, not a size this wrapper exists to allow the creation
/// of a vortex array from a duckdb vector.
/// Nullability is also included since the duckdb doesn't have this info its on the table.
pub struct SizedFlatVector {
pub vector: FlatVector,
pub nullable: bool,
pub len: usize,
}
impl<'a> DataChunkHandleSlice<'a> {
pub fn new(chunk: &'a mut DataChunkHandle, column_index: usize) -> Self {
Self {
chunk,
column_index,
}
}
}
impl WritableVector for DataChunkHandleSlice<'_> {
fn array_vector(&mut self) -> ArrayVector {
self.chunk.array_vector(self.column_index)
}
fn flat_vector(&mut self) -> FlatVector {
self.chunk.flat_vector(self.column_index)
}
fn struct_vector(&mut self) -> StructVector {
self.chunk.struct_vector(self.column_index)
}
fn list_vector(&mut self) -> ListVector {
self.chunk.list_vector(self.column_index)
}
}
impl<'a> NamedDataChunk<'a> {
pub fn from_chunk(chunk: &'a DataChunkHandle) -> Self {
Self {
chunk,
nullable: None,
names: None,
}
}
pub fn named_chunk(chunk: &'a DataChunkHandle, names: FieldNames) -> Self {
Self {
chunk,
nullable: None,
names: Some(names),
}
}
pub fn new(chunk: &'a DataChunkHandle, nullable: &'a [bool], names: FieldNames) -> Self {
Self {
chunk,
nullable: Some(nullable),
names: Some(names),
}
}
}