Skip to content
This repository has been archived by the owner on Jan 11, 2021. It is now read-only.

Support FixedLenByteArrayType in DeltaByteArrayEncoder #106

Merged
merged 1 commit into from
Apr 29, 2018
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
25 changes: 20 additions & 5 deletions src/encodings/decoding.rs
Original file line number Diff line number Diff line change
Expand Up @@ -777,11 +777,15 @@ impl<T: DataType> DeltaByteArrayDecoder<T> {

impl<'m, T: DataType> Decoder<T> for DeltaByteArrayDecoder<T> {
default fn set_data(&mut self, _: ByteBufferPtr, _: usize) -> Result<()> {
Err(general_err!("DeltaByteArrayDecoder only support ByteArrayType"))
Err(general_err!(
"DeltaByteArrayDecoder only supports ByteArrayType and FixedLenByteArrayType"
))
}

default fn get(&mut self, _: &mut [T::T]) -> Result<usize> {
Err(general_err!("DeltaByteArrayDecoder only support ByteArrayType"))
Err(general_err!(
"DeltaByteArrayDecoder only supports ByteArrayType and FixedLenByteArrayType"
))
}

fn values_left(&self) -> usize {
Expand Down Expand Up @@ -815,13 +819,13 @@ impl<> Decoder<ByteArrayType> for DeltaByteArrayDecoder<ByteArrayType> {
assert!(self.suffix_decoder.is_some());

let num_values = cmp::min(buffer.len(), self.num_values);
let mut v: [ByteArray; 1] = [ByteArray::new(); 1];
Copy link
Collaborator

Choose a reason for hiding this comment

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

👍

for i in 0..num_values {
// Process suffix
// TODO: this is awkward - maybe we should add a non-vectorized API?
let mut suffix = vec![ByteArray::new(); 1];
let suffix_decoder = self.suffix_decoder.as_mut().unwrap();
suffix_decoder.get(&mut suffix[..])?;
let suffix = suffix[0].data();
suffix_decoder.get(&mut v[..])?;
let suffix = v[0].data();

// Extract current prefix length, can be 0
let prefix_len = self.prefix_lengths[self.current_idx] as usize;
Expand All @@ -842,6 +846,17 @@ impl<> Decoder<ByteArrayType> for DeltaByteArrayDecoder<ByteArrayType> {
}
}

impl<> Decoder<FixedLenByteArrayType> for DeltaByteArrayDecoder<FixedLenByteArrayType> {
fn set_data(&mut self, data: ByteBufferPtr, num_values: usize) -> Result<()> {
let s: &mut DeltaByteArrayDecoder<ByteArrayType> = unsafe { mem::transmute(self) };
Copy link
Collaborator

Choose a reason for hiding this comment

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

That is an interesting approach!

s.set_data(data, num_values)
}

fn get(&mut self, buffer: &mut [ByteArray]) -> Result<usize> {
let s: &mut DeltaByteArrayDecoder<ByteArrayType> = unsafe { mem::transmute(self) };
s.get(buffer)
}
}

#[cfg(test)]
mod tests {
Expand Down
17 changes: 15 additions & 2 deletions src/encodings/encoding.rs
Original file line number Diff line number Diff line change
Expand Up @@ -832,15 +832,15 @@ impl<T: DataType> DeltaByteArrayEncoder<T> {

impl<T: DataType> Encoder<T> for DeltaByteArrayEncoder<T> {
default fn put(&mut self, _values: &[T::T]) -> Result<()> {
panic!("DeltaByteArrayEncoder only supports ByteArrayType");
panic!("DeltaByteArrayEncoder only supports ByteArrayType and FixedLenByteArrayType");
}

fn encoding(&self) -> Encoding {
Encoding::DELTA_BYTE_ARRAY
}

default fn flush_buffer(&mut self) -> Result<ByteBufferPtr> {
panic!("DeltaByteArrayEncoder only supports ByteArrayType");
panic!("DeltaByteArrayEncoder only supports ByteArrayType and FixedLenByteArrayType");
}
}

Expand Down Expand Up @@ -883,6 +883,18 @@ impl Encoder<ByteArrayType> for DeltaByteArrayEncoder<ByteArrayType> {
}
}

impl Encoder<FixedLenByteArrayType> for DeltaByteArrayEncoder<FixedLenByteArrayType> {
fn put(&mut self, values: &[ByteArray]) -> Result<()> {
let s: &mut DeltaByteArrayEncoder<ByteArrayType> = unsafe { mem::transmute(self) };
s.put(values)
}

fn flush_buffer(&mut self) -> Result<ByteBufferPtr> {
let s: &mut DeltaByteArrayEncoder<ByteArrayType> = unsafe { mem::transmute(self) };
s.flush_buffer()
}
}


#[cfg(test)]
mod tests {
Expand Down Expand Up @@ -946,6 +958,7 @@ mod tests {
fn test_fixed_lenbyte_array() {
FixedLenByteArrayType::test(Encoding::PLAIN, TEST_SET_SIZE, 100);
FixedLenByteArrayType::test(Encoding::PLAIN_DICTIONARY, TEST_SET_SIZE, 100);
FixedLenByteArrayType::test(Encoding::DELTA_BYTE_ARRAY, TEST_SET_SIZE, 100);
}

trait EncodingTester<T: DataType> {
Expand Down