Skip to content

Commit d4dc062

Browse files
committed
move to explicit but hardcoded id
Signed-off-by: Onur Satici <onur@spiraldb.com>
1 parent 4aae32b commit d4dc062

3 files changed

Lines changed: 42 additions & 19 deletions

File tree

vortex-layout/src/layouts/array_tree/flat.rs

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ use crate::LayoutReaderRef;
2121
use crate::LayoutRef;
2222
use crate::VTable;
2323
use crate::children::LayoutChildren;
24+
use crate::layouts::array_tree::ARRAY_TREES_SOURCE_ID;
2425
use crate::layouts::array_tree::ArrayTreesSource;
2526
use crate::layouts::array_tree::reader::ArrayTreeFlatReader;
2627
use crate::layouts::flat::FlatLayout;
@@ -131,14 +132,16 @@ impl VTable for ArrayTreeFlat {
131132
session: &VortexSession,
132133
ctx: &LayoutReaderContext,
133134
) -> VortexResult<LayoutReaderRef> {
134-
let source = ctx.get::<ArrayTreesSource>().ok_or_else(|| {
135-
vortex_error::vortex_err!(
136-
"ArrayTreeFlatLayout requires an ancestor ArrayTreeLayout to publish an \
135+
let source = ctx
136+
.get::<ArrayTreesSource>(*ARRAY_TREES_SOURCE_ID)
137+
.ok_or_else(|| {
138+
vortex_error::vortex_err!(
139+
"ArrayTreeFlatLayout requires an ancestor ArrayTreeLayout to publish an \
137140
ArrayTreesSource into the reader context; call \
138141
ArrayTreeLayout::derive_reader_ctx on each ArrayTreeLayout ancestor before \
139142
constructing a reader for this layout"
140-
)
141-
})?;
143+
)
144+
})?;
142145
Ok(Arc::new(ArrayTreeFlatReader::new(
143146
layout.clone(),
144147
name,

vortex-layout/src/layouts/array_tree/mod.rs

Lines changed: 30 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ mod reader;
1414
pub mod writer;
1515

1616
use std::sync::Arc;
17+
use std::sync::LazyLock;
1718
use std::sync::OnceLock;
1819

1920
use futures::FutureExt;
@@ -38,15 +39,17 @@ use vortex_array::dtype::StructFields;
3839
use vortex_array::expr::root;
3940
use vortex_array::serde::BUFFER_COLUMNS_DTYPE;
4041
use vortex_array::serde::ColumnarArrayTree;
41-
use vortex_array::serde::NODES_COLUMNS_DTYPE;
42+
use vortex_array::serde::DEFAULT_STATS;
4243
use vortex_array::serde::StatsColumns;
44+
use vortex_array::serde::nodes_columns_dtype;
4345
use vortex_error::SharedVortexResult;
4446
use vortex_error::VortexExpect;
4547
use vortex_error::VortexResult;
4648
use vortex_error::vortex_bail;
4749
use vortex_error::vortex_err;
4850
use vortex_error::vortex_panic;
4951
use vortex_session::VortexSession;
52+
use vortex_session::registry::Id;
5053
use vortex_session::registry::ReadContext;
5154
use vortex_utils::aliases::hash_map::HashMap;
5255

@@ -69,6 +72,17 @@ use crate::vtable;
6972

7073
vtable!(ArrayTree);
7174

75+
/// Well-known [`LayoutReaderContext`] key under which [`ArrayTreeLayout::derive_reader_ctx`]
76+
/// publishes its [`ArrayTreesSource`].
77+
///
78+
/// Both the publisher (parent [`ArrayTreeLayout`]) and the consumer
79+
/// ([`ArrayTreeFlatLayout`]'s `new_reader`) hardcode this id, so no metadata persistence is
80+
/// needed to bind them. Two stacked `ArrayTreeLayouts` both publish under this id; the
81+
/// inner one overrides the outer in the descendant's view — exactly the "nearest ancestor
82+
/// wins" semantic each `ArrayTreeFlat` leaf wants.
83+
pub static ARRAY_TREES_SOURCE_ID: LazyLock<Id> =
84+
LazyLock::new(|| Id::new_static("vortex.array_tree.source"));
85+
7286
/// Encoding marker for [`ArrayTreeLayout`].
7387
#[derive(Debug)]
7488
pub struct ArrayTreeLayoutEncoding;
@@ -109,10 +123,15 @@ impl ArrayTreeLayout {
109123
/// }
110124
/// ```
111125
///
112-
/// The List<> element types are exactly the canonical per-tree schemas defined by
113-
/// [`vortex_array::serde::NODES_COLUMNS_DTYPE`] / [`vortex_array::serde::BUFFER_COLUMNS_DTYPE`],
114-
/// so slicing one row's nodes (resp. buffers) yields a [`StructArray`] matching the inner
126+
/// The List<> element types are produced by
127+
/// [`vortex_array::serde::nodes_columns_dtype`] / [`vortex_array::serde::BUFFER_COLUMNS_DTYPE`].
128+
/// Slicing one row's nodes (resp. buffers) yields a [`StructArray`] matching the inner
115129
/// shape of a [`ColumnarArrayTree`].
130+
///
131+
/// The `nodes` schema is parameterized by the stat menu the layout tracks; today this
132+
/// defaults to [`vortex_array::serde::DEFAULT_STATS`] (the historical 11-stat set), but
133+
/// future writers can pick a different menu and the schema field names carry that menu
134+
/// across the wire.
116135
pub fn array_trees_dtype() -> DType {
117136
let nn = Nullability::NonNullable;
118137
DType::Struct(
@@ -125,7 +144,7 @@ impl ArrayTreeLayout {
125144
.into(),
126145
vec![
127146
DType::Primitive(PType::U32, nn),
128-
DType::List(Arc::new(NODES_COLUMNS_DTYPE.clone()), nn),
147+
DType::List(Arc::new(nodes_columns_dtype(DEFAULT_STATS)), nn),
129148
DType::List(Arc::new(BUFFER_COLUMNS_DTYPE.clone()), nn),
130149
],
131150
),
@@ -134,8 +153,9 @@ impl ArrayTreeLayout {
134153
}
135154

136155
/// Derive a [`LayoutReaderContext`] that publishes an [`ArrayTreesSource`] backed by this
137-
/// layout's auxiliary `array_trees` child. Descendant [`ArrayTreeFlatLayout`] readers
138-
/// pull the source via `ctx.get::<ArrayTreesSource>()` to resolve their compact trees.
156+
/// layout's auxiliary `array_trees` child under [`ARRAY_TREES_SOURCE_ID`]. Descendant
157+
/// [`ArrayTreeFlatLayout`] readers pull the source by the same id to resolve their
158+
/// compact trees.
139159
///
140160
/// Used by:
141161
/// - The normal [`crate::VTable::new_reader`] dispatch on `ArrayTreeLayout` (production path).
@@ -158,7 +178,7 @@ impl ArrayTreeLayout {
158178
ctx,
159179
)?;
160180
let source = Arc::new(ArrayTreesSource::new(trees_reader, session.clone()));
161-
Ok(ctx.with(source))
181+
Ok(ctx.with(*ARRAY_TREES_SOURCE_ID, source))
162182
}
163183
}
164184

@@ -259,8 +279,8 @@ impl VTable for ArrayTree {
259279
/// the cached map.
260280
///
261281
/// Published by [`ArrayTreeLayout::derive_reader_ctx`] into the [`LayoutReaderContext`]
262-
/// passed to descendants; pulled by [`ArrayTreeFlatLayout`]'s reader via
263-
/// `ctx.get::<ArrayTreesSource>()`.
282+
/// passed to descendants under [`ARRAY_TREES_SOURCE_ID`]; pulled by
283+
/// [`ArrayTreeFlatLayout`]'s reader by the same id.
264284
pub struct ArrayTreesSource {
265285
reader: LayoutReaderRef,
266286
/// Session used to create execution contexts when canonicalizing the consolidated array

vortex-layout/src/layouts/array_tree/reader.rs

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

4-
use std::collections::BTreeSet;
54
use std::ops::BitAnd;
65
use std::ops::Range;
76
use std::sync::Arc;
@@ -24,6 +23,7 @@ use crate::layouts::SharedArrayFuture;
2423
use crate::layouts::array_tree::ArrayTreesSource;
2524
use crate::layouts::array_tree::flat::ArrayTreeFlatLayout;
2625
use crate::reader::ArrayFuture;
26+
use crate::reader::RowSplits;
2727
use crate::reader::SplitRange;
2828
use crate::segments::SegmentSource;
2929

@@ -62,7 +62,7 @@ impl LayoutReader for ArrayTreeReader {
6262
&self,
6363
field_mask: &[FieldMask],
6464
split_range: &SplitRange,
65-
splits: &mut BTreeSet<u64>,
65+
splits: &mut RowSplits,
6666
) -> VortexResult<()> {
6767
self.data_reader
6868
.register_splits(field_mask, split_range, splits)
@@ -178,10 +178,10 @@ impl LayoutReader for ArrayTreeFlatReader {
178178
&self,
179179
_field_mask: &[FieldMask],
180180
split_range: &SplitRange,
181-
splits: &mut BTreeSet<u64>,
181+
splits: &mut RowSplits,
182182
) -> VortexResult<()> {
183183
split_range.check_bounds(self.layout.inner().row_count())?;
184-
splits.insert(split_range.root_row_range().end);
184+
splits.push(split_range.root_row_range().end);
185185
Ok(())
186186
}
187187

0 commit comments

Comments
 (0)