vortex_array/arrays/extension/vtable/
mod.rs1mod array;
5mod canonical;
6mod kernel;
7mod operations;
8mod validity;
9mod visitor;
10
11use kernel::PARENT_KERNELS;
12use vortex_dtype::DType;
13use vortex_error::VortexExpect;
14use vortex_error::VortexResult;
15use vortex_error::vortex_bail;
16use vortex_error::vortex_ensure;
17use vortex_session::VortexSession;
18
19use crate::ArrayRef;
20use crate::EmptyMetadata;
21use crate::ExecutionCtx;
22use crate::arrays::extension::ExtensionArray;
23use crate::arrays::extension::compute::rules::PARENT_RULES;
24use crate::buffer::BufferHandle;
25use crate::serde::ArrayChildren;
26use crate::vtable;
27use crate::vtable::ArrayId;
28use crate::vtable::VTable;
29use crate::vtable::ValidityVTableFromChild;
30
31vtable!(Extension);
32
33impl VTable for ExtensionVTable {
34 type Array = ExtensionArray;
35
36 type Metadata = EmptyMetadata;
37
38 type ArrayVTable = Self;
39 type OperationsVTable = Self;
40 type ValidityVTable = ValidityVTableFromChild;
41 type VisitorVTable = Self;
42
43 fn id(_array: &Self::Array) -> ArrayId {
44 Self::ID
45 }
46
47 fn metadata(_array: &ExtensionArray) -> VortexResult<Self::Metadata> {
48 Ok(EmptyMetadata)
49 }
50
51 fn serialize(_metadata: Self::Metadata) -> VortexResult<Option<Vec<u8>>> {
52 Ok(Some(vec![]))
53 }
54
55 fn deserialize(
56 _bytes: &[u8],
57 _dtype: &DType,
58 _len: usize,
59 _buffers: &[BufferHandle],
60 _session: &VortexSession,
61 ) -> VortexResult<Self::Metadata> {
62 Ok(EmptyMetadata)
63 }
64
65 fn build(
66 dtype: &DType,
67 len: usize,
68 _metadata: &Self::Metadata,
69 _buffers: &[BufferHandle],
70 children: &dyn ArrayChildren,
71 ) -> VortexResult<ExtensionArray> {
72 let DType::Extension(ext_dtype) = dtype else {
73 vortex_bail!("Not an extension DType");
74 };
75 if children.len() != 1 {
76 vortex_bail!("Expected 1 child, got {}", children.len());
77 }
78 let storage = children.get(0, ext_dtype.storage_dtype(), len)?;
79 Ok(ExtensionArray::new(ext_dtype.clone(), storage))
80 }
81
82 fn with_children(array: &mut Self::Array, children: Vec<ArrayRef>) -> VortexResult<()> {
83 vortex_ensure!(
84 children.len() == 1,
85 "ExtensionArray expects exactly 1 child (storage), got {}",
86 children.len()
87 );
88 array.storage = children
89 .into_iter()
90 .next()
91 .vortex_expect("children length already validated");
92 Ok(())
93 }
94
95 fn execute(array: &Self::Array, _ctx: &mut ExecutionCtx) -> VortexResult<ArrayRef> {
96 Ok(array.to_array())
97 }
98
99 fn reduce_parent(
100 array: &Self::Array,
101 parent: &ArrayRef,
102 child_idx: usize,
103 ) -> VortexResult<Option<ArrayRef>> {
104 PARENT_RULES.evaluate(array, parent, child_idx)
105 }
106
107 fn execute_parent(
108 array: &Self::Array,
109 parent: &ArrayRef,
110 child_idx: usize,
111 ctx: &mut ExecutionCtx,
112 ) -> VortexResult<Option<ArrayRef>> {
113 PARENT_KERNELS.execute(array, parent, child_idx, ctx)
114 }
115}
116
117#[derive(Debug)]
118pub struct ExtensionVTable;
119
120impl ExtensionVTable {
121 pub const ID: ArrayId = ArrayId::new_ref("vortex.ext");
122}