Skip to content

Commit 42e90aa

Browse files
committed
fix issue with off-by-one when top-level array has buffer
1 parent d72be3d commit 42e90aa

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

vortex-serde/src/layouts/write/writer.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,6 @@ impl<W: VortexWrite> LayoutWriter<W> {
117117

118118
async fn write_metadata_arrays(&mut self) -> VortexResult<NestedLayout> {
119119
let mut column_layouts = VecDeque::with_capacity(self.column_chunks.len());
120-
121120
for mut chunk in mem::take(&mut self.column_chunks) {
122121
let len = chunk.byte_offsets.len() - 1;
123122
let mut chunks: VecDeque<Layout> = chunk

vortex-serde/src/messages.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,10 +148,16 @@ impl<'a> WriteFlatBuffer for IPCArray<'a> {
148148
),
149149
};
150150

151+
// Assign buffer indices for all child arrays.
152+
// The second tuple element holds the buffer_index for this Array subtree. If this array
153+
// has a buffer, that is its buffer index. If it does not, that buffer index belongs
154+
// to one of the children.
155+
let child_buffer_offset = self.1 + if self.0.buffer().is_some() { 1 } else { 0 };
156+
151157
let children = column_data
152158
.children()
153159
.iter()
154-
.scan(self.1, |buffer_offset, child| {
160+
.scan(child_buffer_offset, |buffer_offset, child| {
155161
// Update the number of buffers required.
156162
let msg = IPCArray(child, *buffer_offset).write_flatbuffer(fbb);
157163
*buffer_offset += child.cumulative_nbuffers();

0 commit comments

Comments
 (0)