Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Adding literals #76

Merged
merged 2 commits into from
May 28, 2024
Merged

feat: Adding literals #76

merged 2 commits into from
May 28, 2024

Conversation

zeroshade
Copy link
Member

After about 5 or 6 iterations of playing with how to represent expressions to start working on scan planning, I've finally settled on something I like!!

Rather than a huge code dump, I've broken it out into smaller successive PRs so that it is easier to review. This PR contains the definitions for representing Literals, which will then get utilized in constructing BooleanExpressions and so on.

@zeroshade
Copy link
Member Author

CC @Fokko @nastra @wolfeidau

@wolfeidau
Copy link
Contributor

@zeroshade this is a considerable amount of work, I really need to learn more about the internals of iceberg, mostly working to understand the metadata.

Looks great, nothing stands out as issues to me.

@Fokko Fokko self-requested a review May 14, 2024 18:18
literals.go Outdated
return t, nil
case DateType:
tm := time.UnixMicro(int64(t)).UTC()
return DateLiteral(tm.Truncate(24*time.Hour).Unix() / int64((time.Hour * 24).Seconds())), nil
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe good to break this out into a helper class, so it can be re-used.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shifted this into a method on the Timestamp type. It now has a ToDate() Date method which does this and the cast calls that method.

literals.go Outdated

return TimeLiteral(val), nil
case TimestampType:
val, err := arrow.TimestampFromString(string(s), arrow.Microsecond)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In Iceberg we are quite strict around our timezone handling. A TimestampType should have no timestamp, TimestampTzType should have mentioned the timestamp explicitly. See https://github.com/apache/iceberg-python/blob/42afc439d362ef1b3dcff03a1ffd959bc0a399ca/pyiceberg/utils/datetime.py#L29-L33

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@zeroshade can you fix this one before merging?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed, I also added tests to verify the errors for casting to TimestampType with a timezone and casting to TimestampTzType without a timezone. Let me know if I misunderstood anything. Thanks!

Copy link
Contributor

@Fokko Fokko left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some small suggestions, but looks good to me 👍

@Fokko
Copy link
Contributor

Fokko commented May 27, 2024

@zeroshade Thanks! Can you fix the conflicts?

@zeroshade
Copy link
Member Author

updated and fixed the conflicts @Fokko! 😄

@Fokko
Copy link
Contributor

Fokko commented May 28, 2024

@zeroshade Awesome, let's get this in! 🚀

@Fokko Fokko merged commit 3c37b10 into apache:main May 28, 2024
5 checks passed
@zeroshade zeroshade deleted the add-literals branch May 28, 2024 15:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants