vortex_array/arrays/extension/vtable/
mod.rs1mod array;
5mod canonical;
6mod operations;
7mod validity;
8mod visitor;
9
10use vortex_buffer::BufferHandle;
11use vortex_dtype::DType;
12use vortex_error::VortexResult;
13use vortex_error::vortex_bail;
14use vortex_vector::Vector;
15
16use crate::EmptyMetadata;
17use crate::arrays::extension::ExtensionArray;
18use crate::execution::ExecutionCtx;
19use crate::serde::ArrayChildren;
20use crate::vtable;
21use crate::vtable::ArrayId;
22use crate::vtable::ArrayVTable;
23use crate::vtable::ArrayVTableExt;
24use crate::vtable::NotSupported;
25use crate::vtable::VTable;
26use crate::vtable::ValidityVTableFromChild;
27
28vtable!(Extension);
29
30impl VTable for ExtensionVTable {
31 type Array = ExtensionArray;
32
33 type Metadata = EmptyMetadata;
34
35 type ArrayVTable = Self;
36 type CanonicalVTable = Self;
37 type OperationsVTable = Self;
38 type ValidityVTable = ValidityVTableFromChild;
39 type VisitorVTable = Self;
40 type ComputeVTable = NotSupported;
41 type EncodeVTable = NotSupported;
42
43 fn id(&self) -> ArrayId {
44 ArrayId::new_ref("vortex.ext")
45 }
46
47 fn encoding(_array: &Self::Array) -> ArrayVTable {
48 ExtensionVTable.as_vtable()
49 }
50
51 fn metadata(_array: &ExtensionArray) -> VortexResult<Self::Metadata> {
52 Ok(EmptyMetadata)
53 }
54
55 fn serialize(_metadata: Self::Metadata) -> VortexResult<Option<Vec<u8>>> {
56 Ok(Some(vec![]))
57 }
58
59 fn deserialize(_buffer: &[u8]) -> VortexResult<Self::Metadata> {
60 Ok(EmptyMetadata)
61 }
62
63 fn build(
64 &self,
65 dtype: &DType,
66 len: usize,
67 _metadata: &Self::Metadata,
68 _buffers: &[BufferHandle],
69 children: &dyn ArrayChildren,
70 ) -> VortexResult<ExtensionArray> {
71 let DType::Extension(ext_dtype) = dtype else {
72 vortex_bail!("Not an extension DType");
73 };
74 if children.len() != 1 {
75 vortex_bail!("Expected 1 child, got {}", children.len());
76 }
77 let storage = children.get(0, ext_dtype.storage_dtype(), len)?;
78 Ok(ExtensionArray::new(ext_dtype.clone(), storage))
79 }
80
81 fn batch_execute(array: &Self::Array, ctx: &mut ExecutionCtx) -> VortexResult<Vector> {
82 array.storage().batch_execute(ctx)
83 }
84}
85
86#[derive(Debug)]
87pub struct ExtensionVTable;