Skip to content
Closed
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
9 changes: 9 additions & 0 deletions parquet/src/arrow/buffer/offset_buffer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,15 @@ impl<I: OffsetSizeTrait> OffsetBuffer<I> {
) -> Result<()> {
self.offsets.reserve(keys.len());

// Pre-size `values` from the dictionary's average value length. Exact when
// values are uniformly sized, which is the large-value case this targets.
// `try_reserve` because a skewed dictionary can inflate the estimate above
// the real output size, and the dictionary comes from an untrusted file.
let dict_len = dict_offsets.len().saturating_sub(1);
if let Some(avg_len) = dict_values.len().checked_div(dict_len) {
let _ = self.values.try_reserve(avg_len.saturating_mul(keys.len()));
}

for key in keys {
let index = key.as_usize();
if index + 1 >= dict_offsets.len() {
Expand Down
Loading