Decodes a RunEndEncodedArray from `rows` with the provided `options` # Safety `rows` must contain valid data for the provided `converter`
(
converter: &RowConverter,
rows: &mut [&[u8]],
field: &SortField,
validate_utf8: bool,
)
| 85 | /// |
| 86 | /// `rows` must contain valid data for the provided `converter` |
| 87 | pub unsafe fn decode<R: RunEndIndexType>( |
| 88 | converter: &RowConverter, |
| 89 | rows: &mut [&[u8]], |
| 90 | field: &SortField, |
| 91 | validate_utf8: bool, |
| 92 | ) -> Result<RunArray<R>, ArrowError> { |
| 93 | if rows.is_empty() { |
| 94 | let values = unsafe { converter.convert_raw(&mut [], validate_utf8) }?; |
| 95 | let run_ends_array = PrimitiveArray::<R>::try_new(ScalarBuffer::from(vec![]), None)?; |
| 96 | return RunArray::<R>::try_new(&run_ends_array, &values[0]); |
| 97 | } |
| 98 | |
| 99 | // Decode each row's REE data and collect the decoded values |
| 100 | let mut decoded_values = Vec::new(); |
| 101 | let mut run_ends = Vec::new(); |
| 102 | let mut unique_row_indices = Vec::new(); |
| 103 | |
| 104 | // Process each row to extract its REE data (following decode_binary pattern) |
| 105 | let mut decoded_data = Vec::new(); |
| 106 | for (idx, row) in rows.iter_mut().enumerate() { |
| 107 | decoded_data.clear(); |
| 108 | // Extract the decoded value data from this row |
| 109 | let consumed = variable::decode_blocks(row, field.options, |block| { |
| 110 | decoded_data.extend_from_slice(block); |
| 111 | }); |
| 112 | |
| 113 | // Handle bit inversion for descending sort (following decode_binary pattern) |
| 114 | if field.options.descending { |
| 115 | decoded_data.iter_mut().for_each(|b| *b = !*b); |
| 116 | } |
| 117 | |
| 118 | // Update the row to point past the consumed REE data |
| 119 | *row = &row[consumed..]; |
| 120 | |
| 121 | // Check if this decoded value is the same as the previous one to identify runs |
| 122 | let is_new_run = |
| 123 | idx == 0 || decoded_data != decoded_values[*unique_row_indices.last().unwrap()]; |
| 124 | |
| 125 | if is_new_run { |
| 126 | // This is a new unique value - end the previous run if any |
| 127 | if idx > 0 { |
| 128 | run_ends.push(R::Native::usize_as(idx)); |
| 129 | } |
| 130 | unique_row_indices.push(decoded_values.len()); |
| 131 | let capacity = decoded_data.capacity(); |
| 132 | decoded_values.push(std::mem::replace( |
| 133 | &mut decoded_data, |
| 134 | Vec::with_capacity(capacity), |
| 135 | )); |
| 136 | } |
| 137 | } |
| 138 | // Add the final run end |
| 139 | run_ends.push(R::Native::usize_as(rows.len())); |
| 140 | |
| 141 | // Convert the unique decoded values using the row converter |
| 142 | let mut unique_rows: Vec<&[u8]> = decoded_values.iter().map(|v| v.as_slice()).collect(); |
| 143 | let values = if unique_rows.is_empty() { |
| 144 | unsafe { converter.convert_raw(&mut [], validate_utf8) }? |
no test coverage detected