Skip to content

Commit 60476a9

Browse files
authored
Layout readers don't need a mutable context (#6808)
When reading the set of array ids is initialised from the file and then is immutable for whole scan duration. We don't need to share the mutable version with immutable one. --------- Signed-off-by: Robert Kruszewski <github@robertk.io>
1 parent e719a17 commit 60476a9

File tree

32 files changed

+234
-140
lines changed

32 files changed

+234
-140
lines changed

encodings/fastlanes/src/rle/array/mod.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,7 @@ mod tests {
229229
use vortex_array::validity::Validity;
230230
use vortex_buffer::Buffer;
231231
use vortex_buffer::ByteBufferMut;
232+
use vortex_session::registry::ReadContext;
232233

233234
use crate::RLEArray;
234235
use crate::test::SESSION;
@@ -458,7 +459,7 @@ mod tests {
458459
.decode(
459460
&DType::Primitive(PType::U32, Nullability::NonNullable),
460461
2048,
461-
&ctx,
462+
&ReadContext::new(ctx.to_ids()),
462463
&SESSION,
463464
)
464465
.unwrap();
@@ -498,7 +499,12 @@ mod tests {
498499

499500
let parts = ArrayParts::try_from(concat).unwrap();
500501
let decoded = parts
501-
.decode(sliced.dtype(), sliced.len(), &ctx, &SESSION)
502+
.decode(
503+
sliced.dtype(),
504+
sliced.len(),
505+
&ReadContext::new(ctx.to_ids()),
506+
&SESSION,
507+
)
502508
.unwrap();
503509

504510
let original_data = sliced.to_primitive();

encodings/pco/src/test.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ use vortex_buffer::BufferMut;
2727
use vortex_error::VortexResult;
2828
use vortex_mask::Mask;
2929
use vortex_session::VortexSession;
30+
use vortex_session::registry::ReadContext;
3031

3132
static SESSION: LazyLock<VortexSession> = LazyLock::new(|| {
3233
let session = VortexSession::empty().with::<ArraySession>();
@@ -166,7 +167,7 @@ fn test_serde() -> VortexResult<()> {
166167
let decoded = parts.decode(
167168
&DType::Primitive(PType::I32, Nullability::NonNullable),
168169
1_000_000,
169-
&context,
170+
&ReadContext::new(context.to_ids()),
170171
&SESSION,
171172
)?;
172173
let mut ctx = SESSION.create_execution_ctx();

vortex-array/public-api.lock

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15982,7 +15982,7 @@ pub fn vortex_array::serde::ArrayParts::buffer_lengths(&self) -> alloc::vec::Vec
1598215982

1598315983
pub fn vortex_array::serde::ArrayParts::child(&self, idx: usize) -> vortex_array::serde::ArrayParts
1598415984

15985-
pub fn vortex_array::serde::ArrayParts::decode(&self, dtype: &vortex_array::dtype::DType, len: usize, ctx: &vortex_array::ArrayContext, session: &vortex_session::VortexSession) -> vortex_error::VortexResult<vortex_array::ArrayRef>
15985+
pub fn vortex_array::serde::ArrayParts::decode(&self, dtype: &vortex_array::dtype::DType, len: usize, ctx: &vortex_session::registry::ReadContext, session: &vortex_session::VortexSession) -> vortex_error::VortexResult<vortex_array::ArrayRef>
1598615986

1598715987
pub fn vortex_array::serde::ArrayParts::encoding_id(&self) -> u16
1598815988

vortex-array/src/arrays/decimal/vtable/mod.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,7 @@ impl DecimalVTable {
239239
mod tests {
240240
use vortex_buffer::ByteBufferMut;
241241
use vortex_buffer::buffer;
242+
use vortex_session::registry::ReadContext;
242243

243244
use crate::ArrayContext;
244245
use crate::IntoArray;
@@ -273,7 +274,9 @@ mod tests {
273274
let concat = concat.freeze();
274275

275276
let parts = ArrayParts::try_from(concat).unwrap();
276-
let decoded = parts.decode(&dtype, 5, &ctx, &LEGACY_SESSION).unwrap();
277+
let decoded = parts
278+
.decode(&dtype, 5, &ReadContext::new(ctx.to_ids()), &LEGACY_SESSION)
279+
.unwrap();
277280
assert!(decoded.is::<DecimalVTable>());
278281
}
279282
}

vortex-array/src/arrays/masked/vtable/mod.rs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,7 @@ mod tests {
217217
use rstest::rstest;
218218
use vortex_buffer::ByteBufferMut;
219219
use vortex_error::VortexError;
220+
use vortex_session::registry::ReadContext;
220221

221222
use crate::ArrayContext;
222223
use crate::Canonical;
@@ -269,7 +270,14 @@ mod tests {
269270
let concat = concat.freeze();
270271

271272
let parts = ArrayParts::try_from(concat).unwrap();
272-
let decoded = parts.decode(&dtype, len, &ctx, &LEGACY_SESSION).unwrap();
273+
let decoded = parts
274+
.decode(
275+
&dtype,
276+
len,
277+
&ReadContext::new(ctx.to_ids()),
278+
&LEGACY_SESSION,
279+
)
280+
.unwrap();
273281

274282
assert!(decoded.is::<MaskedVTable>());
275283
assert_eq!(

vortex-array/src/context.rs

Lines changed: 0 additions & 8 deletions
This file was deleted.

vortex-array/src/lib.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,15 @@ use std::sync::LazyLock;
1818
pub use array::*;
1919
pub use canonical::*;
2020
pub use columnar::*;
21-
pub use context::*;
2221
pub use executor::*;
2322
pub use hash::*;
2423
pub use mask_future::*;
2524
pub use metadata::*;
2625
use vortex_session::VortexSession;
26+
use vortex_session::registry::Context;
2727

2828
use crate::session::ArraySession;
29+
use crate::vtable::DynVTable;
2930

3031
pub mod accessor;
3132
#[doc(hidden)]
@@ -39,7 +40,6 @@ pub mod builtins;
3940
mod canonical;
4041
mod columnar;
4142
pub mod compute;
42-
mod context;
4343
pub mod display;
4444
pub mod dtype;
4545
mod executor;
@@ -80,3 +80,5 @@ pub mod flatbuffers {
8080
// here...
8181
pub static LEGACY_SESSION: LazyLock<VortexSession> =
8282
LazyLock::new(|| VortexSession::empty().with::<ArraySession>());
83+
84+
pub type ArrayContext = Context<&'static dyn DynVTable>;

vortex-array/src/serde.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ use vortex_flatbuffers::WriteFlatBuffer;
2424
use vortex_flatbuffers::array as fba;
2525
use vortex_flatbuffers::array::Compression;
2626
use vortex_session::VortexSession;
27+
use vortex_session::registry::ReadContext;
2728
use vortex_utils::aliases::hash_map::HashMap;
2829

2930
use crate::ArrayContext;
@@ -318,7 +319,7 @@ impl ArrayParts {
318319
&self,
319320
dtype: &DType,
320321
len: usize,
321-
ctx: &ArrayContext,
322+
ctx: &ReadContext,
322323
session: &VortexSession,
323324
) -> VortexResult<ArrayRef> {
324325
let encoding_idx = self.flatbuffer().encoding();
@@ -623,7 +624,7 @@ impl ArrayParts {
623624

624625
struct ArrayPartsChildren<'a> {
625626
parts: &'a ArrayParts,
626-
ctx: &'a ArrayContext,
627+
ctx: &'a ReadContext,
627628
session: &'a VortexSession,
628629
}
629630

vortex-cuda/src/layout.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ use vortex::scalar::ScalarTruncation;
6464
use vortex::scalar::lower_bound;
6565
use vortex::scalar::upper_bound;
6666
use vortex::session::VortexSession;
67+
use vortex::session::registry::ReadContext;
6768
use vortex::utils::aliases::hash_map::HashMap;
6869

6970
/// A buffer inlined into layout metadata for host-side access.
@@ -94,7 +95,7 @@ pub struct CudaFlatLayout {
9495
row_count: u64,
9596
dtype: DType,
9697
segment_id: SegmentId,
97-
ctx: ArrayContext,
98+
ctx: ReadContext,
9899
array_tree: ByteBuffer,
99100
/// Small buffers kept on host, keyed by global buffer index.
100101
host_buffers: Arc<HashMap<u32, ByteBuffer>>,
@@ -107,7 +108,7 @@ impl CudaFlatLayout {
107108
}
108109

109110
#[inline]
110-
pub fn array_ctx(&self) -> &ArrayContext {
111+
pub fn array_ctx(&self) -> &ReadContext {
111112
&self.ctx
112113
}
113114

@@ -195,7 +196,7 @@ impl VTable for CudaFlatVTable {
195196
metadata: &<Self::Metadata as DeserializeMetadata>::Output,
196197
segment_ids: Vec<SegmentId>,
197198
_children: &dyn LayoutChildren,
198-
ctx: &ArrayContext,
199+
ctx: &ReadContext,
199200
) -> VortexResult<Self::Layout> {
200201
if segment_ids.len() != 1 {
201202
vortex_bail!("CudaFlatLayout must have exactly one segment ID");
@@ -535,7 +536,7 @@ impl LayoutStrategy for CudaFlatLayoutStrategy {
535536
row_count,
536537
dtype: stream.dtype().clone(),
537538
segment_id,
538-
ctx: ctx.clone(),
539+
ctx: ReadContext::new(ctx.to_ids()),
539540
array_tree,
540541
host_buffers: Arc::new(host_buffer_map),
541542
}

vortex-file/src/footer/file_layout.rs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,11 @@ use std::sync::Arc;
1111

1212
use flatbuffers::FlatBufferBuilder;
1313
use flatbuffers::WIPOffset;
14-
use vortex_array::ArrayContext;
1514
use vortex_error::VortexResult;
1615
use vortex_flatbuffers::FlatBufferRoot;
1716
use vortex_flatbuffers::WriteFlatBuffer;
1817
use vortex_flatbuffers::footer as fb;
19-
use vortex_layout::LayoutContext;
18+
use vortex_session::registry::ReadContext;
2019

2120
use crate::footer::segment::SegmentSpec;
2221

@@ -26,9 +25,9 @@ use crate::footer::segment::SegmentSpec;
2625
/// which describes the structure of the data in the file.
2726
pub(crate) struct FooterFlatBufferWriter {
2827
/// The array context containing encodings used in the file.
29-
pub(crate) ctx: ArrayContext,
28+
pub(crate) ctx: ReadContext,
3029
/// The layout context containing the layouts used in the file.
31-
pub(crate) layout_ctx: LayoutContext,
30+
pub(crate) layout_ctx: ReadContext,
3231
/// Specifications for all segments in the file.
3332
pub(crate) segment_specs: Arc<[SegmentSpec]>,
3433
}
@@ -47,7 +46,7 @@ impl WriteFlatBuffer for FooterFlatBufferWriter {
4746

4847
let array_specs = self
4948
.ctx
50-
.to_ids()
49+
.ids()
5150
.iter()
5251
.map(|e| {
5352
let id = fbb.create_string(e.as_ref());
@@ -58,7 +57,7 @@ impl WriteFlatBuffer for FooterFlatBufferWriter {
5857

5958
let layout_specs = self
6059
.layout_ctx
61-
.to_ids()
60+
.ids()
6261
.iter()
6362
.map(|e| {
6463
let id = fbb.create_string(e.as_ref());

0 commit comments

Comments
 (0)