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(timestamps): add support for timestamp/date +/- intervals for additional backends #9799

Merged
merged 10 commits into from
Aug 8, 2024

Conversation

cpcloud
Copy link
Member

@cpcloud cpcloud commented Aug 8, 2024

Based on #9794, I decided to investigate whether we can do a bit better on date/timestamp +/- interval-style operations.

Many backends support adding and subtracting intervals from dates and timestamps, but do not support intervals as a first-class type, and we can allow that functionality to work.

This PR adds support for those operations to mssql and oracle and consolidates some existing implementation details around the IntervalFromInteger operation.

@cpcloud cpcloud added feature Features or general enhancements mysql The MySQL backend timestamps Issues related to the timestamp API mssql The Microsoft SQL Server backend oracle The Oracle backend labels Aug 8, 2024
Copy link
Contributor

github-actions bot commented Aug 8, 2024

ACTION NEEDED

Ibis follows the Conventional Commits specification for release automation.

The PR title and description are used as the merge commit message.

Please update your PR title and description to match the specification.

@cpcloud cpcloud changed the title more intervals feat(timestamps): add support for timestamp/date +/- intervals for additional backends Aug 8, 2024
@cpcloud cpcloud requested a review from gforsyth August 8, 2024 14:30
month = alltypes.date_string_col[:2]
day = alltypes.date_string_col[3:5]
year = alltypes.date_string_col[6:8]
date_col = ("20" + year + "-" + month + "-" + day).cast("date")
Copy link
Member Author

Choose a reason for hiding this comment

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

More backends implement the primitives here than the previous code, which used arrays.

@@ -404,6 +400,8 @@ def visit_Cast(self, op, *, arg, to):
return arg
elif from_.is_integer() and to.is_timestamp():
return self.f.dateadd(self.v.s, arg, "1970-01-01 00:00:00")
elif from_.is_integer() and to.is_interval():
return sge.Interval(this=arg, unit=self.v[to.unit.singular])
Copy link
Member Author

Choose a reason for hiding this comment

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

Since this is such a common implementation I'm going to try and encode the logic in the base implementation of visit_Cast

Copy link
Member

@gforsyth gforsyth left a comment

Choose a reason for hiding this comment

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

Looks good -- not sure if you wanted to handle the casting work in this PR or separately

@cpcloud
Copy link
Member Author

cpcloud commented Aug 8, 2024

I'll do it in a follow-up now that you mention it.

@cpcloud
Copy link
Member Author

cpcloud commented Aug 8, 2024

Lemme run the clouds

@cpcloud cpcloud added the ci-run-cloud Add this label to trigger a run of BigQuery, Snowflake, and Databricks backends in CI label Aug 8, 2024
@ibis-docs-bot ibis-docs-bot bot removed the ci-run-cloud Add this label to trigger a run of BigQuery, Snowflake, and Databricks backends in CI label Aug 8, 2024
@cpcloud cpcloud merged commit 79cef68 into ibis-project:main Aug 8, 2024
90 checks passed
@cpcloud cpcloud deleted the more-intervals branch August 8, 2024 16:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature Features or general enhancements mssql The Microsoft SQL Server backend mysql The MySQL backend oracle The Oracle backend timestamps Issues related to the timestamp API
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants