-
Notifications
You must be signed in to change notification settings - Fork 186
Add temporal interval data type and support interval clause as function #687
Add temporal interval data type and support interval clause as function #687
Conversation
@@ -172,4 +171,8 @@ public static Boolean getBooleanValue(ExprValue exprValue) { | |||
public static ZonedDateTime getDateValue(ExprValue exprValue) { | |||
return exprValue.dateValue(); | |||
} | |||
|
|||
public static TemporalAmount getIntervalValue(ExprValue exprValue) { |
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.
do we need this method?
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.
yes, i've also added getTimeValue, getDatetimeValue, getTimestampValue in the other PR #694 to stay consistent. We can also remove all these methods including the getDateValue actually
core/src/main/java/com/amazon/opendistroforelasticsearch/sql/ast/expression/DataType.java
Show resolved
Hide resolved
...src/main/java/com/amazon/opendistroforelasticsearch/sql/expression/function/FunctionDSL.java
Show resolved
Hide resolved
.../main/java/com/amazon/opendistroforelasticsearch/sql/expression/datetime/IntervalClause.java
Outdated
Show resolved
Hide resolved
So in this PR the changes regarding parser only covers PPL language? |
Added parser in SQL in the latest update, thanks! |
Thanks for adding! In this case please add comparison test case to make sure it can work with JDBC driver together. |
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
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!
# Conflicts: # sql/src/main/java/com/amazon/opendistroforelasticsearch/sql/sql/parser/AstExpressionBuilder.java # sql/src/test/java/com/amazon/opendistroforelasticsearch/sql/sql/parser/AstExpressionBuilderTest.java
Issue #, if available:
Description of changes:
Doc: https://github.com/chloe-zh/sql/blob/interval/docs/user/general/datatypes.rst
Added
INTERVAL
data type in the SQL language structure. Syntax:INTERVAL expr unit
. The corresponding expression value isExprIntervalValue
that can encapsulate the temporal amount as the property value.Quantity expression
expr
in interval clause can be any value expression, including the basic numeric values, field expression, functions etc. which has been revealed in the parser.Interval units to support for phase 1: microsecond, second, minute, hour, day, week, month, quarter, year.
Added docs for date and time data types.
[TODO] Current PR does not contain examples of date and time types in the reference manual yet. These examples will be added in the coming PR for datetime functions where functions
date
,time
,datetime
,timestamp
andinterval
are implemented.Note:
Interval data type maps to
TemporalAmount
in Java runtime, it has two types of amountDuration
subclass that can be mapped with microseconds to days, where all amount would be converted to a value withsecond
as the unit; and another amountPeriod
can be mapped with days to years, where the values would be converted to some value withday
as the the unit. This rule is similar to H2: https://www.h2database.com/html/datatypes.html#interval_typeIn this PR, these two types are sharing the same syntax, but will differ in the storage method, and is only comparable with the same type of interval. For example, the comparison between
INTERVAL 1 week
withINTERVAL 1 month
will result in 1 week is shorter than 1 month, but an attempt to compareINTERVAL 1 week
withINTERVAL 1 minute
will fail and throw an exception. Which is also similar to H2 behavior.By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.