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

Function NormalizeArray

cpp/src/arrow/adapters/orc/util.cc:392–491  ·  view source on GitHub ↗

Make sure children of StructArray have appropriate null.

Source from the content-addressed store, hash-verified

390
391// Make sure children of StructArray have appropriate null.
392Result<std::shared_ptr<Array>> NormalizeArray(const std::shared_ptr<Array>& array) {
393 Type::type kind = array->type_id();
394 switch (kind) {
395 case Type::type::STRUCT: {
396 if (array->null_count() == 0) {
397 return array;
398 } else {
399 auto struct_array = checked_pointer_cast<StructArray>(array);
400 const std::shared_ptr<Buffer> bitmap = struct_array->null_bitmap();
401 std::shared_ptr<DataType> struct_type = struct_array->type();
402 std::size_t size = struct_type->fields().size();
403 std::vector<std::shared_ptr<Array>> new_children(size, nullptr);
404 for (std::size_t i = 0; i < size; i++) {
405 std::shared_ptr<Array> child = struct_array->field(static_cast<int>(i));
406 const std::shared_ptr<Buffer> child_bitmap = child->null_bitmap();
407 std::shared_ptr<Buffer> final_child_bitmap;
408 if (child_bitmap == nullptr) {
409 final_child_bitmap = bitmap;
410 } else {
411 ARROW_ASSIGN_OR_RAISE(
412 final_child_bitmap,
413 internal::BitmapAnd(default_memory_pool(), bitmap->data(), 0,
414 child_bitmap->data(), 0, struct_array->length(), 0));
415 }
416 std::shared_ptr<ArrayData> child_array_data = child->data();
417 std::vector<std::shared_ptr<Buffer>> child_buffers = child_array_data->buffers;
418 child_buffers[0] = final_child_bitmap;
419 std::shared_ptr<ArrayData> new_child_array_data =
420 ArrayData::Make(child->type(), child->length(), child_buffers,
421 child_array_data->child_data, child_array_data->dictionary);
422 ARROW_ASSIGN_OR_RAISE(new_children[i],
423 NormalizeArray(MakeArray(new_child_array_data)));
424 }
425 return std::make_shared<StructArray>(struct_type, struct_array->length(),
426 new_children, bitmap);
427 }
428 }
429 case Type::type::LIST: {
430 auto list_array = checked_pointer_cast<ListArray>(array);
431 ARROW_ASSIGN_OR_RAISE(auto value_array, NormalizeArray(list_array->values()));
432 return std::make_shared<ListArray>(list_array->type(), list_array->length(),
433 list_array->value_offsets(), value_array,
434 list_array->null_bitmap(),
435 list_array->null_count(), list_array->offset());
436 }
437 case Type::type::LARGE_LIST: {
438 auto list_array = checked_pointer_cast<LargeListArray>(array);
439 ARROW_ASSIGN_OR_RAISE(auto value_array, NormalizeArray(list_array->values()));
440 return std::make_shared<LargeListArray>(
441 list_array->type(), list_array->length(), list_array->value_offsets(),
442 value_array, list_array->null_bitmap(), list_array->null_count(),
443 list_array->offset());
444 }
445 case Type::type::FIXED_SIZE_LIST: {
446 auto list_array = checked_pointer_cast<FixedSizeListArray>(array);
447 ARROW_ASSIGN_OR_RAISE(auto value_array, NormalizeArray(list_array->values()));
448 return std::make_shared<FixedSizeListArray>(
449 list_array->type(), list_array->length(), value_array,

Callers

nothing calls this directly

Calls 15

BitmapAndFunction · 0.85
default_memory_poolFunction · 0.85
value_offsetsMethod · 0.80
emplace_backMethod · 0.80
ARROW_ASSIGN_OR_RAISEFunction · 0.50
MakeFunction · 0.50
MakeArrayFunction · 0.50
type_idMethod · 0.45
null_countMethod · 0.45
typeMethod · 0.45
sizeMethod · 0.45
fieldsMethod · 0.45

Tested by

no test coverage detected