rdblue commented on a change in pull request #3774:
URL: https://github.com/apache/iceberg/pull/3774#discussion_r794109173
##########
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);
visitor.beforeRepeatedElement(repeatedElement);
try {
- T elementResult = null;
- if (repeatedElement.getFieldCount() > 0) {
- Type elementField = repeatedElement.getType(0);
- visitor.beforeElementField(elementField);
- try {
- elementResult = visit(elementField, visitor);
- } finally {
- visitor.afterElementField(elementField);
- }
- }
+ T elementResult = visitListElement(list, listElement, visitor);
return visitor.list(list, elementResult);
-
} finally {
visitor.afterRepeatedElement(repeatedElement);
}
}
+ private static <T> T visitListElement(GroupType list, Type listElement,
ParquetTypeVisitor<T> visitor) {
+ Type repeatedElement = list.getFields().get(0);
+ T elementResult = null;
+
+ if (repeatedElement.isPrimitive() ||
repeatedElement.asGroupType().getFieldCount() > 0) {
Review comment:
The purpose of this check was to make sure that there is a list element.
But this method already knows that there is one because it was passed in. So
this check isn't appropriate at this level and should be removed. That's good
because then this method only needs the `listElement` and nothing else.
--
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]