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/11/26 22:04:06 UTC

[GitHub] [iceberg] rdblue commented on a diff in pull request #6258: Python: Implement PyArrow row level filtering

rdblue commented on code in PR #6258:
URL: https://github.com/apache/iceberg/pull/6258#discussion_r1032837463


##########
python/pyiceberg/io/pyarrow.py:
##########
@@ -379,3 +400,95 @@ def _(_: StringType) -> pa.DataType:
 def _(_: BinaryType) -> pa.DataType:
     # Variable length by default
     return pa.binary()
+
+
+class _ConvertToArrowExpression(BooleanExpressionVisitor[pc.Expression]):
+    def visit_true(self) -> pc.Expression:
+        return pc.scalar(True)
+
+    def visit_false(self) -> pc.Expression:
+        return pc.scalar(False)
+
+    def visit_not(self, child_result: pc.Expression) -> pc.Expression:
+        return ~child_result
+
+    def visit_and(self, left_result: pc.Expression, right_result: pc.Expression) -> pc.Expression:
+        return left_result & right_result
+
+    def visit_or(self, left_result: pc.Expression, right_result: pc.Expression) -> pc.Expression:
+        return left_result | right_result
+
+    def visit_unbound_predicate(self, predicate: UnboundPredicate[L]) -> pc.Expression:
+        raise ValueError("Please bind the expression first")
+
+    def visit_bound_predicate(self, predicate: BoundPredicate[Any]) -> pc.Expression:
+        return _iceberg_to_pyarrow_predicate(predicate)
+
+
+@singledispatch
+def _iceberg_to_pyarrow_predicate(expr: BoundPredicate[str]) -> pc.Expression:
+    raise ValueError(f"Unknown expression: {expr}")
+
+
+@_iceberg_to_pyarrow_predicate.register(BoundIsNull)
+def _(bound: BoundIsNull[str]) -> pc.Expression:
+    return pc.field(bound.term.ref().field.name).is_null(False)

Review Comment:
   Nit: `nan_is_null=False` to avoid confusing nameless boolean.



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