• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

vortex-data / vortex / 16593958537

29 Jul 2025 10:48AM UTC coverage: 82.285% (+0.5%) from 81.796%
16593958537

Pull #4036

github

web-flow
Merge 04147cb0f into 348079fc3
Pull Request #4036: varbinview builder buffer deduplication

146 of 154 new or added lines in 2 files covered. (94.81%)

348 existing lines in 26 files now uncovered.

44470 of 54044 relevant lines covered (82.28%)

169522.95 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

50.0
/vortex-layout/src/vtable.rs
1
// SPDX-License-Identifier: Apache-2.0
2
// SPDX-FileCopyrightText: Copyright the Vortex contributors
3

4
use std::fmt::Debug;
5
use std::ops::Deref;
6
use std::sync::Arc;
7

8
use vortex_array::{ArrayContext, DeserializeMetadata, SerializeMetadata};
9
use vortex_dtype::DType;
10
use vortex_error::VortexResult;
11

12
use crate::children::LayoutChildren;
13
use crate::segments::{SegmentId, SegmentSource};
14
use crate::{
15
    IntoLayout, Layout, LayoutChildType, LayoutEncoding, LayoutEncodingRef, LayoutId,
16
    LayoutReaderRef, LayoutRef,
17
};
18

19
pub trait VTable: 'static + Sized + Send + Sync + Debug {
20
    type Layout: 'static + Send + Sync + Clone + Debug + Deref<Target = dyn Layout> + IntoLayout;
21
    type Encoding: 'static + Send + Sync + Deref<Target = dyn LayoutEncoding>;
22
    type Metadata: SerializeMetadata + DeserializeMetadata + Debug;
23

24
    /// Returns the ID of the layout encoding.
25
    fn id(encoding: &Self::Encoding) -> LayoutId;
26

27
    /// Returns the encoding for the layout.
28
    fn encoding(layout: &Self::Layout) -> LayoutEncodingRef;
29

30
    /// Returns the row count for the layout reader.
31
    fn row_count(layout: &Self::Layout) -> u64;
32

33
    /// Returns the dtype for the layout reader.
34
    fn dtype(layout: &Self::Layout) -> &DType;
35

36
    /// Returns the metadata for the layout.
37
    fn metadata(layout: &Self::Layout) -> Self::Metadata;
38

39
    /// Returns the segment IDs for the layout.
40
    fn segment_ids(layout: &Self::Layout) -> Vec<SegmentId>;
41

42
    /// Returns the number of children for the layout.
43
    fn nchildren(layout: &Self::Layout) -> usize;
44

45
    /// Return the child at the given index.
46
    fn child(layout: &Self::Layout, idx: usize) -> VortexResult<LayoutRef>;
47

48
    /// Return the type of the child at the given index.
49
    fn child_type(layout: &Self::Layout, idx: usize) -> LayoutChildType;
50

51
    /// Create a new reader for the layout.
52
    fn new_reader(
53
        layout: &Self::Layout,
54
        name: Arc<str>,
55
        segment_source: Arc<dyn SegmentSource>,
56
    ) -> VortexResult<LayoutReaderRef>;
57

58
    /// Construct a new [`Layout`] from the provided parts.
59
    fn build(
60
        encoding: &Self::Encoding,
61
        dtype: &DType,
62
        row_count: u64,
63
        metadata: &<Self::Metadata as DeserializeMetadata>::Output,
64
        segment_ids: Vec<SegmentId>,
65
        children: &dyn LayoutChildren,
66
        ctx: ArrayContext,
67
    ) -> VortexResult<Self::Layout>;
68
}
69

70
#[macro_export]
71
macro_rules! vtable {
72
    ($V:ident) => {
73
        $crate::aliases::paste::paste! {
74
            #[derive(Debug)]
75
            pub struct [<$V VTable>];
76

77
            impl AsRef<dyn $crate::Layout> for [<$V Layout>] {
78
                fn as_ref(&self) -> &dyn $crate::Layout {
×
79
                    // We can unsafe cast ourselves to a LayoutAdapter.
80
                    unsafe { &*(self as *const [<$V Layout>] as *const $crate::LayoutAdapter<[<$V VTable>]>) }
×
81
                }
×
82
            }
83

84
            impl std::ops::Deref for [<$V Layout>] {
85
                type Target = dyn $crate::Layout;
86

87
                fn deref(&self) -> &Self::Target {
190,716✔
88
                    // We can unsafe cast ourselves to an LayoutAdapter.
89
                    unsafe { &*(self as *const [<$V Layout>] as *const $crate::LayoutAdapter<[<$V VTable>]>) }
190,716✔
90
                }
190,716✔
91
            }
92

93
            impl $crate::IntoLayout for [<$V Layout>] {
94
                fn into_layout(self) -> $crate::LayoutRef {
27,783✔
95
                    // We can unsafe transmute ourselves to an LayoutAdapter.
96
                    std::sync::Arc::new(unsafe { std::mem::transmute::<[<$V Layout>], $crate::LayoutAdapter::<[<$V VTable>]>>(self) })
27,783✔
97
                }
27,783✔
98
            }
99

100
            impl From<[<$V Layout>]> for $crate::LayoutRef {
UNCOV
101
                fn from(value: [<$V Layout>]) -> $crate::LayoutRef {
×
102
                    use $crate::IntoLayout;
UNCOV
103
                    value.into_layout()
×
UNCOV
104
                }
×
105
            }
106

107
            impl AsRef<dyn $crate::LayoutEncoding> for [<$V LayoutEncoding>] {
108
                fn as_ref(&self) -> &dyn $crate::LayoutEncoding {
13,644✔
109
                    // We can unsafe cast ourselves to an LayoutEncodingAdapter.
110
                    unsafe { &*(self as *const [<$V LayoutEncoding>] as *const $crate::LayoutEncodingAdapter<[<$V VTable>]>) }
13,644✔
111
                }
13,644✔
112
            }
113

114
            impl std::ops::Deref for [<$V LayoutEncoding>] {
115
                type Target = dyn $crate::LayoutEncoding;
116

UNCOV
117
                fn deref(&self) -> &Self::Target {
×
118
                    // We can unsafe cast ourselves to an LayoutEncodingAdapter.
UNCOV
119
                    unsafe { &*(self as *const [<$V LayoutEncoding>] as *const $crate::LayoutEncodingAdapter<[<$V VTable>]>) }
×
UNCOV
120
                }
×
121
            }
122
        }
123
    };
124
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc