SQL: Introduce INTERVAL support #35521
Merged
costin merged 9 commits intoelastic:masterfrom Nov 21, 2018
Merged
Conversation
Introduce INTERVAL as a DataType Add INTERVAL to the grammar which supports the standard SQL declaration (without precision): > INTERVAL '1 23:45:01.123456789' DAY TO SECOND but also number for single unit intervals: > INTERVAL 1 YEAR as well as the plurals of the units: > INTERVAL 2 YEARS Interval are internally supported as just another Literal being backed by java.time.Period and java.time.Duration Move JDBC away from JDBCType enum to SQLType interface Refactor DataType by: - move it into server core - add dedicated (and much simpler) JDBC type Improve internal JDBC conversion by normalizing on the DataType Rename JDBC columnInfo to JdbcColumnInfo to differentiate between it and the SQL ColumnInfo Left to do: 4. add basic operation +/- between intervals 5. add basic operation +/- between timestamps and intervals 6. add conversion of intervals and other datatypes (see what functions make sense) 7. introduce now/current date/current time/current timestamp methods Fix elastic#29990
Collaborator
|
Pinging @elastic/es-search-aggs |
astefan
reviewed
Nov 15, 2018
Contributor
astefan
left a comment
There was a problem hiding this comment.
Impressive. Left some minor/picky comments.
...lugin/sql/jdbc/src/main/java/org/elasticsearch/xpack/sql/jdbc/net/client/JdbcHttpClient.java
Outdated
Show resolved
Hide resolved
...lugin/sql/jdbc/src/main/java/org/elasticsearch/xpack/sql/jdbc/jdbc/JdbcDatabaseMetaData.java
Outdated
Show resolved
Hide resolved
...in/sql/jdbc/src/test/java/org/elasticsearch/xpack/sql/jdbc/net/protocol/ColumnInfoTests.java
Outdated
Show resolved
Hide resolved
...in/sql/jdbc/src/test/java/org/elasticsearch/xpack/sql/jdbc/net/protocol/ColumnInfoTests.java
Outdated
Show resolved
Hide resolved
...in/sql/jdbc/src/test/java/org/elasticsearch/xpack/sql/jdbc/net/protocol/ColumnInfoTests.java
Outdated
Show resolved
Hide resolved
...k/plugin/sql/src/main/java/org/elasticsearch/xpack/sql/expression/literal/IntervalUtils.java
Outdated
Show resolved
Hide resolved
...k/plugin/sql/src/main/java/org/elasticsearch/xpack/sql/expression/literal/IntervalUtils.java
Show resolved
Hide resolved
...k/plugin/sql/src/main/java/org/elasticsearch/xpack/sql/expression/literal/IntervalUtils.java
Outdated
Show resolved
Hide resolved
...k/plugin/sql/src/main/java/org/elasticsearch/xpack/sql/expression/literal/IntervalUtils.java
Outdated
Show resolved
Hide resolved
...gin/sql/src/test/java/org/elasticsearch/xpack/sql/expression/literal/IntervalUtilsTests.java
Outdated
Show resolved
Hide resolved
matriv
reviewed
Nov 19, 2018
Contributor
matriv
left a comment
There was a problem hiding this comment.
Left some comments, but still reviewing.
x-pack/plugin/sql/jdbc/src/main/java/org/elasticsearch/xpack/sql/jdbc/jdbc/JdbcResultSet.java
Show resolved
Hide resolved
x-pack/plugin/sql/src/test/java/org/elasticsearch/xpack/sql/type/DataTypesTests.java
Outdated
Show resolved
Hide resolved
x-pack/plugin/sql/src/test/java/org/elasticsearch/xpack/sql/type/DataTypesTests.java
Outdated
Show resolved
Hide resolved
x-pack/plugin/sql/src/test/java/org/elasticsearch/xpack/sql/type/DataTypesTests.java
Show resolved
Hide resolved
x-pack/plugin/sql/src/test/java/org/elasticsearch/xpack/sql/parser/ExpressionTests.java
Show resolved
Hide resolved
matriv
reviewed
Nov 19, 2018
x-pack/plugin/sql/qa/src/main/java/org/elasticsearch/xpack/sql/qa/jdbc/JdbcAssert.java
Show resolved
Hide resolved
matriv
reviewed
Nov 19, 2018
Contributor
matriv
left a comment
There was a problem hiding this comment.
Finished review, left some more comments/questions. Really nice work!!
x-pack/plugin/sql/sql-proto/src/main/java/org/elasticsearch/xpack/sql/proto/StringUtils.java
Outdated
Show resolved
Hide resolved
...gin/sql/sql-proto/src/main/java/org/elasticsearch/xpack/sql/proto/type/ExtendedJDBCType.java
Outdated
Show resolved
Hide resolved
x-pack/plugin/sql/src/main/java/org/elasticsearch/xpack/sql/parser/ExpressionBuilder.java
Show resolved
Hide resolved
...gin/sql/src/test/java/org/elasticsearch/xpack/sql/expression/literal/IntervalUtilsTests.java
Outdated
Show resolved
Hide resolved
Fix datetime formatting
9fc8f29 to
3d62531
Compare
matriv
reviewed
Nov 21, 2018
| // | ||
| // Math | ||
| // | ||
| public static Number add(Number left, Number right) { |
Contributor
There was a problem hiding this comment.
Why did you switch to object? We should have already validated they are Numbers or not?
Contributor
There was a problem hiding this comment.
Ah, ignore, I rushed, it's because of numeric operations between intervals.
matriv
reviewed
Nov 21, 2018
| return Arithmetics.add((ZonedDateTime) r, ((IntervalDayTime) l).interval()); | ||
| } | ||
|
|
||
| throw new SqlIllegalArgumentException("Cannot compute [+] between [{}] [{}]", l.getClass(), r.getClass()); |
Contributor
There was a problem hiding this comment.
Please add a test for this case.
matriv
reviewed
Nov 21, 2018
| throw new SqlIllegalArgumentException("Cannot substract a date from an interval; do you mean the reverse?"); | ||
| } | ||
|
|
||
| throw new SqlIllegalArgumentException("Cannot compute [-] between [{}] [{}]", l.getClass(), r.getClass()); |
matriv
approved these changes
Nov 21, 2018
Contributor
matriv
left a comment
There was a problem hiding this comment.
LGTM. Nice! (Added two pointers to add some test for Exception throwing)
Member
Author
|
test this please |
costin
added a commit
that referenced
this pull request
Nov 21, 2018
Introduce INTERVAL as a DataType Add INTERVAL to the grammar which supports the standard SQL declaration (without precision): > INTERVAL '1 23:45:01.123456789' DAY TO SECOND but also number for single unit intervals: > INTERVAL 1 YEAR as well as the plurals of the units: > INTERVAL 2 YEARS Interval are internally supported as just another Literal being backed by java.time.Period and java.time.Duration Move JDBC away from JDBCType enum to SQLType interface Refactor DataType by moving it into server core and adding dedicated (and much simpler) JDBC driver type Improve internal JDBC conversion by normalizing on the DataType Rename JDBC columnInfo to JdbcColumnInfo to differentiate between it and the SQL ColumnInfo Fix #29990 (cherry picked from commit f0a3d32)
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Sorry for the big PR. It had rippling effects through the code base.
Introduce INTERVAL as a DataType
Add INTERVAL to the grammar which supports the standard SQL declaration
(without precision):
but also number for single unit intervals:
as well as the plurals of the units:
Interval are internally supported as just another Literal being backed
by java.time.Period and java.time.Duration
Move JDBC away from JDBCType enum to SQLType interface
Refactor DataType by:
Improve internal JDBC conversion by normalizing on the DataType
Rename JDBC columnInfo to JdbcColumnInfo to differentiate between it and
the SQL ColumnInfo
Extended arithmetic operations to support operations between intervals and intervals and dates
(underlying folding operation not implemented yet)
Left to do:
Fix #29990