Skip to content

Commit 0763a98

Browse files
authored
feature: Support overriding layout verification settings via environment variables (#3794)
Signed-off-by: Robert Kruszewski <[email protected]>
1 parent afbc015 commit 0763a98

File tree

1 file changed

+22
-2
lines changed

1 file changed

+22
-2
lines changed

vortex-layout/src/flatbuffers.rs

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
// SPDX-License-Identifier: Apache-2.0
22
// SPDX-FileCopyrightText: Copyright the Vortex contributors
33

4-
use flatbuffers::{FlatBufferBuilder, WIPOffset, root};
4+
use std::env;
5+
use std::sync::LazyLock;
6+
7+
use flatbuffers::{FlatBufferBuilder, VerifierOptions, WIPOffset, root_with_opts};
58
use vortex_dtype::DType;
69
use vortex_error::{VortexExpect, VortexResult, vortex_err};
710
use vortex_flatbuffers::{FlatBuffer, FlatBufferRoot, WriteFlatBuffer, layout};
@@ -10,13 +13,30 @@ use crate::children::ViewedLayoutChildren;
1013
use crate::segments::SegmentId;
1114
use crate::{Layout, LayoutContext, LayoutRef};
1215

16+
static LAYOUT_VERIFIER: LazyLock<VerifierOptions> = LazyLock::new(|| {
17+
VerifierOptions {
18+
// Overriden
19+
max_tables: env::var("VORTEX_MAX_LAYOUT_TABLES")
20+
.ok()
21+
.and_then(|lmt| lmt.parse::<usize>().ok())
22+
.unwrap_or(1000000),
23+
max_depth: env::var("VORTEX_MAX_LAYOUT_DEPTH")
24+
.ok()
25+
.and_then(|lmt| lmt.parse::<usize>().ok())
26+
.unwrap_or(64),
27+
// Defaults from flatbuffers
28+
max_apparent_size: 1 << 31,
29+
ignore_missing_null_terminator: false,
30+
}
31+
});
32+
1333
/// Parse a [`LayoutRef`] from a layout flatbuffer.
1434
pub fn layout_from_flatbuffer(
1535
flatbuffer: FlatBuffer,
1636
dtype: &DType,
1737
ctx: &LayoutContext,
1838
) -> VortexResult<LayoutRef> {
19-
let fb_layout = root::<layout::Layout>(&flatbuffer)?;
39+
let fb_layout = root_with_opts::<layout::Layout>(&LAYOUT_VERIFIER, &flatbuffer)?;
2040
let encoding = ctx
2141
.lookup_encoding(fb_layout.encoding())
2242
.ok_or_else(|| vortex_err!("Invalid encoding ID: {}", fb_layout.encoding()))?;

0 commit comments

Comments
 (0)