MCPcopy Create free account
hub / github.com/apache/arrow / PropagateNullsSpans

Function PropagateNullsSpans

cpp/src/arrow/compute/exec.cc:1212–1271  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1210}
1211
1212void PropagateNullsSpans(const ExecSpan& batch, ArraySpan* out) {
1213 if (out->type->id() == Type::NA) {
1214 // Null output type is a no-op (rare when this would happen but we at least
1215 // will test for it)
1216 return;
1217 }
1218
1219 std::vector<const ArraySpan*> arrays_with_nulls;
1220 bool is_all_null = false;
1221 for (const ExecValue& value : batch.values) {
1222 auto null_generalization = NullGeneralization::Get(value);
1223 if (null_generalization == NullGeneralization::ALL_NULL) {
1224 is_all_null = true;
1225 }
1226 if (null_generalization != NullGeneralization::ALL_VALID && value.is_array()) {
1227 arrays_with_nulls.push_back(&value.array);
1228 }
1229 }
1230 uint8_t* out_bitmap = out->buffers[0].data;
1231 if (is_all_null) {
1232 // An all-null value (scalar null or all-null array) gives us a short
1233 // circuit opportunity
1234 // OK, the output should be all null
1235 out->null_count = out->length;
1236 bit_util::SetBitsTo(out_bitmap, out->offset, out->length, false);
1237 return;
1238 }
1239
1240 out->null_count = kUnknownNullCount;
1241 if (arrays_with_nulls.empty()) {
1242 // No arrays with nulls case
1243 out->null_count = 0;
1244 if (out_bitmap != nullptr) {
1245 // An output buffer was allocated, so we fill it with all valid
1246 bit_util::SetBitsTo(out_bitmap, out->offset, out->length, true);
1247 }
1248 } else if (arrays_with_nulls.size() == 1) {
1249 // One array
1250 const ArraySpan& arr = *arrays_with_nulls[0];
1251
1252 // Reuse the null count if it's known
1253 out->null_count = arr.null_count;
1254 CopyBitmap(arr.buffers[0].data, arr.offset, arr.length, out_bitmap, out->offset);
1255 } else {
1256 // More than one array. We use BitmapAnd to intersect their bitmaps
1257 auto Accumulate = [&](const ArraySpan& left, const ArraySpan& right) {
1258 DCHECK(left.buffers[0].data != nullptr);
1259 DCHECK(right.buffers[0].data != nullptr);
1260 BitmapAnd(left.buffers[0].data, left.offset, right.buffers[0].data, right.offset,
1261 out->length, out->offset, out_bitmap);
1262 };
1263 // Seed the output bitmap with the & of the first two bitmaps
1264 Accumulate(*arrays_with_nulls[0], *arrays_with_nulls[1]);
1265
1266 // Accumulate the rest
1267 for (size_t i = 2; i < arrays_with_nulls.size(); ++i) {
1268 Accumulate(*out, *arrays_with_nulls[i]);
1269 }

Callers 2

TEST_FFunction · 0.85
ExecuteSingleSpanMethod · 0.85

Calls 10

BitmapAndFunction · 0.85
AccumulateFunction · 0.85
is_arrayMethod · 0.80
push_backMethod · 0.80
GetFunction · 0.70
SetBitsToFunction · 0.50
CopyBitmapFunction · 0.50
idMethod · 0.45
emptyMethod · 0.45
sizeMethod · 0.45

Tested by 1

TEST_FFunction · 0.68