Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 5 additions & 7 deletions vortex-layout/src/layouts/chunked/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -132,12 +131,11 @@ pub struct ChunkedLayout {

impl ChunkedLayout {
pub fn new(row_count: u64, dtype: DType, children: Arc<dyn LayoutChildren>) -> 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()],
Comment on lines 105 to 140

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

revert or use mut iter if you want perf

row_count,
Expand Down
19 changes: 6 additions & 13 deletions vortex-layout/src/layouts/chunked/reader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,6 @@ pub struct ChunkedReader {
layout: ChunkedLayout,
name: Arc<str>,
lazy_children: LazyReaderChildren,
/// Row offset for each chunk
chunk_offsets: Vec<u64>,
}

static UNKNOWN: LazyLock<Arc<str>> = LazyLock::new(|| Arc::from("chunked-child"));
Expand All @@ -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
Expand All @@ -84,7 +75,6 @@ impl ChunkedReader {
layout,
name,
lazy_children,
chunk_offsets,
}
}

Expand All @@ -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<u64>) -> Range<usize> {
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);
Expand Down
Loading