1use std::fmt::Debug;
5use std::sync::Arc;
6
7use vortex_array::SerializeMetadata;
8use vortex_array::dtype::DType;
9use vortex_error::VortexResult;
10use vortex_session::VortexSession;
11
12use crate::DynLayout;
13use crate::Layout;
14use crate::LayoutBuildContext;
15use crate::LayoutChildType;
16use crate::LayoutChildren;
17use crate::LayoutDeserializeArgs;
18use crate::LayoutId;
19use crate::LayoutParts;
20use crate::LayoutReaderContext;
21use crate::LayoutReaderRef;
22use crate::segments::SegmentId;
23use crate::segments::SegmentSource;
24
25pub type LayoutRef = Arc<dyn DynLayout>;
27
28pub trait VTable: 'static + Clone + Send + Sync + Debug {
33 type LayoutData: 'static + Clone + Send + Sync + Debug;
35 type Metadata: SerializeMetadata + vortex_array::DeserializeMetadata + Debug;
37
38 fn id(&self) -> LayoutId;
40
41 fn metadata(layout: &Layout<Self>) -> Self::Metadata;
43
44 fn deserialize(
46 &self,
47 args: &LayoutDeserializeArgs<'_>,
48 metadata: &<Self::Metadata as vortex_array::DeserializeMetadata>::Output,
49 ) -> VortexResult<Self::LayoutData>;
50
51 fn build(
53 vtable: &Self,
54 dtype: &DType,
55 row_count: u64,
56 metadata: &<Self::Metadata as vortex_array::DeserializeMetadata>::Output,
57 segment_ids: Vec<SegmentId>,
58 children: &dyn LayoutChildren,
59 build_ctx: &LayoutBuildContext<'_>,
60 ) -> VortexResult<Layout<Self>> {
61 let args = LayoutDeserializeArgs {
62 session: build_ctx.session,
63 array_read_ctx: build_ctx.array_read_ctx,
64 dtype,
65 row_count,
66 segment_ids,
67 children,
68 };
69 let data = vtable.deserialize(&args, metadata)?;
70 Ok(LayoutParts::new(
71 vtable.clone(),
72 dtype.clone(),
73 row_count,
74 args.segment_ids,
75 children.to_arc(),
76 data,
77 )
78 .into_typed())
79 }
80
81 fn child_dtype(layout: &Layout<Self>, idx: usize) -> VortexResult<DType>;
83
84 fn child_type(layout: &Layout<Self>, idx: usize) -> LayoutChildType;
86
87 fn new_reader(
89 layout: &Layout<Self>,
90 name: Arc<str>,
91 segment_source: Arc<dyn SegmentSource>,
92 session: &VortexSession,
93 ctx: &LayoutReaderContext,
94 ) -> VortexResult<LayoutReaderRef>;
95}