From 6c1444c45f30b7a1a13ca3e9aaa60e1a696a2c4b Mon Sep 17 00:00:00 2001 From: Mikhail Kot Date: Wed, 3 Jun 2026 12:09:31 +0100 Subject: [PATCH] initial Signed-off-by: Mikhail Kot --- vortex-layout/src/layouts/chunked/mod.rs | 12 +++++------- vortex-layout/src/layouts/chunked/reader.rs | 19 ++++++------------- 2 files changed, 11 insertions(+), 20 deletions(-) diff --git a/vortex-layout/src/layouts/chunked/mod.rs b/vortex-layout/src/layouts/chunked/mod.rs index 82fcb650607..59f41394168 100644 --- a/vortex-layout/src/layouts/chunked/mod.rs +++ b/vortex-layout/src/layouts/chunked/mod.rs @@ -103,10 +103,9 @@ impl VTable for Chunked { let new_children = OwnedLayoutChildren::layout_children(children); // Recalculate chunk offsets based on new children - let mut chunk_offsets = Vec::with_capacity(new_children.nchildren() + 1); - chunk_offsets.push(0); + let mut chunk_offsets = vec![0; new_children.nchildren() + 1]; for i in 0..new_children.nchildren() { - chunk_offsets.push(chunk_offsets[i] + new_children.child_row_count(i)); + chunk_offsets[i + 1] = chunk_offsets[i] + new_children.child_row_count(i); } layout.children = new_children; @@ -132,12 +131,11 @@ pub struct ChunkedLayout { impl ChunkedLayout { pub fn new(row_count: u64, dtype: DType, children: Arc) -> Self { - let mut chunk_offsets = Vec::with_capacity(children.nchildren() + 1); - - chunk_offsets.push(0); + let mut chunk_offsets = vec![0; children.nchildren() + 1]; for i in 0..children.nchildren() { - chunk_offsets.push(chunk_offsets[i] + children.child_row_count(i)); + chunk_offsets[i + 1] = chunk_offsets[i] + children.child_row_count(i); } + assert_eq!( chunk_offsets[children.nchildren()], row_count, diff --git a/vortex-layout/src/layouts/chunked/reader.rs b/vortex-layout/src/layouts/chunked/reader.rs index 39bd8b27b7c..769441e3bc2 100644 --- a/vortex-layout/src/layouts/chunked/reader.rs +++ b/vortex-layout/src/layouts/chunked/reader.rs @@ -39,8 +39,6 @@ pub struct ChunkedReader { layout: ChunkedLayout, name: Arc, lazy_children: LazyReaderChildren, - /// Row offset for each chunk - chunk_offsets: Vec, } static UNKNOWN: LazyLock> = LazyLock::new(|| Arc::from("chunked-child")); @@ -53,13 +51,6 @@ impl ChunkedReader { session: &VortexSession, ) -> Self { let nchildren = layout.nchildren(); - - let mut chunk_offsets = vec![0; nchildren + 1]; - for i in 1..nchildren { - chunk_offsets[i] = chunk_offsets[i - 1] + layout.children.child_row_count(i - 1); - } - chunk_offsets[nchildren] = layout.row_count(); - let dtypes = vec![layout.dtype.clone(); nchildren]; // format!() has non-marginal overhead for short queries like random @@ -84,7 +75,6 @@ impl ChunkedReader { layout, name, lazy_children, - chunk_offsets, } } @@ -94,22 +84,25 @@ impl ChunkedReader { } fn chunk_offset(&self, idx: usize) -> u64 { - self.chunk_offsets.get(idx).copied().unwrap_or_else(|| { + if idx >= self.layout.chunk_offsets.len() { vortex_panic!( "Internal error: Chunk offset {idx} out of bounds (num_children: {}, num_offsets: {}). \ This indicates a bug in ChunkedReader initialization or chunk_range calculation.", self.layout.nchildren(), - self.chunk_offsets.len() + self.layout.chunk_offsets.len() ) - }) + } + self.layout.chunk_offsets[idx] } fn chunk_range(&self, row_range: &Range) -> Range { let start_chunk = self + .layout .chunk_offsets .binary_search(&row_range.start) .unwrap_or_else(|x| x.saturating_sub(1)); let end_chunk = self + .layout .chunk_offsets .binary_search(&row_range.end) .unwrap_or_else(|x| x);