vortex_layout/
vtable.rs

1use std::collections::BTreeSet;
2use std::fmt::{Debug, Display, Formatter};
3use std::sync::Arc;
4
5use arcref::ArcRef;
6use vortex_array::ArrayContext;
7use vortex_dtype::FieldMask;
8use vortex_error::VortexResult;
9
10use crate::segments::SegmentSource;
11use crate::{Layout, LayoutId, LayoutReader};
12
13/// A reference to a layout VTable, either static or arc'd.
14pub type LayoutVTableRef = ArcRef<dyn LayoutVTable>;
15
16pub trait LayoutVTable: Debug + Send + Sync {
17    /// Returns the globally unique ID for this type of layout.
18    fn id(&self) -> LayoutId;
19
20    /// Construct a [`LayoutReader`] for the provided [`Layout`].
21    ///
22    /// May panic if the provided `Layout` is not the same encoding as this `LayoutEncoding`.
23    fn reader(
24        &self,
25        layout: Layout,
26        segment_source: &Arc<dyn SegmentSource>,
27        ctx: &ArrayContext,
28    ) -> VortexResult<Arc<dyn LayoutReader>>;
29
30    /// Register the row splits for this layout, these represent natural boundaries at which
31    /// a reader can split the layout for independent processing.
32    ///
33    /// For example, a ChunkedLayout would register a boundary at the end of every chunk.
34    ///
35    /// The layout is passed a `row_offset` that identifies the starting row of the layout within
36    /// the file.
37    // TODO(ngates): we should check whether this is actually performant enough since we visit
38    //  all nodes of the layout tree, often registering the same splits many times.
39    fn register_splits(
40        &self,
41        layout: &Layout,
42        field_mask: &[FieldMask],
43        row_offset: u64,
44        splits: &mut BTreeSet<u64>,
45    ) -> VortexResult<()>;
46}
47
48impl PartialEq for dyn LayoutVTable + '_ {
49    fn eq(&self, other: &Self) -> bool {
50        self.id() == other.id()
51    }
52}
53
54impl Eq for dyn LayoutVTable + '_ {}
55
56impl Display for dyn LayoutVTable + '_ {
57    fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
58        Display::fmt(&self.id(), f)
59    }
60}