Extends this buffer with a list of keys For each value `key` in `keys` this will insert `&dict_values[dict_offsets[key]..dict_offsets[key+1]]` Note: This will validate offsets are valid
(
&mut self,
keys: &[K],
dict_offsets: &[V],
dict_values: &[u8],
)
| 90 | /// |
| 91 | /// Note: This will validate offsets are valid |
| 92 | pub fn extend_from_dictionary<K: ArrowNativeType, V: ArrowNativeType>( |
| 93 | &mut self, |
| 94 | keys: &[K], |
| 95 | dict_offsets: &[V], |
| 96 | dict_values: &[u8], |
| 97 | ) -> Result<()> { |
| 98 | self.offsets.reserve(keys.len()); |
| 99 | |
| 100 | for key in keys { |
| 101 | let index = key.as_usize(); |
| 102 | if index + 1 >= dict_offsets.len() { |
| 103 | return Err(general_err!( |
| 104 | "dictionary key beyond bounds of dictionary: 0..{}", |
| 105 | dict_offsets.len().saturating_sub(1) |
| 106 | )); |
| 107 | } |
| 108 | let start_offset = dict_offsets[index].as_usize(); |
| 109 | let end_offset = dict_offsets[index + 1].as_usize(); |
| 110 | |
| 111 | // Dictionary values are verified when decoding dictionary page |
| 112 | self.values |
| 113 | .extend_from_slice(&dict_values[start_offset..end_offset]); |
| 114 | let index_offset = I::from_usize(self.values.len()) |
| 115 | .ok_or_else(|| general_err!("index overflow decoding byte array"))?; |
| 116 | self.offsets.push(index_offset); |
| 117 | } |
| 118 | Ok(()) |
| 119 | } |
| 120 | |
| 121 | /// Validates that `&self.values[start_offset..]` is a valid UTF-8 sequence |
| 122 | /// |