-
Notifications
You must be signed in to change notification settings - Fork 179
Add implementation of now, sysdate, localtime and similar functions
#754
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
Add implementation of now, sysdate, localtime and similar functions
#754
Conversation
This comment was marked as spam.
This comment was marked as spam.
4a6a9be to
d5e8a21
Compare
dai-chen
left a comment
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.
Thanks for the changes!
core/src/main/java/org/opensearch/sql/expression/datetime/DateTimeFunction.java
Outdated
Show resolved
Hide resolved
|
@Yury-Fridlyand please update the target branch from |
1e42e2b
…ions (#92) Signed-off-by: Yury-Fridlyand <[email protected]>
Signed-off-by: Yury-Fridlyand <[email protected]>
1e42e2b to
425a998
Compare
| repository.register(week()); | ||
| repository.register(year()); | ||
|
|
||
| repository.register(now()); |
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.
nit: should have inserted these alphabetically into the above list
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'll update in next PR
Signed-off-by: Yury-Fridlyand <[email protected]>
bd79364
dai-chen
left a comment
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.
LGTM. Thanks for the changes!
Signed-off-by: MitchellGale-BitQuill <[email protected]>
* Update docs. Signed-off-by: Yury-Fridlyand <[email protected]> * Reorder functions in docs aplhabetically. Signed-off-by: Yury-Fridlyand <[email protected]> Signed-off-by: Yury-Fridlyand <[email protected]>
…-project#884) * Update docs. Signed-off-by: Yury-Fridlyand <[email protected]> * Reorder functions in docs aplhabetically. Signed-off-by: Yury-Fridlyand <[email protected]> Signed-off-by: Yury-Fridlyand <[email protected]>
Signed-off-by: Yury Fridlyand [email protected]
Description
New functions added:
New signatures:
now():datetimecurrent_timestamp():datetimecurrent_timestamp:datetimelocaltimestamp():datetimelocaltimestamp:datetimelocaltime():datetimelocaltime:datetimesysdate():datetimesysdate(int):datetimecurtime():timecurrent_time():timecurrent_time:timecurdate():datecurrent_date():datecurrent_date:dateNot added signatures
now(int):datetimecurrent_timestamp(int):datetimelocaltimestamp(int):datetimelocaltime(int):datetimecurtime(int):timecurrent_time(int):timeTests
SQL
PPL
Implementation details
NOWandSYSDATEdifferenceAccording to
MySQLstandardI had to save and then to pick time when plugin receives a query.
QueryContextwas chosen to store this unless a better candidate introduced.Parser update
datetimeConstantLiteralwas added toSQLandPPLparsers. It lists pseudo-constants which actually invoke corresponding functions without(). SoCURRENT_DATEis shortcut forCURRENT_DATE()and so on.AstExpressionBuilderwere updated to call a function whendatetimeConstantLiteralmet.AstExpressionBuilderinPPLis updated a bit by addingvisitFunctionmethod and removing some duplicated code. Copied fromAstExpressionBuilderinSQL.ANTLRrules were copied fromSQLtoPPL.ConstantFunctionentity added to represent functions which values should be cached in scope of the current query. Cache is stored inAnalysisContext. This includes changes in:SQLparserPPLparserExpressionAnalyzerConstantFunction) except:sysdatecurdatecurrent_datenow()andnow(int)are different functions, they can't use common cache. To avoid these functions being executed more than once,func(int)signatures of them were removed.Please see PR Bit-Quill#113 which adds caching mechanism.
Doctests
Doctests for new functions always fail, because test validate exact string match for result. I added docs, but disabled doctests for them.
Issues Resolved
See also
Check List
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
For more information on following Developer Certificate of Origin and signing off your commits, please check here.