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


##########
python/pyiceberg/transforms.py:
##########
@@ -644,8 +751,89 @@ def can_transform(self, _: IcebergType) -> bool:
     def result_type(self, source: IcebergType) -> IcebergType:
         return source
 
+    def project(self, name: str, pred: BoundPredicate) -> 
Optional[UnboundPredicate]:
+        return None
+
     def to_human_string(self, _: IcebergType, value: Optional[S]) -> str:
         return "null"
 
     def __repr__(self) -> str:
         return "VoidTransform()"
+
+
+M = TypeVar("M")
+
+
+def _truncate_number(
+    name: str, pred: BoundLiteralPredicate, transform: Callable[[Optional[M]], 
Optional[M]]
+) -> Optional[UnboundPredicate]:
+    boundary = pred.literal
+
+    if not isinstance(boundary, (LongLiteral, DecimalLiteral, DateLiteral, 
TimeLiteral, TimestampLiteral)):
+        raise ValueError(f"Expected a numeric literal, got: {type(boundary)}")
+
+    if isinstance(pred, BoundLessThan):
+        return LessThanOrEqual(Reference(name), _transform_literal(transform, 
boundary.decrement()))
+    elif isinstance(pred, BoundLessThanOrEqual):
+        return LessThanOrEqual(Reference(name), _transform_literal(transform, 
boundary))
+    elif isinstance(pred, BoundGreaterThan):
+        return GreaterThanOrEqual(Reference(name), 
_transform_literal(transform, boundary.increment()))
+    elif isinstance(pred, BoundGreaterThanOrEqual):
+        return GreaterThanOrEqual(Reference(name), 
_transform_literal(transform, boundary))
+    elif isinstance(pred, BoundEqualTo):
+        return EqualTo(Reference(name), _transform_literal(transform, 
boundary))
+    else:
+        return None
+
+
+def _truncate_array(
+    name: str, pred: BoundLiteralPredicate, func: Callable[[Optional[M]], 
Optional[M]]
+) -> Optional[UnboundPredicate]:
+    boundary = pred.literal
+
+    if type(pred) in {BoundLessThan, BoundLessThanOrEqual}:
+        return LessThanOrEqual(Reference(name), _transform_literal(func, 
boundary))
+    elif type(pred) in {BoundGreaterThan, BoundGreaterThanOrEqual}:
+        return GreaterThanOrEqual(Reference(name), _transform_literal(func, 
boundary))
+    if isinstance(pred, BoundEqualTo):
+        return EqualTo(Reference(name), _transform_literal(func, boundary))
+    else:
+        return None
+
+
+def _project_transform_predicate(transform: Transform, partition_name: str, 
pred: BoundPredicate) -> Optional[UnboundPredicate]:
+    term = pred.term
+    if isinstance(term, BoundTransform) and transform == term.transform:
+        return _remove_transform(partition_name, pred)
+    return None
+
+
+def _remove_transform(partition_name: str, pred: BoundPredicate):
+    if isinstance(pred, BoundUnaryPredicate):
+        return pred.as_unbound(Reference(partition_name))
+    elif isinstance(pred, BoundLiteralPredicate):
+        return pred.as_unbound(Reference(partition_name), pred.literal)
+    elif isinstance(pred, (BoundIn, BoundNotIn)):
+        return pred.as_unbound(Reference(partition_name), pred.literals)
+    else:
+        raise ValueError(f"Cannot replace transform in unknown predicate: 
{pred}")
+
+
+def _transform_set(name: str, pred: BoundSetPredicate, func: 
Callable[[Optional[M]], Optional[M]]) -> UnboundPredicate:

Review Comment:
   I think the difference is that this is only called to truncate? Maybe it 
should be `_truncate_set` then?



-- 
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-unsubscr...@iceberg.apache.org

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


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

Reply via email to