| 563 | } |
| 564 | |
| 565 | static std::shared_ptr<Array> MakeStructArray(::arrow::random::RandomArrayGenerator* rng, |
| 566 | const ArrayVector& children, |
| 567 | double null_probability, |
| 568 | bool propagate_validity = false) { |
| 569 | ARROW_CHECK_GT(children.size(), 0); |
| 570 | const int64_t length = children[0]->length(); |
| 571 | |
| 572 | std::shared_ptr<::arrow::Buffer> null_bitmap; |
| 573 | if (null_probability > 0.0) { |
| 574 | null_bitmap = rng->NullBitmap(length, null_probability); |
| 575 | if (propagate_validity) { |
| 576 | // HACK: the Parquet writer currently doesn't allow non-empty list |
| 577 | // entries where a parent node is null (for instance, a struct-of-list |
| 578 | // where the outer struct is marked null but the inner list value is |
| 579 | // non-empty). |
| 580 | for (const auto& child : children) { |
| 581 | null_bitmap = *::arrow::internal::BitmapOr( |
| 582 | ::arrow::default_memory_pool(), null_bitmap->data(), 0, |
| 583 | child->null_bitmap_data(), 0, length, 0); |
| 584 | } |
| 585 | } |
| 586 | } |
| 587 | FieldVector fields(children.size()); |
| 588 | char field_name = 'a'; |
| 589 | for (size_t i = 0; i < children.size(); ++i) { |
| 590 | fields[i] = field(std::string{field_name++}, children[i]->type(), |
| 591 | /*nullable=*/null_probability > 0.0); |
| 592 | } |
| 593 | return *::arrow::StructArray::Make(children, std::move(fields), null_bitmap); |
| 594 | } |
| 595 | |
| 596 | // Make a (int32, int64) struct array |
| 597 | static std::shared_ptr<Array> MakeStructArray(::arrow::random::RandomArrayGenerator* rng, |
no test coverage detected