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

 ##########
 File path: api/src/main/java/org/apache/iceberg/expressions/BoundReference.java
 ##########
 @@ -19,57 +19,35 @@
 
 package org.apache.iceberg.expressions;
 
-import java.util.List;
+import org.apache.iceberg.Accessor;
 import org.apache.iceberg.StructLike;
-import org.apache.iceberg.exceptions.ValidationException;
 import org.apache.iceberg.types.Type;
-import org.apache.iceberg.types.Types;
 
 public class BoundReference<T> implements Reference {
   private final int fieldId;
-  private final Type type;
-  private final int pos;
+  private final Accessor<StructLike> accessor;
 
-  BoundReference(Types.StructType struct, int fieldId) {
+  BoundReference(int fieldId, Accessor<StructLike> accessor) {
     this.fieldId = fieldId;
-    this.pos = find(fieldId, struct);
-    this.type = struct.fields().get(pos).type();
-  }
-
-  private int find(int id, Types.StructType struct) {
-    List<Types.NestedField> fields = struct.fields();
-    for (int i = 0; i < fields.size(); i += 1) {
-      if (fields.get(i).fieldId() == id) {
-        return i;
-      }
-    }
-    throw new ValidationException(
-        "Cannot find top-level field id %d in struct: %s", id, struct);
+    this.accessor = accessor;
   }
 
   public Type type() {
-    return type;
+    return accessor.type();
   }
 
   public int fieldId() {
     return fieldId;
   }
 
-  public int pos() {
-    return pos;
-  }
-
+  @SuppressWarnings("unchecked")
   public T get(StructLike struct) {
-    return struct.get(pos, javaType());
+    return (T) accessor.get(struct);
   }
 
   @Override
   public String toString() {
-    return String.format("ref(id=%d, pos=%d, type=%s)", fieldId, pos, type);
+    return String.format("ref(id=%d, accessor=%s)", fieldId, accessor);
 
 Review comment:
   Accessors don't implement `toString`.

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