SQL: Fix display size for DATE/DATETIME (#40669)

A full format for a DATETIME would be:
`2019-03-30T10:20:30.123+10:00` which is 29 chars long.

For DATE a full format would be: `2019-03-30T00:00:00.000+10:00`
which is also 29 chars long.


(cherry picked from commit 6be83964ed025528778bca8d35692762e166983b)
This commit is contained in:
Marios Trivyzas 2019-04-03 13:28:30 +02:00
parent 1d2bc85586
commit 952c4d9653
No known key found for this signature in database
GPG Key ID: 8817B46B0CF36A3F
6 changed files with 20 additions and 16 deletions

View File

@ -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`

View File

@ -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
@ -66,7 +66,7 @@ s|SQL type
s|SQL precision
| date | 24
| date | 29
| time | 18
| interval_year | 7
| interval_month | 7

View File

@ -67,16 +67,16 @@ public abstract class SqlProtocolTestCase extends ESRestTestCase {
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);

View File

@ -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

View File

@ -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
//

View File

@ -50,7 +50,7 @@ public class SysColumnsTests extends ESTestCase {
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);
@ -173,7 +173,7 @@ public class SysColumnsTests extends ESTestCase {
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());
@ -308,7 +308,7 @@ public class SysColumnsTests extends ESTestCase {
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());