56
56
import java .util .Map ;
57
57
import java .util .Set ;
58
58
59
+ import static org .apache .flink .connector .datagen .table .RandomGeneratorVisitor .RANDOM_COLLECTION_LENGTH_DEFAULT ;
59
60
import static org .apache .flink .core .testutils .FlinkAssertions .anyCauseMatches ;
60
61
import static org .apache .flink .table .factories .utils .FactoryMocks .createTableSource ;
61
62
import static org .assertj .core .api .Assertions .assertThat ;
@@ -81,6 +82,11 @@ class DataGenTableSourceFactoryTest {
81
82
Column .physical ("f2" , DataTypes .VARCHAR (30 )),
82
83
Column .physical ("f3" , DataTypes .VARBINARY (20 )),
83
84
Column .physical ("f4" , DataTypes .STRING ()));
85
+ private static final ResolvedSchema COLLECTION_SCHEMA =
86
+ ResolvedSchema .of (
87
+ Column .physical ("f0" , DataTypes .ARRAY (DataTypes .STRING ())),
88
+ Column .physical ("f1" , DataTypes .MAP (DataTypes .STRING (), DataTypes .INT ())),
89
+ Column .physical ("f2" , DataTypes .MULTISET (DataTypes .INT ())));
84
90
85
91
@ Test
86
92
void testDataTypeCoverage () throws Exception {
@@ -347,6 +353,43 @@ void testVariableLengthDataType() throws Exception {
347
353
"Custom length '21' for variable-length type (VARCHAR/STRING/VARBINARY/BYTES) field 'f3' should be shorter than '20' defined in the schema." );
348
354
}
349
355
356
+ @ Test
357
+ void testLengthForCollectionType () throws Exception {
358
+ DescriptorProperties descriptor = new DescriptorProperties ();
359
+ final int rowsNumber = 200 ;
360
+ final int collectionSize = 10 ;
361
+ descriptor .putString (FactoryUtil .CONNECTOR .key (), "datagen" );
362
+ descriptor .putLong (DataGenConnectorOptions .NUMBER_OF_ROWS .key (), rowsNumber );
363
+ // test for default length.
364
+ List <RowData > results = runGenerator (COLLECTION_SCHEMA , descriptor );
365
+ assertThat (results ).hasSize (rowsNumber );
366
+ for (RowData row : results ) {
367
+ assertThat (row .getArray (0 ).size ()).isEqualTo (RANDOM_COLLECTION_LENGTH_DEFAULT );
368
+ assertThat (row .getMap (1 ).size ())
369
+ .isEqualTo (RandomGeneratorVisitor .RANDOM_COLLECTION_LENGTH_DEFAULT );
370
+ assertThat (row .getMap (2 ).size ())
371
+ .isEqualTo (RandomGeneratorVisitor .RANDOM_COLLECTION_LENGTH_DEFAULT );
372
+ }
373
+
374
+ // test for provided length.
375
+ descriptor .putLong (
376
+ DataGenConnectorOptionsUtil .FIELDS + ".f0." + DataGenConnectorOptionsUtil .LENGTH ,
377
+ collectionSize );
378
+ descriptor .putLong (
379
+ DataGenConnectorOptionsUtil .FIELDS + ".f1." + DataGenConnectorOptionsUtil .LENGTH ,
380
+ collectionSize );
381
+ descriptor .putLong (
382
+ DataGenConnectorOptionsUtil .FIELDS + ".f2." + DataGenConnectorOptionsUtil .LENGTH ,
383
+ collectionSize );
384
+ results = runGenerator (COLLECTION_SCHEMA , descriptor );
385
+ assertThat (results ).hasSize (rowsNumber );
386
+ for (RowData row : results ) {
387
+ assertThat (row .getArray (0 ).size ()).isEqualTo (collectionSize );
388
+ assertThat (row .getMap (1 ).size ()).isEqualTo (collectionSize );
389
+ assertThat (row .getMap (2 ).size ()).isEqualTo (collectionSize );
390
+ }
391
+ }
392
+
350
393
@ Test
351
394
void testFixedLengthDataType () throws Exception {
352
395
DescriptorProperties descriptor = new DescriptorProperties ();
0 commit comments