MCPcopy Create free account
hub / github.com/apache/datafusion / scatter

Function scatter

datafusion/physical-expr-common/src/utils.rs:76–102  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

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.
76pub 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
104fn scatter_array(
105 truthy: &dyn Array,

Callers 15

expr_or_exprMethod · 0.85
evaluate_selectionMethod · 0.85
scatter_intFunction · 0.85
scatter_with_null_maskFunction · 0.85
scatter_booleanFunction · 0.85
scatter_all_trueFunction · 0.85
scatter_all_falseFunction · 0.85
scatter_emptyFunction · 0.85
scatter_string_testFunction · 0.85
scatter_string_view_testFunction · 0.85

Calls 6

scatter_arrayFunction · 0.85
null_countMethod · 0.80
sliceMethod · 0.80
lenMethod · 0.45
data_typeMethod · 0.45
valuesMethod · 0.45

Tested by 12

scatter_intFunction · 0.68
scatter_with_null_maskFunction · 0.68
scatter_all_trueFunction · 0.68
scatter_all_falseFunction · 0.68
scatter_emptyFunction · 0.68
scatter_string_testFunction · 0.68
scatter_string_view_testFunction · 0.68
scatter_dictionary_testFunction · 0.68
scatter_filter_roundtripFunction · 0.68

Used in the wild real call sites across dependent graphs

searching dependent graphs…