-
Notifications
You must be signed in to change notification settings - Fork 141
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
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
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
@@ -85,6 +89,84 @@ public void register(BuiltinFunctionRepository repository) { | |||
repository.register(to_days()); | |||
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
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()
:datetime
current_timestamp()
:datetime
current_timestamp
:datetime
localtimestamp()
:datetime
localtimestamp
:datetime
localtime()
:datetime
localtime
:datetime
sysdate()
:datetime
sysdate(int)
:datetime
curtime()
:time
current_time()
:time
current_time
:time
curdate()
:date
current_date()
:date
current_date
:date
Not added signatures
now(int)
:datetime
current_timestamp(int)
:datetime
localtimestamp(int)
:datetime
localtime(int)
:datetime
curtime(int)
:time
current_time(int)
:time
Tests
SQL
PPL
Implementation details
NOW
andSYSDATE
differenceAccording to
MySQL
standardI had to save and then to pick time when plugin receives a query.
QueryContext
was chosen to store this unless a better candidate introduced.Parser update
datetimeConstantLiteral
was added toSQL
andPPL
parsers. It lists pseudo-constants which actually invoke corresponding functions without()
. SoCURRENT_DATE
is shortcut forCURRENT_DATE()
and so on.AstExpressionBuilder
were updated to call a function whendatetimeConstantLiteral
met.AstExpressionBuilder
inPPL
is updated a bit by addingvisitFunction
method and removing some duplicated code. Copied fromAstExpressionBuilder
inSQL
.ANTLR
rules were copied fromSQL
toPPL
.ConstantFunction
entity added to represent functions which values should be cached in scope of the current query. Cache is stored inAnalysisContext
. This includes changes in:SQL
parserPPL
parserExpressionAnalyzer
ConstantFunction
) except:sysdate
curdate
current_date
now()
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.