1818 */
1919package org .apache .parquet .avro ;
2020
21- import static org .apache .parquet .schema .PrimitiveType .PrimitiveTypeName .*;
22- import static org .junit .Assert .*;
21+ import static org .junit .Assert .assertEquals ;
2322
2423import java .io .File ;
2524import java .io .IOException ;
2625import java .math .BigDecimal ;
2726import java .nio .ByteBuffer ;
28- import java .util .*;
27+ import java .util .Arrays ;
28+ import java .util .ArrayList ;
29+ import java .util .List ;
30+ import java .util .UUID ;
2931import java .util .function .Consumer ;
3032import org .apache .avro .Schema ;
3133import org .apache .avro .generic .GenericData ;
3537import org .apache .parquet .DirectWriterTest ;
3638import org .apache .parquet .hadoop .ParquetWriter ;
3739import org .apache .parquet .hadoop .api .WriteSupport ;
38- import org .apache .parquet .schema .*;
40+ import org .apache .parquet .schema .GroupType ;
41+ import org .apache .parquet .schema .LogicalTypeAnnotation ;
42+ import org .apache .parquet .schema .MessageType ;
43+ import org .apache .parquet .schema .Type ;
44+ import org .apache .parquet .schema .Types ;
3945import org .apache .parquet .schema .LogicalTypeAnnotation .TimeUnit ;
4046import org .apache .parquet .schema .PrimitiveType .PrimitiveTypeName ;
4147import org .apache .parquet .variant .ImmutableMetadata ;
@@ -87,7 +93,7 @@ private static ByteBuffer variant(String s) {
8793
8894 private static MessageType parquetSchema (GroupType variantGroup ) {
8995 return Types .buildMessage ()
90- .required (INT32 )
96+ .required (PrimitiveTypeName . INT32 )
9197 .named ("id" )
9298 .addField (variantGroup )
9399 .named ("table" );
@@ -359,18 +365,18 @@ public void testShreddedValues() throws IOException {
359365
360366 @ Test
361367 public void testMixedShredding () throws IOException {
362- for (Variant valueForSchema : VARIANTS ) {
363- List <GenericRecord > expected = new ArrayList <>();
364- for (int i = 0 ; i < VARIANTS .length ; i ++) {
365- expected .add (createRecord (i , VARIANTS [i ]));
366- }
368+ List <GenericRecord > expected = new ArrayList <>();
369+ for (int i = 0 ; i < VARIANTS .length ; i ++) {
370+ expected .add (createRecord (i , VARIANTS [i ]));
371+ }
367372
373+ for (Variant valueForSchema : VARIANTS ) {
368374 MessageType writeSchema = shreddingSchema (valueForSchema );
369375 TestSchema testSchema = new TestSchema (writeSchema , READ_SCHEMA );
370376
371377 List <GenericRecord > actual = writeAndRead (testSchema , expected );
372- assertEquals (actual .size (), VARIANTS . length );
373- for (int i = 0 ; i < VARIANTS . length ; i ++) {
378+ assertEquals (actual .size (), expected . size () );
379+ for (int i = 0 ; i < expected . size () ; i ++) {
374380 Variant actualV =
375381 new Variant ((ByteBuffer ) ((GenericRecord ) actual .get (i ).get (1 )).get (1 ), (ByteBuffer )
376382 ((GenericRecord ) actual .get (i ).get (1 )).get (0 ));
@@ -419,7 +425,7 @@ protected WriteSupport<GenericRecord> getWriteSupport(Configuration conf) {
419425
420426 GenericRecord writeAndRead (TestSchema testSchema , GenericRecord record ) throws IOException {
421427 List <GenericRecord > result = writeAndRead (testSchema , Arrays .asList (record ));
422- assert (result .size () == 1 );
428+ assertEquals (result .size (), 1 );
423429 return result .get (0 );
424430 }
425431
@@ -456,9 +462,9 @@ private static MessageType shreddingSchema(Variant v) {
456462 Type shreddedType = shreddedType (v );
457463 Types .GroupBuilder <GroupType > partialType = Types .buildGroup (Type .Repetition .OPTIONAL )
458464 .as (LogicalTypeAnnotation .variantType ((byte ) 1 ))
459- .required (BINARY )
465+ .required (PrimitiveTypeName . BINARY )
460466 .named ("metadata" )
461- .optional (BINARY )
467+ .optional (PrimitiveTypeName . BINARY )
462468 .named ("value" );
463469 Type variantType ;
464470 if (shreddedType == null ) {
@@ -467,7 +473,7 @@ private static MessageType shreddingSchema(Variant v) {
467473 variantType = partialType .addField (shreddedType ).named ("var" );
468474 }
469475 return Types .buildMessage ()
470- .required (INT32 )
476+ .required (PrimitiveTypeName . INT32 )
471477 .named ("id" )
472478 .addField (variantType )
473479 .named ("table" );
@@ -477,12 +483,12 @@ private static GroupType shreddedGroup(Variant v, String name) {
477483 Type shreddedType = shreddedType (v );
478484 if (shreddedType == null ) {
479485 return Types .buildGroup (Type .Repetition .OPTIONAL )
480- .optional (BINARY )
486+ .optional (PrimitiveTypeName . BINARY )
481487 .named ("value" )
482488 .named (name );
483489 } else {
484490 return Types .buildGroup (Type .Repetition .OPTIONAL )
485- .optional (BINARY )
491+ .optional (PrimitiveTypeName . BINARY )
486492 .named ("value" )
487493 .addField (shreddedType )
488494 .named (name );
@@ -497,67 +503,67 @@ private static Type shreddedType(Variant v) {
497503 case NULL :
498504 return null ;
499505 case BOOLEAN :
500- return Types .optional (BOOLEAN ).named ("typed_value" );
506+ return Types .optional (PrimitiveTypeName . BOOLEAN ).named ("typed_value" );
501507 case BYTE :
502- return Types .optional (INT32 )
508+ return Types .optional (PrimitiveTypeName . INT32 )
503509 .as (LogicalTypeAnnotation .intType (8 ))
504510 .named ("typed_value" );
505511 case SHORT :
506- return Types .optional (INT32 )
512+ return Types .optional (PrimitiveTypeName . INT32 )
507513 .as (LogicalTypeAnnotation .intType (16 ))
508514 .named ("typed_value" );
509515 case INT :
510- return Types .optional (INT32 ).named ("typed_value" );
516+ return Types .optional (PrimitiveTypeName . INT32 ).named ("typed_value" );
511517 case LONG :
512- return Types .optional (INT64 ).named ("typed_value" );
518+ return Types .optional (PrimitiveTypeName . INT64 ).named ("typed_value" );
513519 case FLOAT :
514- return Types .optional (FLOAT ).named ("typed_value" );
520+ return Types .optional (PrimitiveTypeName . FLOAT ).named ("typed_value" );
515521 case DOUBLE :
516- return Types .optional (DOUBLE ).named ("typed_value" );
522+ return Types .optional (PrimitiveTypeName . DOUBLE ).named ("typed_value" );
517523 case DECIMAL4 :
518- return Types .optional (INT32 )
524+ return Types .optional (PrimitiveTypeName . INT32 )
519525 .as (LogicalTypeAnnotation .decimalType (v .getDecimal ().scale (), 9 ))
520526 .named ("typed_value" );
521527 case DECIMAL8 :
522- return Types .optional (INT64 )
528+ return Types .optional (PrimitiveTypeName . INT64 )
523529 .as (LogicalTypeAnnotation .decimalType (v .getDecimal ().scale (), 18 ))
524530 .named ("typed_value" );
525531 case DECIMAL16 :
526- return Types .optional (BINARY )
532+ return Types .optional (PrimitiveTypeName . BINARY )
527533 .as (LogicalTypeAnnotation .decimalType (v .getDecimal ().scale (), 38 ))
528534 .named ("typed_value" );
529535 case DATE :
530- return Types .optional (INT32 )
536+ return Types .optional (PrimitiveTypeName . INT32 )
531537 .as (LogicalTypeAnnotation .dateType ())
532538 .named ("typed_value" );
533539 case TIMESTAMP_TZ :
534- return Types .optional (INT64 )
540+ return Types .optional (PrimitiveTypeName . INT64 )
535541 .as (LogicalTypeAnnotation .timestampType (true , TimeUnit .MICROS ))
536542 .named ("typed_value" );
537543 case TIMESTAMP_NTZ :
538- return Types .optional (INT64 )
544+ return Types .optional (PrimitiveTypeName . INT64 )
539545 .as (LogicalTypeAnnotation .timestampType (false , TimeUnit .MICROS ))
540546 .named ("typed_value" );
541547 case BINARY :
542- return Types .optional (BINARY ).named ("typed_value" );
548+ return Types .optional (PrimitiveTypeName . BINARY ).named ("typed_value" );
543549 case STRING :
544- return Types .optional (BINARY )
550+ return Types .optional (PrimitiveTypeName . BINARY )
545551 .as (LogicalTypeAnnotation .stringType ())
546552 .named ("typed_value" );
547553 case TIME :
548- return Types .optional (INT64 )
554+ return Types .optional (PrimitiveTypeName . INT64 )
549555 .as (LogicalTypeAnnotation .timeType (false , TimeUnit .MICROS ))
550556 .named ("typed_value" );
551557 case TIMESTAMP_NANOS_TZ :
552- return Types .optional (INT64 )
558+ return Types .optional (PrimitiveTypeName . INT64 )
553559 .as (LogicalTypeAnnotation .timestampType (true , TimeUnit .NANOS ))
554560 .named ("typed_value" );
555561 case TIMESTAMP_NANOS_NTZ :
556- return Types .optional (INT64 )
562+ return Types .optional (PrimitiveTypeName . INT64 )
557563 .as (LogicalTypeAnnotation .timestampType (false , TimeUnit .NANOS ))
558564 .named ("typed_value" );
559565 case UUID :
560- return Types .optional (FIXED_LEN_BYTE_ARRAY )
566+ return Types .optional (PrimitiveTypeName . FIXED_LEN_BYTE_ARRAY )
561567 .as (LogicalTypeAnnotation .uuidType ())
562568 .named ("typed_value" );
563569 case OBJECT :
0 commit comments