forked from opensearch-project/sql
-
Notifications
You must be signed in to change notification settings - Fork 0
Dialect fixes for operator.date test as of AOS-203 #4
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
Closed
Closed
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
d62d23f
Added few functions to compare date and datetimes to fix some test ca…
Yury-Fridlyand 96ac3ca
Using CAST instead of type conversion because it has higher performance
Yury-Fridlyand be77676
Added DATE_FORMAT because CAST to TIMESTAMP doesn't work for all types
Yury-Fridlyand 634d4e8
Typo fix
Yury-Fridlyand 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -63,16 +63,87 @@ | |
| <argument type='datetime' /> | ||
| <argument type='datetime' /> | ||
| </function> | ||
|
|
||
| <function group='operator' name='==' return-type='bool'> | ||
| <formula>(CAST(DATE_FORMAT(%1, '%Y-%m-%d %H:%i:%s') AS TIMESTAMP)) = CAST(DATE_FORMAT(%2, '%Y-%m-%d %H:%i:%s') as TIMESTAMP))</formula> | ||
| <argument type='date' /> | ||
| <argument type='datetime' /> | ||
| </function> | ||
| <function group='operator' name='==' return-type='bool'> | ||
| <formula>(CAST(DATE_FORMAT(%1, '%Y-%m-%d %H:%i:%s') AS TIMESTAMP)) = CAST(DATE_FORMAT(%2, '%Y-%m-%d %H:%i:%s') as TIMESTAMP))</formula> | ||
| <argument type='datetime' /> | ||
| <argument type='date' /> | ||
| </function> | ||
| <function group='operator' name='!=' return-type='bool'> | ||
| <formula>(CAST(DATE_FORMAT(DATE(%1), '%Y-%m-%d 00:00:00') AS TIMESTAMP) <> %2)</formula> | ||
| <formula>(CAST(DATE_FORMAT(%1, '%Y-%m-%d %H:%i:%s') AS TIMESTAMP)) <> CAST(DATE_FORMAT(%2, '%Y-%m-%d %H:%i:%s') as TIMESTAMP))</formula> | ||
| <argument type='date' /> | ||
| <argument type='datetime' /> | ||
| </function> | ||
| <function group='operator' name='!=' return-type='bool'> | ||
| <formula>(%1 <> CAST(DATE_FORMAT(DATE(%2), '%Y-%m-%d 00:00:00') AS TIMESTAMP))</formula> | ||
| <formula>(CAST(DATE_FORMAT(%1, '%Y-%m-%d %H:%i:%s') AS TIMESTAMP)) <> CAST(DATE_FORMAT(%2, '%Y-%m-%d %H:%i:%s') as TIMESTAMP))</formula> | ||
| <argument type='datetime' /> | ||
| <argument type='date' /> | ||
| </function> | ||
| <function group='operator' name='>=' return-type='bool'> | ||
| <formula>(CAST(DATE_FORMAT(%1, '%Y-%m-%d %H:%i:%s') AS TIMESTAMP)) >= CAST(DATE_FORMAT(%2, '%Y-%m-%d %H:%i:%s') as TIMESTAMP))</formula> | ||
| <argument type='date' /> | ||
| <argument type='datetime' /> | ||
| </function> | ||
| <function group='operator' name='>=' return-type='bool'> | ||
| <formula>(CAST(DATE_FORMAT(%1, '%Y-%m-%d %H:%i:%s') AS TIMESTAMP)) >= CAST(DATE_FORMAT(%2, '%Y-%m-%d %H:%i:%s') as TIMESTAMP))</formula> | ||
| <argument type='datetime' /> | ||
| <argument type='date' /> | ||
| </function> | ||
| <function group='operator' name='<=' return-type='bool'> | ||
| <formula>(CAST(DATE_FORMAT(%1, '%Y-%m-%d %H:%i:%s') as TIMESTAMP)) <= CAST(DATE_FORMAT(%2, '%Y-%m-%d %H:%i:%s') as TIMESTAMP))</formula> | ||
| <argument type='date' /> | ||
| <argument type='datetime' /> | ||
| </function> | ||
| <function group='operator' name='<=' return-type='bool'> | ||
| <formula>(CAST(DATE_FORMAT(%1, '%Y-%m-%d %H:%i:%s') as TIMESTAMP)) <= CAST(DATE_FORMAT(%2, '%Y-%m-%d %H:%i:%s') as TIMESTAMP))</formula> | ||
| <argument type='datetime' /> | ||
| <argument type='date' /> | ||
| </function> | ||
| <function group='operator' name='>' return-type='bool'> | ||
| <formula>(CAST(DATE_FORMAT(%1, '%Y-%m-%d %H:%i:%s') as TIMESTAMP)) > CAST(DATE_FORMAT(%2, '%Y-%m-%d %H:%i:%s') as TIMESTAMP))</formula> | ||
| <argument type='date' /> | ||
| <argument type='datetime' /> | ||
| </function> | ||
| <function group='operator' name='>' return-type='bool'> | ||
| <formula>(CAST(DATE_FORMAT(%1, '%Y-%m-%d %H:%i:%s') as TIMESTAMP)) > CAST(DATE_FORMAT(%2, '%Y-%m-%d %H:%i:%s') as TIMESTAMP))</formula> | ||
| <argument type='datetime' /> | ||
| <argument type='date' /> | ||
| </function> | ||
| <function group='operator' name='<' return-type='bool'> | ||
| <formula>(CAST(DATE_FORMAT(%1, '%Y-%m-%d %H:%i:%s') as TIMESTAMP)) < CAST(DATE_FORMAT(%2, '%Y-%m-%d %H:%i:%s') as TIMESTAMP))</formula> | ||
| <argument type='date' /> | ||
| <argument type='datetime' /> | ||
| </function> | ||
| <function group='operator' name='<' return-type='bool'> | ||
| <formula>(CAST(DATE_FORMAT(%1, '%Y-%m-%d %H:%i:%s') as TIMESTAMP)) < CAST(DATE_FORMAT(%2, '%Y-%m-%d %H:%i:%s') as TIMESTAMP))</formula> | ||
| <argument type='datetime' /> | ||
| <argument type='date' /> | ||
| </function> | ||
|
|
||
| <function group='operator' name='-' return-type='real'> | ||
| <!-- 86400 as it represents seconds in a day --> | ||
| <formula>((TO_DAYS(CAST(%1 as TIMESTAMP)) - TO_DAYS(CAST(%2 as TIMESTAMP))) + ((TIME_TO_SEC(CAST(%1 as TIMESTAMP)) - TIME_TO_SEC(CAST(%2 as TIMESTAMP))) / 86400.0))</formula> | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Casting DATE to TIMESTAMP doesn't work. We have to use TIMESTAMP() or DATE_FORMAT. Ideally we should use SUBDATE(TIMESTAMP(%2), INTERVAL HOUR(TIMESTAMP(%2)) HOUR). |
||
| <argument type='date' /> | ||
| <argument type='datetime' /> | ||
| </function> | ||
| <function group='operator' name='-' return-type='real'> | ||
| <!-- 86400 as it represents seconds in a day --> | ||
| <formula>((TO_DAYS(CAST(%1 as TIMESTAMP)) - TO_DAYS(CAST(%2 as TIMESTAMP))) + ((TIME_TO_SEC(CAST(%1 as TIMESTAMP)) - TIME_TO_SEC(CAST(%2 as TIMESTAMP))) / 86400.0))</formula> | ||
| <argument type='datetime' /> | ||
| <argument type='date' /> | ||
| </function> | ||
| <function group='operator' name='-' return-type='real'> | ||
| <!-- 86400 as it represents seconds in a day --> | ||
| <formula>((TO_DAYS(CAST(%1 as TIMESTAMP)) - TO_DAYS(CAST(%2 as TIMESTAMP))) + ((TIME_TO_SEC(CAST(%1 as TIMESTAMP)) - TIME_TO_SEC(CAST(%2 as TIMESTAMP))) / 86400.0))</formula> | ||
| <argument type='datetime' /> | ||
| <argument type='datetime' /> | ||
| </function> | ||
|
|
||
| <function group='operator' name='+' return-type='datetime'> | ||
| <!-- 86400 as it represents seconds in a day --> | ||
| <formula>DATE_ADD(DATE_ADD(%1, INTERVAL FLOOR(%2) DAY), INTERVAL CAST(86400 * (%2 - FLOOR(%2)) AS INT) SECOND)</formula> | ||
|
|
||
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.
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.
I think just calling TIMESTAMP would cause an issue where the time would not be 00:00:00 as expected. We have to do something like SUBDATE(TIMESTAMP(DATE(%2)), INTERVAL HOUR(TIMESTAMP(DATE(%2))) HOUR). This will likely result in a an error logged in this issue.
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.
It works fine, see the test on the pic:
