Decodes a binary array from `rows` with the provided `options`
(
rows: &mut [&[u8]],
options: SortOptions,
)
| 266 | |
| 267 | /// Decodes a binary array from `rows` with the provided `options` |
| 268 | pub fn decode_binary<I: OffsetSizeTrait>( |
| 269 | rows: &mut [&[u8]], |
| 270 | options: SortOptions, |
| 271 | ) -> GenericBinaryArray<I> { |
| 272 | let len = rows.len(); |
| 273 | let mut null_count = 0; |
| 274 | let nulls = MutableBuffer::collect_bool(len, |x| { |
| 275 | let valid = rows[x][0] != null_sentinel(options); |
| 276 | null_count += !valid as usize; |
| 277 | valid |
| 278 | }); |
| 279 | |
| 280 | let values_capacity = rows.iter().map(|row| decoded_len(row, options)).sum(); |
| 281 | let mut offsets = BufferBuilder::<I>::new(len + 1); |
| 282 | offsets.append(I::zero()); |
| 283 | let mut values = MutableBuffer::new(values_capacity); |
| 284 | |
| 285 | for row in rows { |
| 286 | let offset = decode_blocks(row, options, |b| values.extend_from_slice(b)); |
| 287 | *row = &row[offset..]; |
| 288 | offsets.append(I::from_usize(values.len()).expect("offset overflow")) |
| 289 | } |
| 290 | |
| 291 | if options.descending { |
| 292 | values.as_slice_mut().iter_mut().for_each(|o| *o = !*o) |
| 293 | } |
| 294 | |
| 295 | let d = match I::IS_LARGE { |
| 296 | true => DataType::LargeBinary, |
| 297 | false => DataType::Binary, |
| 298 | }; |
| 299 | |
| 300 | let builder = ArrayDataBuilder::new(d) |
| 301 | .len(len) |
| 302 | .null_count(null_count) |
| 303 | .null_bit_buffer(Some(nulls.into())) |
| 304 | .add_buffer(offsets.finish()) |
| 305 | .add_buffer(values.into()); |
| 306 | |
| 307 | // SAFETY: |
| 308 | // Valid by construction above |
| 309 | unsafe { GenericBinaryArray::from(builder.build_unchecked()) } |
| 310 | } |
| 311 | |
| 312 | fn decode_binary_view_inner( |
| 313 | rows: &mut [&[u8]], |
nothing calls this directly
no test coverage detected