Skip to content

Commit 9f963b1

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

3 files changed

Lines changed: 31 additions & 14 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: 19 additions & 5 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;
@@ -47,6 +48,7 @@ use vortex_error::vortex_bail;
4748
use vortex_error::vortex_err;
4849
use vortex_error::vortex_panic;
4950
use vortex_session::VortexSession;
51+
use vortex_session::registry::Id;
5052
use vortex_session::registry::ReadContext;
5153
use vortex_utils::aliases::hash_map::HashMap;
5254

@@ -69,6 +71,17 @@ use crate::vtable;
6971

7072
vtable!(ArrayTree);
7173

74+
/// Well-known [`LayoutReaderContext`] key under which [`ArrayTreeLayout::derive_reader_ctx`]
75+
/// publishes its [`ArrayTreesSource`].
76+
///
77+
/// Both the publisher (parent [`ArrayTreeLayout`]) and the consumer
78+
/// ([`ArrayTreeFlatLayout`]'s `new_reader`) hardcode this id, so no metadata persistence is
79+
/// needed to bind them. Two stacked `ArrayTreeLayouts` both publish under this id; the
80+
/// inner one overrides the outer in the descendant's view — exactly the "nearest ancestor
81+
/// wins" semantic each `ArrayTreeFlat` leaf wants.
82+
pub static ARRAY_TREES_SOURCE_ID: LazyLock<Id> =
83+
LazyLock::new(|| Id::new_static("vortex.array_tree.source"));
84+
7285
/// Encoding marker for [`ArrayTreeLayout`].
7386
#[derive(Debug)]
7487
pub struct ArrayTreeLayoutEncoding;
@@ -134,8 +147,9 @@ impl ArrayTreeLayout {
134147
}
135148

136149
/// 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.
150+
/// layout's auxiliary `array_trees` child under [`ARRAY_TREES_SOURCE_ID`]. Descendant
151+
/// [`ArrayTreeFlatLayout`] readers pull the source by the same id to resolve their
152+
/// compact trees.
139153
///
140154
/// Used by:
141155
/// - The normal [`crate::VTable::new_reader`] dispatch on `ArrayTreeLayout` (production path).
@@ -158,7 +172,7 @@ impl ArrayTreeLayout {
158172
ctx,
159173
)?;
160174
let source = Arc::new(ArrayTreesSource::new(trees_reader, session.clone()));
161-
Ok(ctx.with(source))
175+
Ok(ctx.with(*ARRAY_TREES_SOURCE_ID, source))
162176
}
163177
}
164178

@@ -259,8 +273,8 @@ impl VTable for ArrayTree {
259273
/// the cached map.
260274
///
261275
/// Published by [`ArrayTreeLayout::derive_reader_ctx`] into the [`LayoutReaderContext`]
262-
/// passed to descendants; pulled by [`ArrayTreeFlatLayout`]'s reader via
263-
/// `ctx.get::<ArrayTreesSource>()`.
276+
/// passed to descendants under [`ARRAY_TREES_SOURCE_ID`]; pulled by
277+
/// [`ArrayTreeFlatLayout`]'s reader by the same id.
264278
pub struct ArrayTreesSource {
265279
reader: LayoutReaderRef,
266280
/// 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)