Skip to content

Commit ac7c405

Browse files
committed
PARQUET-212: Add tests for list of list cases from PARQUET-364.
1 parent 356fdb7 commit ac7c405

File tree

2 files changed

+132
-0
lines changed

2 files changed

+132
-0
lines changed

parquet-thrift/src/test/java/org/apache/parquet/hadoop/thrift/TestArrayCompatibility.java

Lines changed: 128 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,13 @@
2020

2121
import com.google.common.collect.Lists;
2222
import java.io.IOException;
23+
import java.util.Arrays;
2324
import java.util.List;
25+
import org.apache.avro.Schema;
26+
import org.apache.avro.generic.GenericRecord;
2427
import org.apache.hadoop.conf.Configuration;
2528
import org.apache.hadoop.fs.Path;
29+
import org.apache.parquet.thrift.test.compat.ListOfLists;
2630
import org.apache.thrift.TBase;
2731
import org.junit.Assert;
2832
import org.junit.Ignore;
@@ -475,6 +479,130 @@ public void write(RecordConsumer rc) {
475479
assertReaderContains(reader(test, ListOfLocations.class), expected);
476480
}
477481

482+
@Test
483+
public void testAvroCompatListInList() throws Exception {
484+
Path test = writeDirect(
485+
"message AvroCompatListInList {" +
486+
" optional group listOfLists (LIST) {" +
487+
" repeated group array (LIST) {" +
488+
" repeated int32 array;" +
489+
" }" +
490+
" }" +
491+
"}",
492+
new DirectWriter() {
493+
@Override
494+
public void write(RecordConsumer rc) {
495+
rc.startMessage();
496+
rc.startField("locations", 0);
497+
498+
rc.startGroup();
499+
rc.startField("array", 0); // start writing array contents
500+
501+
rc.startGroup();
502+
rc.startField("array", 0); // start writing inner array contents
503+
504+
// write [34, 35, 36]
505+
rc.addInteger(34);
506+
rc.addInteger(35);
507+
rc.addInteger(36);
508+
509+
rc.endField("array", 0); // finished writing inner array contents
510+
rc.endGroup();
511+
512+
// write an empty list
513+
rc.startGroup();
514+
rc.endGroup();
515+
516+
rc.startGroup();
517+
rc.startField("array", 0); // start writing inner array contents
518+
519+
// write [32, 33, 34]
520+
rc.addInteger(32);
521+
rc.addInteger(33);
522+
rc.addInteger(34);
523+
524+
rc.endField("array", 0); // finished writing inner array contents
525+
rc.endGroup();
526+
527+
rc.endField("array", 0); // finished writing array contents
528+
rc.endGroup();
529+
530+
rc.endField("locations", 0);
531+
rc.endMessage();
532+
}
533+
});
534+
535+
ListOfLists expected = new ListOfLists();
536+
expected.addToListOfLists(Arrays.asList(34, 35, 36));
537+
expected.addToListOfLists(Arrays.<Integer>asList());
538+
expected.addToListOfLists(Arrays.asList(32, 33, 34));
539+
540+
// should detect the "array" name
541+
assertReaderContains(reader(test, ListOfLists.class), expected);
542+
}
543+
544+
@Test
545+
public void testThriftCompatListInList() throws Exception {
546+
Path test = writeDirect(
547+
"message ThriftCompatListInList {" +
548+
" optional group listOfLists (LIST) {" +
549+
" repeated group listOfLists_tuple (LIST) {" +
550+
" repeated int32 listOfLists_tuple_tuple;" +
551+
" }" +
552+
" }" +
553+
"}",
554+
new DirectWriter() {
555+
@Override
556+
public void write(RecordConsumer rc) {
557+
rc.startMessage();
558+
rc.startField("locations", 0);
559+
560+
rc.startGroup();
561+
rc.startField("listOfLists_tuple", 0); // start writing array contents
562+
563+
rc.startGroup();
564+
rc.startField("listOfLists_tuple_tuple", 0); // start writing inner array contents
565+
566+
// write [34, 35, 36]
567+
rc.addInteger(34);
568+
rc.addInteger(35);
569+
rc.addInteger(36);
570+
571+
rc.endField("listOfLists_tuple_tuple", 0); // finished writing inner array contents
572+
rc.endGroup();
573+
574+
// write an empty list
575+
rc.startGroup();
576+
rc.endGroup();
577+
578+
rc.startGroup();
579+
rc.startField("listOfLists_tuple_tuple", 0); // start writing inner array contents
580+
581+
// write [32, 33, 34]
582+
rc.addInteger(32);
583+
rc.addInteger(33);
584+
rc.addInteger(34);
585+
586+
rc.endField("listOfLists_tuple_tuple", 0); // finished writing inner array contents
587+
rc.endGroup();
588+
589+
rc.endField("listOfLists_tuple", 0); // finished writing array contents
590+
rc.endGroup();
591+
592+
rc.endField("locations", 0);
593+
rc.endMessage();
594+
}
595+
});
596+
597+
ListOfLists expected = new ListOfLists();
598+
expected.addToListOfLists(Arrays.asList(34, 35, 36));
599+
expected.addToListOfLists(Arrays.<Integer>asList());
600+
expected.addToListOfLists(Arrays.asList(32, 33, 34));
601+
602+
// should detect the "_tuple" names
603+
assertReaderContains(reader(test, ListOfLists.class), expected);
604+
}
605+
478606
@Test
479607
public void testOldThriftCompatRequiredGroupInList() throws Exception {
480608
Path test = writeDirect(

parquet-thrift/src/test/thrift/array_compat.thrift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,3 +47,7 @@ struct ListOfSingleElementGroups {
4747
struct ListOfCounts {
4848
1: optional list<i64> single_element_groups;
4949
}
50+
51+
struct ListOfLists {
52+
1: optional list<list<i32>> listOfLists;
53+
}

0 commit comments

Comments
 (0)