tprelle commented on code in PR #4599:
URL: https://github.com/apache/iceberg/pull/4599#discussion_r873579002


##########
api/src/main/java/org/apache/iceberg/types/TypeUtil.java:
##########
@@ -130,15 +131,45 @@ private static Set<Integer> getIdsInternal(Type type, 
boolean includeStructIds)
     return visit(type, new GetProjectedIds(includeStructIds));
   }
 
+  private static Set<Integer> innerFilter(Set<Integer> filteredIds, 
Types.NestedField innerField) {
+    // If it's a struct and if all ids need to be filtered we remove all
+    if (innerField.type().isStructType()) {
+      if (innerField.type().asStructType().fields()
+              .stream().allMatch(f -> filteredIds.contains(f.fieldId()))) {
+        
filteredIds.removeAll(innerField.type().asStructType().fields().stream()
+                .map(Types.NestedField::fieldId).collect(Collectors.toSet()));
+      }
+      innerField.type().asStructType().fields().forEach(f -> 
innerFilter(filteredIds, f));
+    }
+    return filteredIds;
+  }
+
+  private static void filter(Set<Integer> projectedIds, Types.StructType 
struct, Set<Integer> fieldIds,
+                                boolean filteredStruct) {
+    Set<Integer> filteredIds = Sets.newHashSet(fieldIds);
+    if (filteredStruct) {
+      struct.fields().forEach(f -> innerFilter(filteredIds, f));
+    }
+    projectedIds.removeAll(filteredIds);
+  }
+
   public static Types.StructType selectNot(Types.StructType struct, 
Set<Integer> fieldIds) {
+    return selectNot(struct, fieldIds, false);
+  }
+
+  public static Types.StructType selectNot(Types.StructType struct, 
Set<Integer> fieldIds, boolean filteredStruct) {

Review Comment:
   i just renamed it to doesNeedToKeepInnerStruct
   Because it's more if it's a struct and if all ids need to be filtered we 
need keep all. So we remove all ids from filtered ids set



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