MCPcopy Create free account
hub / github.com/apache/arrow-rs / decode_binary

Function decode_binary

arrow-row/src/variable.rs:268–310  ·  view source on GitHub ↗

Decodes a binary array from `rows` with the provided `options`

(
    rows: &mut [&[u8]],
    options: SortOptions,
)

Source from the content-addressed store, hash-verified

266
267/// Decodes a binary array from `rows` with the provided `options`
268pub 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
312fn decode_binary_view_inner(
313 rows: &mut [&[u8]],

Callers

nothing calls this directly

Calls 14

collect_boolFunction · 0.85
null_sentinelFunction · 0.85
decoded_lenFunction · 0.85
decode_blocksFunction · 0.85
extend_from_sliceMethod · 0.80
add_bufferMethod · 0.80
lenMethod · 0.45
iterMethod · 0.45
appendMethod · 0.45
as_slice_mutMethod · 0.45
null_bit_bufferMethod · 0.45
null_countMethod · 0.45

Tested by

no test coverage detected