use std::fmt::Debug;
use std::sync::Arc;
use vortex_array::SerializeMetadata;
use vortex_array::dtype::DType;
use vortex_error::VortexResult;
use vortex_session::VortexSession;
use crate::DynLayout;
use crate::Layout;
use crate::LayoutBuildContext;
use crate::LayoutChildType;
use crate::LayoutChildren;
use crate::LayoutDeserializeArgs;
use crate::LayoutId;
use crate::LayoutParts;
use crate::LayoutReaderContext;
use crate::LayoutReaderRef;
use crate::segments::SegmentId;
use crate::segments::SegmentSource;
pub type LayoutRef = Arc<dyn DynLayout>;
pub trait VTable: 'static + Clone + Send + Sync + Debug {
type LayoutData: 'static + Clone + Send + Sync + Debug;
type Metadata: SerializeMetadata + vortex_array::DeserializeMetadata + Debug;
fn id(&self) -> LayoutId;
fn metadata(layout: &Layout<Self>) -> Self::Metadata;
fn deserialize(
&self,
args: &LayoutDeserializeArgs<'_>,
metadata: &<Self::Metadata as vortex_array::DeserializeMetadata>::Output,
) -> VortexResult<Self::LayoutData>;
fn build(
vtable: &Self,
dtype: &DType,
row_count: u64,
metadata: &<Self::Metadata as vortex_array::DeserializeMetadata>::Output,
segment_ids: Vec<SegmentId>,
children: &dyn LayoutChildren,
build_ctx: &LayoutBuildContext<'_>,
) -> VortexResult<Layout<Self>> {
let args = LayoutDeserializeArgs {
session: build_ctx.session,
array_read_ctx: build_ctx.array_read_ctx,
dtype,
row_count,
segment_ids,
children,
};
let data = vtable.deserialize(&args, metadata)?;
Ok(LayoutParts::new(
vtable.clone(),
dtype.clone(),
row_count,
args.segment_ids,
children.to_arc(),
data,
)
.into_typed())
}
fn nslots(layout: &Layout<Self>) -> usize {
layout.nchildren()
}
fn slot_to_child(layout: &Layout<Self>, slot: usize) -> Option<usize> {
(slot < Self::nslots(layout)).then_some(slot)
}
fn child_dtype(layout: &Layout<Self>, slot: usize) -> VortexResult<DType>;
fn child_type(layout: &Layout<Self>, slot: usize) -> LayoutChildType;
fn new_reader(
layout: &Layout<Self>,
name: Arc<str>,
segment_source: Arc<dyn SegmentSource>,
session: &VortexSession,
ctx: &LayoutReaderContext,
) -> VortexResult<LayoutReaderRef>;
fn is_indivisible(&self) -> bool {
false
}
}