vortex_array/arrays/extension/
serde.rs

1use vortex_dtype::DType;
2use vortex_error::{VortexResult, vortex_bail};
3
4use super::ExtensionEncoding;
5use crate::arrays::ExtensionArray;
6use crate::serde::ArrayParts;
7use crate::vtable::EncodingVTable;
8use crate::{
9    Array, ArrayChildVisitor, ArrayContext, ArrayRef, ArrayVisitorImpl, EmptyMetadata, EncodingId,
10};
11
12impl EncodingVTable for ExtensionEncoding {
13    fn id(&self) -> EncodingId {
14        EncodingId::new_ref("vortex.ext")
15    }
16
17    fn decode(
18        &self,
19        parts: &ArrayParts,
20        ctx: &ArrayContext,
21        dtype: DType,
22        len: usize,
23    ) -> VortexResult<ArrayRef> {
24        let DType::Extension(ext_dtype) = dtype else {
25            vortex_bail!("Not an extension DType");
26        };
27        let storage = parts
28            .child(0)
29            .decode(ctx, ext_dtype.storage_dtype().clone(), len)?;
30        Ok(ExtensionArray::new(ext_dtype, storage).into_array())
31    }
32}
33
34impl ArrayVisitorImpl for ExtensionArray {
35    fn _visit_children(&self, visitor: &mut dyn ArrayChildVisitor) {
36        visitor.visit_child("storage", self.storage())
37    }
38
39    fn _metadata(&self) -> EmptyMetadata {
40        EmptyMetadata
41    }
42}