diff --git a/read_buffer/src/column/encoding/scalar/rle.rs b/read_buffer/src/column/encoding/scalar/rle.rs index a30b038702..a2f38781a5 100644 --- a/read_buffer/src/column/encoding/scalar/rle.rs +++ b/read_buffer/src/column/encoding/scalar/rle.rs @@ -13,7 +13,7 @@ pub const ENCODING_NAME: &str = "RLE"; /// An RLE encoding is one where identical "runs" of values in the column are /// stored as a tuple: `(run_length, value)`, where `run_length` indicates the /// number of times the value is to be repeated. -#[derive(Debug, Default)] +#[derive(Debug, Default, PartialEq)] pub struct RLE where T: PartialOrd + Debug, @@ -383,7 +383,10 @@ impl RLE { /// /// TODO(edd): a sparse index on this can help with materialisation cost by /// providing starting indexes into the in the run length collection. - pub fn value(&self, row_id: u32) -> Option { + pub fn value(&self, row_id: u32) -> Option + where + U: From, + { assert!( row_id < self.num_rows(), "row_id {:?} out of bounds for {:?} rows", @@ -395,7 +398,7 @@ impl RLE { for (rl, v) in &self.run_lengths { if ordinal_offset + rl > row_id { // this run-length overlaps desired row id - return *v; + return v.map(U::from); } ordinal_offset += rl; } @@ -441,7 +444,10 @@ impl RLE { /// Panics if a requested row ID is out of bounds of the ordinal offset of /// a logical value. /// - pub fn values(&self, row_ids: &[u32], mut dst: Vec>) -> Vec> { + pub fn values(&self, row_ids: &[u32], mut dst: Vec>) -> Vec> + where + U: From, + { assert!(!row_ids.is_empty(), "no row IDs provided"); assert!( row_ids.len() <= self.num_rows() as usize, @@ -479,7 +485,7 @@ impl RLE { } // this encoded entry covers the row_id we want. - dst.push(curr_value); + dst.push(curr_value.map(U::from)); curr_logical_row_id += 1; // move forwards a logical row curr_entry_rl -= 1; @@ -493,12 +499,15 @@ impl RLE { /// the column. /// /// NULL values are represented by None. - pub fn all_values(&self, mut dst: Vec>) -> Vec> { + pub fn all_values(&self, mut dst: Vec>) -> Vec> + where + U: From, + { dst.clear(); dst.reserve(self.num_rows as usize); for (rl, v) in &self.run_lengths { - dst.extend(iter::repeat(v).take(*rl as usize)); + dst.extend(iter::repeat(v.map(U::from)).take(*rl as usize)); } dst } @@ -573,7 +582,10 @@ impl RLE { /// Returns the summation of the logical (decoded) values for the provided /// row IDs. - pub fn sum(&self, _row_ids: &[u32]) -> Option { + pub fn sum(&self, _row_ids: &[u32]) -> Option + where + U: From, + { todo!() } @@ -591,13 +603,19 @@ impl RLE { /// Returns the minimum logical (decoded) value from the provided /// row IDs. - pub fn min(&self, _row_ids: &[u32]) -> Option { + pub fn min(&self, _row_ids: &[u32]) -> Option + where + U: From, + { todo!() } /// Returns the maximum logical (decoded) value from the provided /// row IDs. - pub fn max(&self, _row_ids: &[u32]) -> Option { + pub fn max(&self, _row_ids: &[u32]) -> Option + where + U: From, + { todo!() } } @@ -840,7 +858,7 @@ mod test { enc.push_additional(Some(90), 2); enc.push(21); - assert_eq!(enc.value(0), None); + assert_eq!(enc.value::(0), None); assert_eq!(enc.value(1), Some(45)); assert_eq!(enc.value(3), Some(45)); assert_eq!(enc.value(4), Some(90)); @@ -918,7 +936,7 @@ mod test { let mut enc: RLE = RLE::default(); enc.push_none(); - assert_eq!(enc.all_values(vec![]), vec![None]); + assert_eq!(enc.all_values::(vec![]), vec![None]); } #[test]