|
20 | 20 |
|
21 | 21 | import com.google.common.collect.Lists; |
22 | 22 | import java.io.IOException; |
| 23 | +import java.util.Arrays; |
23 | 24 | import java.util.List; |
| 25 | +import org.apache.avro.Schema; |
| 26 | +import org.apache.avro.generic.GenericRecord; |
24 | 27 | import org.apache.hadoop.conf.Configuration; |
25 | 28 | import org.apache.hadoop.fs.Path; |
| 29 | +import org.apache.parquet.thrift.test.compat.ListOfLists; |
26 | 30 | import org.apache.thrift.TBase; |
27 | 31 | import org.junit.Assert; |
28 | 32 | import org.junit.Ignore; |
@@ -475,6 +479,130 @@ public void write(RecordConsumer rc) { |
475 | 479 | assertReaderContains(reader(test, ListOfLocations.class), expected); |
476 | 480 | } |
477 | 481 |
|
| 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 | + |
478 | 606 | @Test |
479 | 607 | public void testOldThriftCompatRequiredGroupInList() throws Exception { |
480 | 608 | Path test = writeDirect( |
|
0 commit comments