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