ZENOTME commented on code in PR #1422: URL: https://github.com/apache/iceberg-python/pull/1422#discussion_r1892659133
########## tests/test_transforms.py: ########## @@ -988,608 +997,367 @@ def _test_projection(lhs: Optional[UnboundPredicate[L]], rhs: Optional[UnboundPr raise ValueError(f"Comparing unrelated: {lhs} <> {rhs}") +def _assert_projection_strict( + pred: BooleanExpression, + transform: Transform[S, T], + expected_type: type[BooleanExpression], + expected_human_str: Optional[str] = None, +) -> None: + result = transform.strict_project(name="name", pred=pred) + + assert type(result) is expected_type or AlwaysFalse + + if expected_human_str is not None: + if isinstance(result, LiteralPredicate): + actual_human_str = transform.to_human_string(pred.term.ref().field.field_type, result.literal.value) + elif isinstance(result, SetPredicate): + results = [transform.to_human_string(pred.term.ref().field.field_type, lit.value) for lit in result.literals] + results.sort() + actual_human_str = "[" + ", ".join(results) + "]" + else: + raise ValueError(f"Unknown predicate: {result}") + assert actual_human_str == expected_human_str + + def test_month_projection_strict_epoch(bound_reference_date: BoundReference[int]) -> None: date = literal("1970-01-01").to(DateType()) - transform: Transform[Any, int] = MonthTransform() - _test_projection( - transform.strict_project(name="name", pred=BoundLessThan(term=bound_reference_date, literal=date)), - LessThan(term="name", literal=DateLiteral(0)), - ) - _test_projection( - transform.strict_project(name="name", pred=BoundLessThanOrEqual(term=bound_reference_date, literal=date)), - LessThan(term="name", literal=DateLiteral(0)), - ) - _test_projection( - transform.strict_project(name="name", pred=BoundGreaterThan(term=bound_reference_date, literal=date)), - GreaterThan(term="name", literal=DateLiteral(0)), - ) - _test_projection( - transform.strict_project(name="name", pred=BoundGreaterThanOrEqual(term=bound_reference_date, literal=date)), - GreaterThan(term="name", literal=LongLiteral(-1)), # In Java this is human string 1970-01 - ) - _test_projection( - transform.strict_project(name="name", pred=BoundNotEqualTo(term=bound_reference_date, literal=date)), - NotEqualTo(term="name", literal=DateLiteral(0)), - ) - _test_projection( - lhs=transform.strict_project(name="name", pred=BoundEqualTo(term=bound_reference_date, literal=date)), rhs=None - ) - + transform = MonthTransform() + _assert_projection_strict(BoundLessThan(term=bound_reference_date, literal=date), transform, LessThan, "1970-01") + _assert_projection_strict(BoundLessThanOrEqual(term=bound_reference_date, literal=date), transform, LessThan, "1970-01") + _assert_projection_strict(BoundGreaterThan(term=bound_reference_date, literal=date), transform, GreaterThan, "1970-01") + _assert_projection_strict(BoundGreaterThanOrEqual(term=bound_reference_date, literal=date), transform, GreaterThan, "1969-12") Review Comment: Hi @Fokko, I'm still confused as to why it's not be `_assert_projection_strict(BoundGreaterThanOrEqual(term=bound_reference_date, literal=date), transform, GreaterThan, "1970-01")` here. https://github.com/apache/iceberg-python/pull/539#discussion_r1879010689, It looks like a bug that is not limited to the negative value. Let's assume predicate `date >= 1980-02-02`, strict projection for month partition will project it to `month(date)>1980-01`, assume date is `1980-02-01`, then the strict projection predicate will be true `month(1980-02-01) == 1980-02 > 1980-01`, but original predicate is false. `1980-02-01 < 1980-02-02`. -- 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