2828import com .google .protobuf .Message ;
2929import com .google .protobuf .Timestamp ;
3030import com .google .protobuf .util .Timestamps ;
31+ import java .util .ArrayList ;
32+ import java .util .Arrays ;
33+ import java .util .Collection ;
3134import java .util .List ;
3235import org .apache .hadoop .conf .Configuration ;
3336import org .apache .hadoop .fs .Path ;
3841import org .apache .parquet .proto .utils .ReadUsingMR ;
3942import org .apache .parquet .proto .utils .WriteUsingMR ;
4043import org .junit .Test ;
44+ import org .junit .runner .RunWith ;
45+ import org .junit .runners .Parameterized ;
4146
47+ @ RunWith (Parameterized .class )
4248public class ProtoInputOutputFormatTest {
4349
50+ @ Parameterized .Parameters (name = "codegenMode: {0}" )
51+ public static Collection <Object []> data () {
52+ List <Object []> data = new ArrayList <>();
53+
54+ List <ProtoWriteSupport .CodegenMode > codegenModes =
55+ new ArrayList <>(Arrays .asList (ProtoWriteSupport .CodegenMode .values ()));
56+ codegenModes .add (null );
57+
58+ for (ProtoWriteSupport .CodegenMode codegenMode : codegenModes ) {
59+ data .add (new Object [] {codegenMode });
60+ }
61+
62+ return data ;
63+ }
64+
65+ private final ProtoWriteSupport .CodegenMode codegenMode ;
66+
67+ public ProtoInputOutputFormatTest (ProtoWriteSupport .CodegenMode codegenMode ) {
68+ this .codegenMode = codegenMode ;
69+ }
70+
4471 /**
4572 * Writes Protocol Buffer using first MR job, reads written file using
4673 * second job and compares input and output.
@@ -241,7 +268,7 @@ public void testRepeatedIntMessageClassSchemaCompliant() throws Exception {
241268 .addRepeatedInt (2 )
242269 .build ();
243270
244- Configuration conf = new Configuration ();
271+ Configuration conf = updateConfiguration ( new Configuration () );
245272 ProtoWriteSupport .setWriteSpecsCompliant (conf , true );
246273
247274 Path outputPath = new WriteUsingMR (conf ).write (msgEmpty , msgNonEmpty );
@@ -264,7 +291,7 @@ public void testProto3RepeatedIntMessageClassSchemaCompliant() throws Exception
264291 .addRepeatedInt (2 )
265292 .build ();
266293
267- Configuration conf = new Configuration ();
294+ Configuration conf = updateConfiguration ( new Configuration () );
268295 ProtoWriteSupport .setWriteSpecsCompliant (conf , true );
269296
270297 Path outputPath = new WriteUsingMR (conf ).write (msgEmpty , msgNonEmpty );
@@ -327,7 +354,7 @@ public void testMapIntMessageClassSchemaCompliant() throws Exception {
327354 .putMapInt (2 , 234 )
328355 .build ();
329356
330- Configuration conf = new Configuration ();
357+ Configuration conf = updateConfiguration ( new Configuration () );
331358 ProtoWriteSupport .setWriteSpecsCompliant (conf , true );
332359
333360 Path outputPath = new WriteUsingMR (conf ).write (msgEmpty , msgNonEmpty );
@@ -350,7 +377,7 @@ public void testProto3MapIntMessageClassSchemaCompliant() throws Exception {
350377 .putMapInt (2 , 234 )
351378 .build ();
352379
353- Configuration conf = new Configuration ();
380+ Configuration conf = updateConfiguration ( new Configuration () );
354381 ProtoWriteSupport .setWriteSpecsCompliant (conf , true );
355382
356383 Path outputPath = new WriteUsingMR (conf ).write (msgEmpty , msgNonEmpty );
@@ -419,7 +446,7 @@ public void testRepeatedInnerMessageClassSchemaCompliant() throws Exception {
419446 TestProtobuf .InnerMessage .newBuilder ().setTwo ("two" ).build ())
420447 .build ();
421448
422- Configuration conf = new Configuration ();
449+ Configuration conf = updateConfiguration ( new Configuration () );
423450 ProtoWriteSupport .setWriteSpecsCompliant (conf , true );
424451
425452 Path outputPath = new WriteUsingMR (conf ).write (msgEmpty , msgNonEmpty );
@@ -444,7 +471,7 @@ public void testProto3RepeatedInnerMessageClassSchemaCompliant() throws Exceptio
444471 TestProto3 .InnerMessage .newBuilder ().setTwo ("two" ).build ())
445472 .build ();
446473
447- Configuration conf = new Configuration ();
474+ Configuration conf = updateConfiguration ( new Configuration () );
448475 ProtoWriteSupport .setWriteSpecsCompliant (conf , true );
449476
450477 Path outputPath = new WriteUsingMR (conf ).write (msgEmpty , msgNonEmpty );
@@ -463,7 +490,7 @@ public void testProto3Defaults() throws Exception {
463490 TestProto3 .SchemaConverterAllDatatypes msgEmpty =
464491 TestProto3 .SchemaConverterAllDatatypes .newBuilder ().build ();
465492
466- Configuration conf = new Configuration ();
493+ Configuration conf = updateConfiguration ( new Configuration () );
467494 ProtoWriteSupport .setWriteSpecsCompliant (conf , true );
468495
469496 Path outputPath = new WriteUsingMR (conf ).write (msgEmpty );
@@ -508,7 +535,7 @@ public void testProto3AllTypes() throws Exception {
508535
509536 TestProto3 .SchemaConverterAllDatatypes dataBuilt = data .build ();
510537
511- Configuration conf = new Configuration ();
538+ Configuration conf = updateConfiguration ( new Configuration () );
512539 ProtoWriteSupport .setWriteSpecsCompliant (conf , true );
513540
514541 Path outputPath = new WriteUsingMR (conf ).write (dataBuilt );
@@ -574,7 +601,7 @@ public void testProto3AllTypesMultiple() throws Exception {
574601 input [i ] = d .build ();
575602 }
576603
577- Configuration conf = new Configuration ();
604+ Configuration conf = updateConfiguration ( new Configuration () );
578605 ProtoWriteSupport .setWriteSpecsCompliant (conf , true );
579606
580607 Path outputPath = new WriteUsingMR (conf ).write (input );
@@ -606,7 +633,7 @@ public void testProto3RepeatedMessages() throws Exception {
606633 top .addInnerBuilder ().setTwo ("Second inner" );
607634 top .addInnerBuilder ().setThree ("Third inner" );
608635
609- Configuration conf = new Configuration ();
636+ Configuration conf = updateConfiguration ( new Configuration () );
610637 ProtoWriteSupport .setWriteSpecsCompliant (conf , true );
611638
612639 Path outputPath = new WriteUsingMR (conf ).write (top .build ());
@@ -643,7 +670,7 @@ public void testProto3TimestampMessageClass() throws Exception {
643670 TestProto3 .DateTimeMessage msgNonEmpty =
644671 TestProto3 .DateTimeMessage .newBuilder ().setTimestamp (timestamp ).build ();
645672
646- Configuration conf = new Configuration ();
673+ Configuration conf = updateConfiguration ( new Configuration () );
647674 conf .setBoolean (ProtoWriteSupport .PB_UNWRAP_PROTO_WRAPPERS , true );
648675 Path outputPath = new WriteUsingMR (conf ).write (msgEmpty , msgNonEmpty );
649676 ReadUsingMR readUsingMR = new ReadUsingMR ();
@@ -665,7 +692,7 @@ public void testProto3WrappedMessageClass() throws Exception {
665692 .setWrappedBool (BoolValue .of (true ))
666693 .build ();
667694
668- Configuration conf = new Configuration ();
695+ Configuration conf = updateConfiguration ( new Configuration () );
669696 conf .setBoolean (ProtoWriteSupport .PB_UNWRAP_PROTO_WRAPPERS , true );
670697 Path outputPath = new WriteUsingMR (conf ).write (msgEmpty , msgNonEmpty );
671698 ReadUsingMR readUsingMR = new ReadUsingMR ();
@@ -681,9 +708,16 @@ public void testProto3WrappedMessageClass() throws Exception {
681708 /**
682709 * Runs job that writes input to file and then job reading data back.
683710 */
684- public static List <Message > runMRJobs (Message ... messages ) throws Exception {
685- Path outputPath = new WriteUsingMR ().write (messages );
711+ public List <Message > runMRJobs (Message ... messages ) throws Exception {
712+ Path outputPath = new WriteUsingMR (updateConfiguration ( new Configuration ()) ).write (messages );
686713 List <Message > result = new ReadUsingMR ().read (outputPath );
687714 return result ;
688715 }
716+
717+ private Configuration updateConfiguration (Configuration configuration ) {
718+ if (codegenMode != null ) {
719+ ProtoWriteSupport .setCodegenMode (configuration , codegenMode );
720+ }
721+ return configuration ;
722+ }
689723}
0 commit comments