xabriel commented on a change in pull request #123: Add support for struct 
field based filtering
URL: https://github.com/apache/incubator-iceberg/pull/123#discussion_r264358717
 
 

 ##########
 File path: 
api/src/main/java/com/netflix/iceberg/expressions/BoundReference.java
 ##########
 @@ -32,19 +32,41 @@
 
   BoundReference(Types.StructType struct, int fieldId) {
     this.fieldId = fieldId;
-    this.pos = find(fieldId, struct);
-    this.type = struct.fields().get(pos).type();
+    this.pos = findTopFieldPos(fieldId, struct);
+    this.type = (pos > -1) ? struct.fields().get(pos).type() : 
findStructFieldType(fieldId, struct);
   }
 
-  private int find(int fieldId, Types.StructType struct) {
+  private int findTopFieldPos(int fieldId, Types.StructType struct) {
     List<Types.NestedField> fields = struct.fields();
     for (int i = 0; i < fields.size(); i += 1) {
       if (fields.get(i).fieldId() == fieldId) {
         return i;
       }
     }
-    throw new ValidationException(
-        "Cannot find top-level field id %d in struct: %s", fieldId, struct);
+
+    return -1;
+  }
+
+  private Type findStructFieldType(int fieldId, Types.StructType struct) {
+    List<Types.NestedField> fields = struct.fields();
+    for (int i = 0; i < fields.size(); i += 1) {
+
+      if (fields.get(i).fieldId() == fieldId) {
+        return fields.get(i).type();
+      } else {
+
+        // look under struct by calling this method recursively
+        if (fields.get(i).type() instanceof Types.StructType) {
+          Types.StructType subStruct = fields.get(i).type().asStructType();
+
+          Type ret = findStructFieldType(fieldId, subStruct);
+          if (ret != null) {
 
 Review comment:
   Minor: Looks like your recursive call would never 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.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

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

Reply via email to