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

vortex-data / vortex / 16324698785

16 Jul 2025 04:12PM UTC coverage: 80.702% (-0.9%) from 81.557%
16324698785

Pull #3881

github

web-flow
Merge afc822f8d into ced09d9a8
Pull Request #3881: feat: build with stable rust

119 of 172 new or added lines in 28 files covered. (69.19%)

174 existing lines in 102 files now uncovered.

41861 of 51871 relevant lines covered (80.7%)

157493.2 hits per line

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

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

4
use std::env;
5
use std::sync::LazyLock;
6

7
use flatbuffers::{FlatBufferBuilder, VerifierOptions, WIPOffset, root_with_opts};
8
use vortex_array::ArrayContext;
9
use vortex_dtype::DType;
10
use vortex_error::{VortexExpect, VortexResult, vortex_err};
11
use vortex_flatbuffers::{FlatBuffer, FlatBufferRoot, WriteFlatBuffer, layout};
12

13
use crate::children::ViewedLayoutChildren;
14
use crate::segments::SegmentId;
15
use crate::{Layout, LayoutContext, LayoutRef};
16

17
static LAYOUT_VERIFIER: LazyLock<VerifierOptions> = LazyLock::new(|| {
668✔
18
    VerifierOptions {
19
        // Overriden
20
        max_tables: env::var("VORTEX_MAX_LAYOUT_TABLES")
668✔
21
            .ok()
668✔
22
            .and_then(|lmt| lmt.parse::<usize>().ok())
668✔
23
            .unwrap_or(1000000),
668✔
24
        max_depth: env::var("VORTEX_MAX_LAYOUT_DEPTH")
668✔
25
            .ok()
668✔
26
            .and_then(|lmt| lmt.parse::<usize>().ok())
668✔
27
            .unwrap_or(64),
668✔
28
        // Defaults from flatbuffers
29
        max_apparent_size: 1 << 31,
668✔
30
        ignore_missing_null_terminator: false,
31
    }
32
});
668✔
33

34
/// Parse a [`LayoutRef`] from a layout flatbuffer.
35
pub fn layout_from_flatbuffer(
906✔
36
    flatbuffer: FlatBuffer,
906✔
37
    dtype: &DType,
906✔
38
    layout_ctx: &LayoutContext,
906✔
39
    array_ctx: &ArrayContext,
906✔
40
) -> VortexResult<LayoutRef> {
906✔
41
    let fb_layout = root_with_opts::<layout::Layout>(&LAYOUT_VERIFIER, &flatbuffer)?;
906✔
42
    let encoding = layout_ctx
906✔
43
        .lookup_encoding(fb_layout.encoding())
906✔
44
        .ok_or_else(|| vortex_err!("Invalid encoding ID: {}", fb_layout.encoding()))?;
906✔
45

46
    // SAFETY: we validate the flatbuffer above in the `root` call, and extract a loc.
47
    let viewed_children = unsafe {
906✔
48
        ViewedLayoutChildren::new_unchecked(
906✔
49
            flatbuffer.clone(),
906✔
50
            fb_layout._tab.loc(),
906✔
51
            array_ctx.clone(),
906✔
52
            layout_ctx.clone(),
906✔
53
        )
54
    };
55

56
    let layout = encoding.build(
906✔
57
        dtype,
906✔
58
        fb_layout.row_count(),
906✔
59
        fb_layout
906✔
60
            .metadata()
906✔
61
            .map(|m| m.bytes())
906✔
62
            .unwrap_or_else(|| &[]),
906✔
63
        fb_layout
906✔
64
            .segments()
906✔
65
            .unwrap_or_default()
906✔
66
            .iter()
906✔
67
            .map(SegmentId::from)
906✔
68
            .collect(),
906✔
69
        &viewed_children,
906✔
70
        array_ctx.clone(),
906✔
UNCOV
71
    )?;
×
72

73
    Ok(layout)
906✔
74
}
906✔
75

76
impl dyn Layout + '_ {
77
    /// Serialize the layout into a [`FlatBufferBuilder`].
78
    pub fn flatbuffer_writer<'a>(
736✔
79
        &'a self,
736✔
80
        ctx: &'a LayoutContext,
736✔
81
    ) -> impl WriteFlatBuffer<Target<'a> = layout::Layout<'a>> + FlatBufferRoot + 'a {
736✔
82
        LayoutFlatBufferWriter { layout: self, ctx }
736✔
83
    }
736✔
84
}
85

86
/// An adapter struct for writing a layout to a FlatBuffer.
87
struct LayoutFlatBufferWriter<'a> {
88
    layout: &'a dyn Layout,
89
    ctx: &'a LayoutContext,
90
}
91

92
impl FlatBufferRoot for LayoutFlatBufferWriter<'_> {}
93

94
impl WriteFlatBuffer for LayoutFlatBufferWriter<'_> {
95
    type Target<'t> = layout::Layout<'t>;
96

97
    fn write_flatbuffer<'fb>(
5,168✔
98
        &self,
5,168✔
99
        fbb: &mut FlatBufferBuilder<'fb>,
5,168✔
100
    ) -> WIPOffset<Self::Target<'fb>> {
5,168✔
101
        // First we recurse into the children and write them out
102
        let child_layouts = self
5,168✔
103
            .layout
5,168✔
104
            .children()
5,168✔
105
            .vortex_expect("Failed to load layout children");
5,168✔
106
        let children = child_layouts
5,168✔
107
            .iter()
5,168✔
108
            .map(|layout| {
5,168✔
109
                LayoutFlatBufferWriter {
4,432✔
110
                    layout: layout.as_ref(),
4,432✔
111
                    ctx: self.ctx,
4,432✔
112
                }
4,432✔
113
                .write_flatbuffer(fbb)
4,432✔
114
            })
4,432✔
115
            .collect::<Vec<_>>();
5,168✔
116
        let children = (!children.is_empty()).then(|| fbb.create_vector(&children));
5,168✔
117

118
        // Next we write out the metadata if it's non-empty.
119
        let metadata = self.layout.metadata();
5,168✔
120
        let metadata = (!metadata.is_empty()).then(|| fbb.create_vector(&metadata));
5,168✔
121

122
        let segments = self
5,168✔
123
            .layout
5,168✔
124
            .segment_ids()
5,168✔
125
            .into_iter()
5,168✔
126
            .map(|s| *s)
5,168✔
127
            .collect::<Vec<_>>();
5,168✔
128
        let segments = (!segments.is_empty()).then(|| fbb.create_vector(&segments));
5,168✔
129

130
        // Dictionary-encode the layout ID
131
        let encoding = self.ctx.encoding_idx(&self.layout.encoding());
5,168✔
132

133
        layout::Layout::create(
5,168✔
134
            fbb,
5,168✔
135
            &layout::LayoutArgs {
5,168✔
136
                encoding,
5,168✔
137
                row_count: self.layout.row_count(),
5,168✔
138
                metadata,
5,168✔
139
                children,
5,168✔
140
                segments,
5,168✔
141
            },
5,168✔
142
        )
143
    }
5,168✔
144
}
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