Skip to content

Commit c6359bf

Browse files
authored
Avoid copy/allocation when read view types from parquet (#5877)
* avoid copy/allocation when build from offset buffer * avoid hard code block id
1 parent 2d17bf0 commit c6359bf

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

parquet/src/arrow/buffer/offset_buffer.rs

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -156,16 +156,19 @@ impl<I: OffsetSizeTrait> OffsetBuffer<I> {
156156

157157
fn build_generic_byte_view(self) -> GenericByteViewBuilder<BinaryViewType> {
158158
let mut builder = GenericByteViewBuilder::<BinaryViewType>::with_capacity(self.len());
159-
let mut values = self.values;
159+
let buffer = self.values.into();
160+
let block = builder.append_block(buffer);
160161
for window in self.offsets.windows(2) {
161162
let start = window[0];
162163
let end = window[1];
163164
let len = (end - start).to_usize().unwrap();
164-
let b = values.drain(..len).collect::<Vec<u8>>();
165-
if b.is_empty() {
166-
builder.append_null();
165+
166+
if len != 0 {
167+
builder
168+
.try_append_view(block, start.as_usize() as u32, len as u32)
169+
.unwrap();
167170
} else {
168-
builder.append_value(b);
171+
builder.append_null();
169172
}
170173
}
171174
builder

0 commit comments

Comments
 (0)