rdblue commented on a change in pull request #3774:
URL: https://github.com/apache/iceberg/pull/3774#discussion_r795265536
##########
File path:
parquet/src/main/java/org/apache/iceberg/parquet/ParquetTypeVisitor.java
##########
@@ -66,32 +66,52 @@
Preconditions.checkArgument(list.getFieldCount() == 1,
"Invalid list: does not contain single repeated field: %s", list);
- GroupType repeatedElement = list.getFields().get(0).asGroupType();
+ Type repeatedElement = list.getFields().get(0);
Preconditions.checkArgument(repeatedElement.isRepetition(Type.Repetition.REPEATED),
"Invalid list: inner group is not repeated");
- Preconditions.checkArgument(repeatedElement.getFieldCount() <= 1,
- "Invalid list: repeated group is not a single field: %s", list);
+
+ Type listElement = ParquetSchemaUtil.determineListElementType(list);
+ if (listElement.isRepetition(Type.Repetition.REPEATED)) {
+ return visitTwoLevelList(list, listElement, visitor);
+ } else {
+ return visitThreeLevelList(list, listElement, visitor);
+ }
+ }
+
+ private static <T> T visitTwoLevelList(GroupType list, Type listElement,
ParquetTypeVisitor<T> visitor) {
+ T elementResult = visitListElement(list, listElement, visitor);
+ return visitor.list(list, elementResult);
+ }
+
+ private static <T> T visitThreeLevelList(GroupType list, Type listElement,
ParquetTypeVisitor<T> visitor) {
+ Type repeatedElement = list.getFields().get(0);
Review comment:
Looks like the only place that `list` is used is to retrieve the
repeated element and to visit the list. Visiting the list is done in both
`visitTwoLevelList` and `visitThreeLevelList`. So I think the cleanest
structure is to keep `visitListElement` and change these methods to visit just
the element. `visitTwoLevelList` is not needed, the original method should call
`visitListElement` directly. Then this function should accept `GroupType
repeated, Type listElement, ParquetTypeVisitor<T> visitor` and return the
element result.
Then you can move `visitor.list(list, elementResult)` into the original
method. That's pretty clean.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]