| 3706 | } |
| 3707 | |
| 3708 | void DoNestedRequiredRoundtrip( |
| 3709 | const std::shared_ptr<::arrow::DataType>& inner_type, |
| 3710 | const std::shared_ptr<WriterProperties>& writer_properties, |
| 3711 | const std::shared_ptr<ArrowWriterProperties>& arrow_writer_properties) { |
| 3712 | // Test ARROW-15961/ARROW-16116 |
| 3713 | ARROW_SCOPED_TRACE("Type: ", inner_type->ToString()); |
| 3714 | std::shared_ptr<::arrow::KeyValueMetadata> metadata; |
| 3715 | if (inner_type->id() != ::arrow::Type::DICTIONARY) { |
| 3716 | metadata = ::arrow::key_value_metadata({{"min", "0"}, {"max", "127"}}); |
| 3717 | } |
| 3718 | auto inner_field = |
| 3719 | ::arrow::field("inner", inner_type, /*nullable=*/false, std::move(metadata)); |
| 3720 | auto type = ::arrow::struct_({inner_field}); |
| 3721 | auto field = ::arrow::field("outer", type, /*nullable=*/true); |
| 3722 | |
| 3723 | auto gen = ::arrow::random::RandomArrayGenerator(/*seed=*/42); |
| 3724 | auto inner = gen.ArrayOf(*inner_field, /*size=*/4); |
| 3725 | ASSERT_EQ(inner->null_count(), 0) << inner->ToString(); |
| 3726 | |
| 3727 | ::arrow::TypedBufferBuilder<bool> bitmap_builder; |
| 3728 | ASSERT_OK(bitmap_builder.Append(2, false)); |
| 3729 | ASSERT_OK(bitmap_builder.Append(2, true)); |
| 3730 | ASSERT_OK_AND_ASSIGN(auto null_bitmap, bitmap_builder.Finish()); |
| 3731 | ASSERT_OK_AND_ASSIGN(auto array, |
| 3732 | ::arrow::StructArray::Make({inner}, {inner_field}, null_bitmap)); |
| 3733 | auto table = ::arrow::Table::Make(::arrow::schema({field}), {array}); |
| 3734 | ASSERT_OK(table->ValidateFull()); |
| 3735 | |
| 3736 | auto sink = CreateOutputStream(); |
| 3737 | ASSERT_OK_NO_THROW(WriteTable(*table, ::arrow::default_memory_pool(), sink, |
| 3738 | /*row_group_size=*/4, writer_properties, |
| 3739 | arrow_writer_properties)); |
| 3740 | ASSERT_OK_AND_ASSIGN(auto buffer, sink->Finish()); |
| 3741 | ASSERT_NO_FATAL_FAILURE(DoNestedValidate(inner_type, field, buffer, table)); |
| 3742 | } |
| 3743 | |
| 3744 | TEST(ArrowReadWrite, NestedRequiredOuterOptional) { |
| 3745 | std::vector<std::shared_ptr<DataType>> types = ::arrow::PrimitiveTypes(); |
no test coverage detected