samredai commented on code in PR #4619:
URL: https://github.com/apache/iceberg/pull/4619#discussion_r857156833


##########
python/src/iceberg/expressions/base.py:
##########
@@ -147,3 +148,61 @@ def get(self, container: StructProtocol) -> Any:
             Any: The value at position `self.position` in the container
         """
         return container.get(self.position)
+
+
+class BoundReference:
+    """A reference bound to a field with an accessor for acquiring the field's 
value
+
+    Args:
+        field (NestedField): A referenced field in an Iceberg schema
+        accessor (Accessor): An Accessor object to access the value at the 
field's position
+    """
+
+    def __init__(self, field: NestedField, accessor: Accessor):
+        self._field = field
+        self._accessor = accessor
+
+    def __str__(self):
+        return f"ref(id={self.field_id})"
+
+    def __repr__(self):
+        return f"BoundReference(field={repr(self.field)}, 
accessor={repr(self.accessor)})"
+
+    @property
+    def field(self) -> NestedField:
+        """The referenced field"""
+        return self._field
+
+    @property
+    def field_id(self) -> int:
+        """The ID referenced field"""
+        return self._field.field_id
+
+    @property
+    def field_type(self) -> IcebergType:
+        """The type of the referenced field"""
+        return self._field.type
+
+    @property
+    def accessor(self) -> Accessor:
+        """The accessor for retrieving the value at the referenced field's 
position"""
+        return self._accessor
+
+    def __eq__(self, other) -> bool:
+        if id(self) == id(other):
+            return True
+        elif other is None or not isinstance(other, BoundReference):
+            return False

Review Comment:
   In the path you described it would fall to the return statement at the end 
of the function:
   ```py
           return self.field_id == other.field_id and self.field_type == 
other.field_type
   ```
   I don't yet have full context around all scenarios where we'd compare 
against a `BoundReference` but the if/else here is just to get the easy cases 
(True is the id is the same, False if `other` isn't even a `BoundReference`). 
In the case where the ids differ but `other` is a `BoundReference`, it checks 
if the field being bound is the same ID and Type.
   
   One thing I'm noticing though is that `elif other is None or not 
isinstance(other, BoundReference)` is redundant and can be changed to just 
`elif not isinstance(other, BoundReference)`. Updated it!



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