Add CAST expression support to parser - #3207
Conversation
|
@Fokko @geruh @kevinjqliu PTAL |
| expected = EqualTo( | ||
| UnboundTransform(Reference("created_at"), DayTransform()), | ||
| StringLiteral("2024-01-01"), | ||
| ) |
There was a problem hiding this comment.
For testing, I think it would be good to have an integration test as well. The StringLiteral should be converted to a DateLiteral when bound to the transform.
There was a problem hiding this comment.
Added a unit test for this.
|
I've been playing around with this PR and I ran into something. Here's a quick demo script for your own testing. It looks like we're running into this issue because we coerce ts to a TimestampType at comparison time. That means the right side is |
| assert expected == parser.parse("CAST(created_at AS date) = '2024-01-01'") | ||
|
|
||
|
|
||
| def test_cast_date_binds_string_literal_to_date() -> None: |
There was a problem hiding this comment.
We should have more tests like this with uneven types. I posted an example in another comment.
|
This pull request has been marked as stale due to 30 days of inactivity. It will be closed in 1 week if no further activity occurs. If you think that's incorrect or this pull request requires a review, please simply write any comment. If closed, you can revive the PR at any time and @mention a reviewer or discuss it on the dev@iceberg.apache.org list. Thank you for your contributions. |
Closes #198
Picks up where #209 left off with @Fokko's feedback addressed. Thanks @jayceslesar for the original work.
Rationale for this change
Adds
CAST(column AS type)parsing that maps to Iceberg transforms (date→DayTransform,year→YearTransform,month→MonthTransform,hour→HourTransform). Also implementsBoundTransform.ref()andeval()— both were missing abstract methods required byBoundTerm. IntroducesUnboundTransformwithbind()that validates viacan_transform().Are these changes tested?
Yes. 11 new tests covering all transform types, case insensitivity, nested fields, unsupported types, comparison operators, and boolean composition.
Are there any user-facing changes?
No.