Skip to content
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

SQL: Fix display size for DATE/DATETIME #40669

Merged
merged 4 commits into from
Apr 3, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions docs/reference/sql/functions/date-time.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,10 @@ relative date/time filtering:
include-tagged::{sql-specs}/docs/docs.csv-spec[filterNow]
--------------------------------------------------

[IMPORTANT]
Currently, Using a _precision_ greater than 3 doesn't make any difference to the output of the
function as the maximum number of second fractional digits returned is 3 (milliseconds).

[[sql-functions-datetime-day]]
==== `DAY_OF_MONTH/DOM/DAY`

Expand Down
4 changes: 2 additions & 2 deletions docs/reference/sql/language/data-types.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ s|SQL precision
| <<keyword, `keyword`>> | keyword | VARCHAR | 32,766
| <<text, `text`>> | text | VARCHAR | 2,147,483,647
| <<binary, `binary`>> | binary | VARBINARY | 2,147,483,647
| <<date, `date`>> | datetime | TIMESTAMP | 24
| <<date, `date`>> | datetime | TIMESTAMP | 29
| <<ip, `ip`>> | ip | VARCHAR | 39

4+h| Complex types
Expand Down Expand Up @@ -66,7 +66,7 @@ s|SQL type
s|SQL precision


| date | 24
| date | 29
| time | 18
| interval_year | 7
| interval_month | 7
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,16 +67,16 @@ public void testTextualType() throws IOException {

public void testDateTimes() throws IOException {
assertQuery("SELECT CAST('2019-01-14T12:29:25.000Z' AS DATETIME)", "CAST('2019-01-14T12:29:25.000Z' AS DATETIME)",
"datetime", "2019-01-14T12:29:25.000Z", 24);
"datetime", "2019-01-14T12:29:25.000Z", 29);
assertQuery("SELECT CAST(-26853765751000 AS DATETIME)", "CAST(-26853765751000 AS DATETIME)",
"datetime", "1119-01-15T12:37:29.000Z", 24);
"datetime", "1119-01-15T12:37:29.000Z", 29);
assertQuery("SELECT CAST(CAST('-26853765751000' AS BIGINT) AS DATETIME)", "CAST(CAST('-26853765751000' AS BIGINT) AS DATETIME)",
"datetime", "1119-01-15T12:37:29.000Z", 24);
"datetime", "1119-01-15T12:37:29.000Z", 29);

assertQuery("SELECT CAST('2019-01-14' AS DATE)", "CAST('2019-01-14' AS DATE)",
"date", "2019-01-14T00:00:00.000Z", 24);
"date", "2019-01-14T00:00:00.000Z", 29);
assertQuery("SELECT CAST(-26853765751000 AS DATE)", "CAST(-26853765751000 AS DATE)",
"date", "1119-01-15T00:00:00.000Z", 24);
"date", "1119-01-15T00:00:00.000Z", 29);

assertQuery("SELECT CAST('12:29:25.123Z' AS TIME)", "CAST('12:29:25.123Z' AS TIME)",
"time", "12:29:25.123Z", 18);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ SELECT null, 'test1', 'name.keyword', 12, 'KEYWORD', 32766, 2147483647, null, nu
null, null, 12, 0, 2147483647, 1, 'YES', null, null, null, null, 'NO', 'NO'
FROM DUAL
UNION ALL
SELECT null, 'test2', 'date', 93, 'DATETIME', 24, 8, null, null,
SELECT null, 'test2', 'date', 93, 'DATETIME', 29, 8, null, null,
1, -- columnNullable
null, null, 9, 3, null, 1, 'YES', null, null, null, null, 'NO', 'NO'
FROM DUAL
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,12 @@ public enum DataType {
OBJECT( "object", JDBCType.STRUCT, -1, 0, 0, false, false, false),
NESTED( "nested", JDBCType.STRUCT, -1, 0, 0, false, false, false),
BINARY( "binary", JDBCType.VARBINARY, -1, Integer.MAX_VALUE, Integer.MAX_VALUE, false, false, false),
DATE( JDBCType.DATE, Long.BYTES, 24, 24, false, false, true),
TIME( JDBCType.TIME, Long.BYTES, 3, 18, false, false, true),
// since ODBC and JDBC interpret precision for Date as display size
// the precision is 23 (number of chars in ISO8601 with millis) + Z (the UTC timezone)
// the precision is 23 (number of chars in ISO8601 with millis) + 6 chars for the timezone (e.g.: +05:00)
// see https://github.com/elastic/elasticsearch/issues/30386#issuecomment-386807288
DATETIME( "date", JDBCType.TIMESTAMP, Long.BYTES, 3, 24, false, false, true),
DATE( JDBCType.DATE, Long.BYTES, 3, 29, false, false, true),
TIME( JDBCType.TIME, Long.BYTES, 3, 18, false, false, true),
DATETIME( "date", JDBCType.TIMESTAMP, Long.BYTES, 3, 29, false, false, true),
//
// specialized types
//
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public void testSysColumns() {
assertEquals("date", name(row));
assertEquals(Types.TIMESTAMP, sqlType(row));
assertEquals(null, radix(row));
assertEquals(24, precision(row));
assertEquals(29, precision(row));
assertEquals(8, bufferLength(row));

row = rows.get(5);
Expand Down Expand Up @@ -173,7 +173,7 @@ public void testSysColumnsInOdbcMode() {
assertEquals("date", name(row));
assertEquals((short) Types.TIMESTAMP, sqlType(row));
assertEquals(null, radix(row));
assertEquals(24, precision(row));
assertEquals(29, precision(row));
assertEquals(8, bufferLength(row));
assertNull(decimalPrecision(row));
assertEquals(Short.class, nullable(row).getClass());
Expand Down Expand Up @@ -308,7 +308,7 @@ public void testSysColumnsInJdbcMode() {
assertEquals("date", name(row));
assertEquals(Types.TIMESTAMP, sqlType(row));
assertEquals(null, radix(row));
assertEquals(24, precision(row));
assertEquals(29, precision(row));
assertEquals(8, bufferLength(row));
assertNull(decimalPrecision(row));
assertEquals(Integer.class, nullable(row).getClass());
Expand Down Expand Up @@ -431,4 +431,4 @@ private static Object sqlDataType(List<?> list) {
private static Object sqlDataTypeSub(List<?> list) {
return list.get(14);
}
}
}