rdblue commented on code in PR #13039:
URL: https://github.com/apache/iceberg/pull/13039#discussion_r2241260841


##########
core/src/main/java/org/apache/iceberg/MetricsConfig.java:
##########
@@ -107,6 +115,81 @@ public static MetricsConfig forPositionDelete(Table table) 
{
     return new MetricsConfig(columnModes.build(), defaultMode);
   }
 
+  static Iterable<Integer> breadthFirstFieldPriority(Schema schema) {
+    return TypeUtil.visit(
+        schema,
+        new TypeUtil.CustomOrderSchemaVisitor<>() {
+
+          @Override
+          public Iterable<Integer> schema(Schema schema, 
Supplier<Iterable<Integer>> structResult) {
+            return structResult.get();
+          }
+
+          @Override
+          public Iterable<Integer> struct(
+              Types.StructType struct, Iterable<Iterable<Integer>> 
fieldResults) {

Review Comment:
   Here's what I was thinking:
   
   ```java
     static Set<Integer> limitFieldIds(Schema schema, int limit) {
       return TypeUtil.visit(
           schema,
           new TypeUtil.CustomOrderSchemaVisitor<>() {
             private final Set<Integer> idSet = Sets.newHashSet();
   
             private boolean shouldContinue() {
               return idSet.size() < limit;
             }
   
             @Override
             public Set<Integer> schema(Schema schema, Supplier<Set<Integer>> 
structResult) {
               return idSet;
             }
   
             @Override
             public Set<Integer> struct(Types.StructType struct, 
Iterable<Set<Integer>> fieldResults) {
               Iterator<Types.NestedField> fields = struct.fields().iterator();
               while (shouldContinue() && fields.hasNext()) {
                 Types.NestedField field = fields.next();
                 if (field.type().isPrimitiveType() || 
field.type().isVariantType()) {
                   idSet.add(field.fieldId());
                 }
               }
   
               // visit children to add more ids
               Iterator<Set<Integer>> iter = fieldResults.iterator();
               while (iter.hasNext() && shouldContinue()) {
                 iter.next();
               }
   
               return null;
             }
   
             @Override
             public Set<Integer> field(Types.NestedField field, 
Supplier<Set<Integer>> fieldResult) {
               return fieldResult.get();
             }
   
             @Override
             public Set<Integer> list(Types.ListType list, 
Supplier<Set<Integer>> elementResult) {
               if (shouldContinue()
                   && (list.elementType().isPrimitiveType() || 
list.elementType().isVariantType())) {
                 idSet.add(list.elementId());
               }
   
               if (shouldContinue()) {
                 elementResult.get();
               }
   
               return null;
             }
   
             @Override
             public Set<Integer> map(
                 Types.MapType map,
                 Supplier<Set<Integer>> keyResult,
                 Supplier<Set<Integer>> valueResult) {
               if (shouldContinue()
                   && (map.keyType().isPrimitiveType() || 
map.keyType().isVariantType())) {
                 idSet.add(map.keyId());
               }
   
               if (shouldContinue()
                   && (map.valueType().isPrimitiveType() || 
map.valueType().isVariantType())) {
                 idSet.add(map.valueId());
               }
   
               if (shouldContinue()) {
                 keyResult.get();
                 valueResult.get();
               }
   
               return null;
             }
           });
     }
   ```



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

Reply via email to