From 77ff4337f8e6999903a5d09ca51d0b8dec906094 Mon Sep 17 00:00:00 2001 From: Jefffrey Date: Sat, 28 Sep 2024 20:41:00 +1000 Subject: [PATCH] Implement PrimitiveValueDecoder::decode for BooleanDecoder --- src/encoding/boolean.rs | 33 +++++++++++++++++++++++++++++++-- 1 file changed, 31 insertions(+), 2 deletions(-) diff --git a/src/encoding/boolean.rs b/src/encoding/boolean.rs index fdf596fb..0a3f1b33 100644 --- a/src/encoding/boolean.rs +++ b/src/encoding/boolean.rs @@ -23,7 +23,10 @@ use arrow::{ }; use bytes::Bytes; -use crate::{error::Result, memory::EstimateMemory}; +use crate::{ + error::{OutOfSpecSnafu, Result}, + memory::EstimateMemory, +}; use super::{ byte::{ByteRleDecoder, ByteRleEncoder}, @@ -76,7 +79,33 @@ impl Iterator for BooleanDecoder { } } -impl PrimitiveValueDecoder for BooleanDecoder {} +impl PrimitiveValueDecoder for BooleanDecoder { + // TODO: can probably implement this better, just copying from iter for now + fn decode(&mut self, out: &mut [bool]) -> Result<()> { + for x in out.iter_mut() { + // read more data if necessary + if self.bits_in_data == 0 { + match self.decoder.next() { + Some(Ok(data)) => { + self.data = data as u8; + self.bits_in_data = 8; + *x = self.value(); + } + Some(Err(err)) => return Err(err), + None => { + return OutOfSpecSnafu { + msg: "Array length less than expected", + } + .fail() + } + } + } else { + *x = self.value(); + } + } + Ok(()) + } +} /// ORC encodes validity starting from MSB, whilst Arrow encodes it /// from LSB. After bytes are filled with the present bits, they are