|
8 | 8 | use Faker\Factory; |
9 | 9 | use Flow\Parquet\{Consts, Reader, Writer}; |
10 | 10 | use Flow\Parquet\ParquetFile\Schema; |
11 | | -use Flow\Parquet\ParquetFile\Schema\{FlatColumn, ListElement, NestedColumn}; |
| 11 | +use Flow\Parquet\ParquetFile\Schema\{FlatColumn, ListElement, NestedColumn, Repetition}; |
12 | 12 | use PHPUnit\Framework\TestCase; |
13 | 13 |
|
14 | 14 | final class ListsWritingTest extends TestCase |
@@ -226,6 +226,40 @@ public function test_writing_nullable_list_of_structures() : void |
226 | 226 | ); |
227 | 227 | } |
228 | 228 |
|
| 229 | + public function test_writing_nullable_list_of_structures_with_required_fields() : void |
| 230 | + { |
| 231 | + $path = __DIR__ . '/var/test-writer-parquet-test-' . generate_random_string() . '.parquet'; |
| 232 | + |
| 233 | + $writer = new Writer(); |
| 234 | + $schema = Schema::with( |
| 235 | + NestedColumn::list( |
| 236 | + 'list_of_structs', |
| 237 | + ListElement::structure( |
| 238 | + [ |
| 239 | + FlatColumn::int32('id', Repetition::REQUIRED), |
| 240 | + ], |
| 241 | + true |
| 242 | + ), |
| 243 | + ) |
| 244 | + ); |
| 245 | + |
| 246 | + $faker = Factory::create(); |
| 247 | + $inputData = \array_merge(...\array_map(static fn (int $i) : array => [ |
| 248 | + [ |
| 249 | + 'list_of_structs' => \array_map(static fn ($i) => [ |
| 250 | + 'id' => $faker->numberBetween(0, Consts::PHP_INT32_MAX), |
| 251 | + ], \range(1, generate_random_int(2, 10))), |
| 252 | + ], |
| 253 | + ], \range(1, 10))); |
| 254 | + |
| 255 | + $writer->write($path, $schema, $inputData); |
| 256 | + |
| 257 | + self::assertSame( |
| 258 | + $inputData, |
| 259 | + \iterator_to_array((new Reader())->read($path)->values()) |
| 260 | + ); |
| 261 | + } |
| 262 | + |
229 | 263 | public function test_writing_nullable_lists_of_ints() : void |
230 | 264 | { |
231 | 265 | $path = __DIR__ . '/var/test-writer-parquet-test-' . generate_random_string() . '.parquet'; |
|
0 commit comments