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

Function zip_impl

arrow-select/src/zip.rs:148–201  ·  view source on GitHub ↗
(
    mask: &BooleanArray,
    truthy: &ArrayData,
    truthy_is_scalar: bool,
    falsy: &ArrayData,
    falsy_is_scalar: bool,
)

Source from the content-addressed store, hash-verified

146}
147
148fn zip_impl(
149 mask: &BooleanArray,
150 truthy: &ArrayData,
151 truthy_is_scalar: bool,
152 falsy: &ArrayData,
153 falsy_is_scalar: bool,
154) -> Result<ArrayRef, ArrowError> {
155 let mut mutable = MutableArrayData::new(vec![truthy, falsy], false, truthy.len());
156
157 // the SlicesIterator slices only the true values. So the gaps left by this iterator we need to
158 // fill with falsy values
159
160 // keep track of how much is filled
161 let mut filled = 0;
162
163 let mask_buffer = maybe_prep_null_mask_filter(mask);
164 SlicesIterator::from(&mask_buffer).for_each(|(start, end)| {
165 // the gap needs to be filled with falsy values
166 if start > filled {
167 if falsy_is_scalar {
168 for _ in filled..start {
169 // Copy the first item from the 'falsy' array into the output buffer.
170 mutable.extend(1, 0, 1);
171 }
172 } else {
173 mutable.extend(1, filled, start);
174 }
175 }
176 // fill with truthy values
177 if truthy_is_scalar {
178 for _ in start..end {
179 // Copy the first item from the 'truthy' array into the output buffer.
180 mutable.extend(0, 0, 1);
181 }
182 } else {
183 mutable.extend(0, start, end);
184 }
185 filled = end;
186 });
187 // the remaining part is falsy
188 if filled < mask.len() {
189 if falsy_is_scalar {
190 for _ in filled..mask.len() {
191 // Copy the first item from the 'falsy' array into the output buffer.
192 mutable.extend(1, 0, 1);
193 }
194 } else {
195 mutable.extend(1, filled, mask.len());
196 }
197 }
198
199 let data = mutable.freeze();
200 Ok(make_array(data))
201}
202
203/// Zipper for 2 scalars
204///

Callers 2

zipFunction · 0.85
create_outputMethod · 0.85

Calls 5

freezeMethod · 0.80
make_arrayFunction · 0.50
lenMethod · 0.45
extendMethod · 0.45

Tested by

no test coverage detected