rdblue commented on a change in pull request #1112:
URL: https://github.com/apache/iceberg/pull/1112#discussion_r441714055



##########
File path: orc/src/main/java/org/apache/iceberg/orc/OrcMetrics.java
##########
@@ -214,64 +210,33 @@ private static Metrics buildOrcMetrics(final long 
numOfRows, final TypeDescripti
     return Optional.ofNullable(Conversions.toByteBuffer(column.type(), max));
   }
 
-  private static Set<TypeDescription> findColumnsInContainers(Schema schema,
-                                                              TypeDescription 
orcSchema) {
-    ColumnsInContainersVisitor visitor = new ColumnsInContainersVisitor();
-    OrcSchemaWithTypeVisitor.visit(schema, orcSchema, visitor);
-    return visitor.getColumnsInContainers();
+  private static Set<TypeDescription> findColumnsInContainers(TypeDescription 
orcSchema) {
+    Set<TypeDescription> columnsInContainers = Sets.newHashSet();
+    findColumnsInContainers(orcSchema, columnsInContainers, false);
+    return Collections.unmodifiableSet(columnsInContainers);
   }
 
-  private static class ColumnsInContainersVisitor extends 
OrcSchemaWithTypeVisitor<TypeDescription> {
-
-    private final Set<TypeDescription> columnsInContainers;
-
-    private ColumnsInContainersVisitor() {
-      columnsInContainers = Sets.newHashSet();
-    }
-
-    public Set<TypeDescription> getColumnsInContainers() {
-      return columnsInContainers;
-    }
-
-    private Set<TypeDescription> flatten(TypeDescription rootType) {
-      if (rootType == null) {
-        return ImmutableSet.of();
-      }
-
-      final Set<TypeDescription> flatTypes = 
Sets.newHashSetWithExpectedSize(rootType.getMaximumId());
-      final Queue<TypeDescription> queue = Queues.newLinkedBlockingQueue();
-      queue.add(rootType);
-      while (!queue.isEmpty()) {
-        TypeDescription type = queue.remove();
-        flatTypes.add(type);
-        
queue.addAll(Optional.ofNullable(type.getChildren()).orElse(ImmutableList.of()));
-      }
-      return flatTypes;
+  private static void findColumnsInContainers(TypeDescription column,
+                                              Set<TypeDescription> 
columnsInContainers,
+                                              boolean isInContainers) {

Review comment:
       I agree about the complexity of traversing a schema not being a huge 
concern. I think the main value of this is to simplify the code to make it 
easier to maintain.
   
   Here's the version I came up with, which is a bit simpler:
   
   ```java
   
     private static Set<Integer> statsColumns(TypeDescription schema) {
       return OrcSchemaWithTypeVisitor.visit((Type) null, schema, new 
StatsColumnsVisitor());
     }
   
     private static class StatsColumnsVisitor extends 
OrcSchemaWithTypeVisitor<Set<Integer>> {
       @Override
       public Set<Integer> record(Types.StructType s, TypeDescription record, 
List<String> names, List<Set<Integer>> fields) {
         ImmutableSet.Builder<Integer> result = ImmutableSet.builder();
         fields.stream().filter(Objects::nonNull).forEach(result::addAll);
         
record.getChildren().stream().map(ORCSchemaUtil::fieldId).forEach(result::add);
         return result.build();
       }
   
       @Override
       public Set<Integer> list(Types.ListType l, TypeDescription array, 
Set<Integer> element) {
         return null;
       }
   
       @Override
       public Set<Integer> map(Types.MapType m, TypeDescription map, 
Set<Integer> key, Set<Integer> value) {
         return null;
       }
   
       @Override
       public Set<Integer> primitive(Type.PrimitiveType p, TypeDescription 
primitive) {
         return null;
       }
     }
   ```
   
   Using this would avoid the need to negate the check, so it would be `if 
(statsColumns.contains(icebergId)) {...}`.




----------------------------------------------------------------
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.

For queries about this service, please contact Infrastructure at:
[email protected]



---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to