-
Notifications
You must be signed in to change notification settings - Fork 95
feat(isthmus): enable precision timestamp addition/subtraction #745
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
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
201 changes: 201 additions & 0 deletions
201
isthmus/src/test/java/io/substrait/isthmus/PrecisionTimestampDatetimeAdditionTest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,201 @@ | ||
| package io.substrait.isthmus; | ||
|
|
||
| import org.junit.jupiter.api.Test; | ||
|
|
||
| /** | ||
| * Test class for precision timestamp datetime addition operations. Tests the mapping of Calcite's | ||
| * DATETIME_PLUS operator to Substrait's add function for precision_timestamp and | ||
| * precision_timestamp_tz types. | ||
| */ | ||
| class PrecisionTimestampDatetimeAdditionTest extends PlanTestBase { | ||
|
|
||
| static String CREATES = | ||
| "CREATE TABLE events (" | ||
| + "event_id INT, " | ||
| + "event_date DATE, " | ||
| + "event_timestamp TIMESTAMP(3), " | ||
| + "event_timestamp_tz TIMESTAMP(6) WITH LOCAL TIME ZONE" | ||
| + ")"; | ||
|
|
||
| @Test | ||
| void dateAddIntervalYear() throws Exception { | ||
| String query = "SELECT event_date + INTERVAL '1' YEAR FROM events"; | ||
| assertFullRoundTrip(query, CREATES); | ||
| } | ||
|
|
||
| @Test | ||
| void dateAddIntervalMonth() throws Exception { | ||
| String query = "SELECT event_date + INTERVAL '3' MONTH FROM events"; | ||
| assertFullRoundTrip(query, CREATES); | ||
| } | ||
|
|
||
| @Test | ||
| void dateAddIntervalYearToMonth() throws Exception { | ||
| String query = "SELECT event_date + INTERVAL '1-6' YEAR TO MONTH FROM events"; | ||
| assertFullRoundTrip(query, CREATES); | ||
| } | ||
|
|
||
| @Test | ||
| void dateAddIntervalDay() throws Exception { | ||
| String query = "SELECT event_date + INTERVAL '5' DAY FROM events"; | ||
| assertFullRoundTrip(query, CREATES); | ||
| } | ||
|
|
||
| @Test | ||
| void precisionTimestampAddIntervalYear() throws Exception { | ||
| String query = "SELECT event_timestamp + INTERVAL '1' YEAR FROM events"; | ||
| assertFullRoundTrip(query, CREATES); | ||
| } | ||
|
|
||
| @Test | ||
| void precisionTimestampAddIntervalMonth() throws Exception { | ||
| String query = "SELECT event_timestamp + INTERVAL '3' MONTH FROM events"; | ||
| assertFullRoundTrip(query, CREATES); | ||
| } | ||
|
|
||
| @Test | ||
| void precisionTimestampAddIntervalYearToMonth() throws Exception { | ||
| String query = "SELECT event_timestamp + INTERVAL '1-6' YEAR TO MONTH FROM events"; | ||
| assertFullRoundTrip(query, CREATES); | ||
| } | ||
|
|
||
| @Test | ||
| void precisionTimestampAddIntervalDay() throws Exception { | ||
| String query = "SELECT event_timestamp + INTERVAL '5' DAY FROM events"; | ||
| assertFullRoundTrip(query, CREATES); | ||
| } | ||
|
|
||
| @Test | ||
| void precisionTimestampAddIntervalHour() throws Exception { | ||
| String query = "SELECT event_timestamp + INTERVAL '12' HOUR FROM events"; | ||
| assertFullRoundTrip(query, CREATES); | ||
| } | ||
|
|
||
| @Test | ||
| void precisionTimestampAddIntervalMinute() throws Exception { | ||
| String query = "SELECT event_timestamp + INTERVAL '30' MINUTE FROM events"; | ||
| assertFullRoundTrip(query, CREATES); | ||
| } | ||
|
|
||
| @Test | ||
| void precisionTimestampAddIntervalSecond() throws Exception { | ||
| String query = "SELECT event_timestamp + INTERVAL '45' SECOND FROM events"; | ||
| assertFullRoundTrip(query, CREATES); | ||
| } | ||
|
|
||
| @Test | ||
| void precisionTimestampAddIntervalDayToSecond() throws Exception { | ||
| String query = "SELECT event_timestamp + INTERVAL '1 12:30:45' DAY TO SECOND FROM events"; | ||
| assertFullRoundTrip(query, CREATES); | ||
| } | ||
|
|
||
| @Test | ||
| void precisionTimestampTzAddIntervalYear() throws Exception { | ||
| String query = "SELECT event_timestamp_tz + INTERVAL '2' YEAR FROM events"; | ||
| assertFullRoundTrip(query, CREATES); | ||
| } | ||
|
|
||
| @Test | ||
| void precisionTimestampTzAddIntervalMonth() throws Exception { | ||
| String query = "SELECT event_timestamp_tz + INTERVAL '6' MONTH FROM events"; | ||
| assertFullRoundTrip(query, CREATES); | ||
| } | ||
|
|
||
| @Test | ||
| void precisionTimestampTzAddIntervalYearToMonth() throws Exception { | ||
| String query = "SELECT event_timestamp_tz + INTERVAL '2-3' YEAR TO MONTH FROM events"; | ||
| assertFullRoundTrip(query, CREATES); | ||
| } | ||
|
|
||
| @Test | ||
| void precisionTimestampTzAddIntervalDay() throws Exception { | ||
| String query = "SELECT event_timestamp_tz + INTERVAL '10' DAY FROM events"; | ||
| assertFullRoundTrip(query, CREATES); | ||
| } | ||
|
|
||
| @Test | ||
| void precisionTimestampTzAddIntervalHour() throws Exception { | ||
| String query = "SELECT event_timestamp_tz + INTERVAL '6' HOUR FROM events"; | ||
| assertFullRoundTrip(query, CREATES); | ||
| } | ||
|
|
||
| @Test | ||
| void precisionTimestampTzAddIntervalMinute() throws Exception { | ||
| String query = "SELECT event_timestamp_tz + INTERVAL '15' MINUTE FROM events"; | ||
| assertFullRoundTrip(query, CREATES); | ||
| } | ||
|
|
||
| @Test | ||
| void precisionTimestampTzAddIntervalSecond() throws Exception { | ||
| String query = "SELECT event_timestamp_tz + INTERVAL '30' SECOND FROM events"; | ||
| assertFullRoundTrip(query, CREATES); | ||
| } | ||
|
|
||
| @Test | ||
| void precisionTimestampTzAddIntervalDayToSecond() throws Exception { | ||
| String query = "SELECT event_timestamp_tz + INTERVAL '2 06:15:30' DAY TO SECOND FROM events"; | ||
| assertFullRoundTrip(query, CREATES); | ||
| } | ||
|
|
||
| @Test | ||
| void multiplePrecisionTimestampAdditions() throws Exception { | ||
| String query = | ||
| "SELECT " | ||
| + "event_timestamp + INTERVAL '1' YEAR, " | ||
| + "event_timestamp + INTERVAL '5' DAY, " | ||
| + "event_timestamp_tz + INTERVAL '2' MONTH, " | ||
| + "event_timestamp_tz + INTERVAL '12' HOUR " | ||
| + "FROM events"; | ||
| assertFullRoundTrip(query, CREATES); | ||
| } | ||
|
|
||
| @Test | ||
| void precisionTimestampAdditionInWhereClause() throws Exception { | ||
| String query = | ||
| "SELECT event_id FROM events " | ||
| + "WHERE event_timestamp + INTERVAL '1' DAY > TIMESTAMP '2024-01-01 00:00:00'"; | ||
| assertFullRoundTrip(query, CREATES); | ||
| } | ||
|
|
||
| @Test | ||
| void precisionTimestampTzAdditionInWhereClause() throws Exception { | ||
| String query = | ||
| "SELECT event_id FROM events " | ||
| + "WHERE event_timestamp_tz + INTERVAL '1' MONTH > TIMESTAMP WITH LOCAL TIME ZONE '2024-01-01 00:00:00'"; | ||
| assertFullRoundTrip(query, CREATES); | ||
| } | ||
|
|
||
| @Test | ||
| void precisionTimestampAdditionWithComparison() throws Exception { | ||
| String query = | ||
| "SELECT event_id, event_timestamp FROM events " | ||
| + "WHERE event_timestamp + INTERVAL '7' DAY < event_timestamp + INTERVAL '14' DAY"; | ||
| assertFullRoundTrip(query, CREATES); | ||
| } | ||
|
|
||
| @Test | ||
| void dateAdditionInWhereClause() throws Exception { | ||
| String query = | ||
| "SELECT event_id FROM events " + "WHERE event_date + INTERVAL '1' DAY > DATE '2024-01-01'"; | ||
| assertFullRoundTrip(query, CREATES); | ||
| } | ||
|
|
||
| @Test | ||
| void dateAdditionWithComparison() throws Exception { | ||
| String query = | ||
| "SELECT event_id, event_date FROM events " | ||
| + "WHERE event_date + INTERVAL '7' DAY < event_date + INTERVAL '14' DAY"; | ||
| assertFullRoundTrip(query, CREATES); | ||
| } | ||
|
|
||
| @Test | ||
| void multipleDateAdditions() throws Exception { | ||
| String query = | ||
| "SELECT " | ||
| + "event_date + INTERVAL '1' YEAR, " | ||
| + "event_date + INTERVAL '5' DAY, " | ||
| + "event_date + INTERVAL '2' MONTH " | ||
| + "FROM events"; | ||
| assertFullRoundTrip(query, CREATES); | ||
| } | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this somehow still did work with the less specific/wrong SqlOperator. now it uses the right one