Skip to content
Merged
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
15 changes: 8 additions & 7 deletions parquet/src/encodings/decoding.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1008,7 +1008,8 @@ pub struct DeltaByteArrayDecoder<T: DataType> {
suffix_decoder: Option<DeltaLengthByteArrayDecoder<ByteArrayType>>,

// The last byte array, used to derive the current prefix
previous_value: Vec<u8>,
// Stored as Bytes to avoid clone allocation when creating output
previous_value: Bytes,

// Number of values left
num_values: usize,
Expand All @@ -1030,7 +1031,7 @@ impl<T: DataType> DeltaByteArrayDecoder<T> {
prefix_lengths: vec![],
current_idx: 0,
suffix_decoder: None,
previous_value: vec![],
previous_value: Bytes::new(),
num_values: 0,
_phantom: PhantomData,
}
Expand All @@ -1053,7 +1054,7 @@ impl<T: DataType> Decoder<T> for DeltaByteArrayDecoder<T> {
self.suffix_decoder = Some(suffix_decoder);
self.num_values = num_prefixes;
self.current_idx = 0;
self.previous_value.clear();
self.previous_value = Bytes::new();
Ok(())
}
_ => Err(general_err!(
Expand Down Expand Up @@ -1081,14 +1082,14 @@ impl<T: DataType> Decoder<T> for DeltaByteArrayDecoder<T> {
let prefix_len = self.prefix_lengths[self.current_idx] as usize;

// Concatenate prefix with suffix
let mut result = Vec::new();
let mut result = Vec::with_capacity(prefix_len + suffix.len());
Copy link
Contributor

Choose a reason for hiding this comment

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

makes sense to allocate the correct size.

result.extend_from_slice(&self.previous_value[0..prefix_len]);
result.extend_from_slice(suffix);

let data = Bytes::from(result.clone());
Copy link
Contributor

Choose a reason for hiding this comment

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

this certainly seems to save a clone. Looks good to me 👍

item.set_from_bytes(data);
let data = Bytes::from(result);
item.set_from_bytes(data.clone());

self.previous_value = result;
self.previous_value = data;
self.current_idx += 1;
}

Expand Down
Loading