You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@iceberg.apache.org by GitBox <gi...@apache.org> on 2022/05/13 16:44:07 UTC

[GitHub] [iceberg] kbendick commented on a diff in pull request #4599: Orc : Fix inner struct field as partition (#4604)

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


##########
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:
   Nit: This boolean name is a bit strange to me. Is there perhaps a more descriptive name for what this corresponds to? Maybe `doesHaveInnerStruct` or `doesHaveInnerProjectedStruct`?
   
   I was going to ask you to inline the field name with the raw boolean values in the tests, like `true /* filteredStruct /*`, but that still left me with some confusion.



-- 
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: issues-unsubscribe@iceberg.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org