vortex_layout/
vtable.rs

1use std::collections::BTreeSet;
2use std::fmt::{Debug, Display, Formatter};
3use std::sync::Arc;
4
5use vortex_array::ArrayContext;
6use vortex_array::arcref::ArcRef;
7use vortex_dtype::FieldMask;
8use vortex_error::VortexResult;
9
10use crate::segments::{AsyncSegmentReader, SegmentCollector};
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        ctx: ArrayContext,
27        segment_reader: Arc<dyn AsyncSegmentReader>,
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    fn required_segments(
48        &self,
49        layout: &Layout,
50        row_offset: u64,
51        filter_field_mask: &[FieldMask],
52        projection_field_mask: &[FieldMask],
53        segments: &mut SegmentCollector,
54    ) -> VortexResult<()>;
55}
56
57impl PartialEq for dyn LayoutVTable + '_ {
58    fn eq(&self, other: &Self) -> bool {
59        self.id() == other.id()
60    }
61}
62
63impl Eq for dyn LayoutVTable + '_ {}
64
65impl Display for dyn LayoutVTable + '_ {
66    fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
67        Display::fmt(&self.id(), f)
68    }
69}