Scatter `truthy` array by boolean mask. When the mask evaluates `true`, next values of `truthy` are taken, when the mask evaluates `false` values null values are filled. # Arguments `mask` - Boolean values used to determine where to put the `truthy` values `truthy` - All values of this array are to scatter according to `mask` into final result.
(mask: &BooleanArray, truthy: &dyn Array)
| 74 | /// * `mask` - Boolean values used to determine where to put the `truthy` values |
| 75 | /// * `truthy` - All values of this array are to scatter according to `mask` into final result. |
| 76 | pub fn scatter(mask: &BooleanArray, truthy: &dyn Array) -> Result<ArrayRef> { |
| 77 | let mask = match mask.null_count() { |
| 78 | 0 => Cow::Borrowed(mask), |
| 79 | n if n == mask.len() => { |
| 80 | return Ok(new_null_array(truthy.data_type(), mask.len())); |
| 81 | } |
| 82 | _ => Cow::Owned(prep_null_mask_filter(mask)), |
| 83 | }; |
| 84 | |
| 85 | let output_len = mask.len(); |
| 86 | |
| 87 | // Fast path: no true values mean all-null object |
| 88 | if !mask.has_true() { |
| 89 | return Ok(new_null_array(truthy.data_type(), output_len)); |
| 90 | } |
| 91 | |
| 92 | // Fast path: all true means output = truthy |
| 93 | if mask.null_count() == 0 && !mask.has_false() { |
| 94 | return Ok(truthy.slice(0, truthy.len())); |
| 95 | } |
| 96 | |
| 97 | let count = mask.true_count(); |
| 98 | let selectivity = count as f64 / output_len as f64; |
| 99 | let mask_buffer = mask.values(); |
| 100 | |
| 101 | scatter_array(truthy, mask_buffer, output_len, selectivity) |
| 102 | } |
| 103 | |
| 104 | fn scatter_array( |
| 105 | truthy: &dyn Array, |
searching dependent graphs…