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

Method mask_sparse_skip_without_nulls

arrow-array/src/array/union_array.rs:409–458  ·  view source on GitHub ↗

Computes the logical nulls for a sparse union, optimized for when there's a lot of fields without nulls

(&self, nulls: Vec<(i8, NullBuffer)>)

Source from the content-addressed store, hash-verified

407
408 /// Computes the logical nulls for a sparse union, optimized for when there's a lot of fields without nulls
409 fn mask_sparse_skip_without_nulls(&self, nulls: Vec<(i8, NullBuffer)>) -> BooleanBuffer {
410 // Example logic for a union with 5 fields, a, b & c with nulls, d & e without nulls:
411 // let [a_nulls, b_nulls, c_nulls] = nulls;
412 // let [is_a, is_b, is_c] = masks;
413 // let is_d_or_e = !(is_a | is_b | is_c)
414 // let union_chunk_nulls = is_d_or_e | (is_a & a_nulls) | (is_b & b_nulls) | (is_c & c_nulls)
415 let fold = |(with_nulls_selected, union_nulls), (is_field, field_nulls)| {
416 (
417 with_nulls_selected | is_field,
418 union_nulls | (is_field & field_nulls),
419 )
420 };
421
422 self.mask_sparse_helper(
423 nulls,
424 |type_ids_chunk_array, nulls_masks_iters| {
425 let (with_nulls_selected, union_nulls) = nulls_masks_iters
426 .iter_mut()
427 .map(|(field_type_id, field_nulls)| {
428 let field_nulls = field_nulls.next().unwrap();
429 let is_field = selection_mask(type_ids_chunk_array, *field_type_id);
430
431 (is_field, field_nulls)
432 })
433 .fold((0, 0), fold);
434
435 // In the example above, this is the is_d_or_e = !(is_a | is_b) part
436 let without_nulls_selected = !with_nulls_selected;
437
438 // if a field without nulls is selected, the value is always true(set bit)
439 // otherwise, the true/set bits have been computed above
440 without_nulls_selected | union_nulls
441 },
442 |type_ids_remainder, bit_chunks| {
443 let (with_nulls_selected, union_nulls) = bit_chunks
444 .iter()
445 .map(|(field_type_id, field_bit_chunks)| {
446 let field_nulls = field_bit_chunks.remainder_bits();
447 let is_field = selection_mask(type_ids_remainder, *field_type_id);
448
449 (is_field, field_nulls)
450 })
451 .fold((0, 0), fold);
452
453 let without_nulls_selected = !with_nulls_selected;
454
455 without_nulls_selected | union_nulls
456 },
457 )
458 }
459
460 /// Computes the logical nulls for a sparse union, optimized for when there's a lot of fields fully null
461 fn mask_sparse_skip_fully_null(&self, mut nulls: Vec<(i8, NullBuffer)>) -> BooleanBuffer {

Callers 1

logical_nullsMethod · 0.80

Calls 5

selection_maskFunction · 0.85
mask_sparse_helperMethod · 0.80
remainder_bitsMethod · 0.80
nextMethod · 0.45
iterMethod · 0.45

Tested by

no test coverage detected