Skip to content

Commit 2e3f9d5

Browse files
committed
Implement remaining TODOs from TIMESTAMP semantic fix
Fixes #37
1 parent 262c6ec commit 2e3f9d5

File tree

3 files changed

+35
-21
lines changed

3 files changed

+35
-21
lines changed

client/trino-jdbc/src/test/java/io/trino/jdbc/BaseTestJdbcResultSet.java

+21-10
Original file line numberDiff line numberDiff line change
@@ -349,11 +349,17 @@ public void testTime()
349349
.hasMessage("Expected column to be a timestamp type but is time(3)");
350350
});
351351

352-
// TODO https://github.com/trinodb/trino/issues/37
353-
// TODO line 1:8: '00:39:05' is not a valid time literal
354-
// checkRepresentation(statementWrapper.getStatement(), "TIME '00:39:05'", Types.TIME, (rs, column) -> {
355-
// ...
356-
// });
352+
checkRepresentation(connectedStatement.getStatement(), "TIME '00:39:05'", Types.TIME, (rs, column) -> {
353+
assertEquals(rs.getObject(column), toSqlTime(LocalTime.of(0, 39, 5)));
354+
assertEquals(rs.getObject(column, Time.class), toSqlTime(LocalTime.of(0, 39, 5)));
355+
assertThatThrownBy(() -> rs.getDate(column))
356+
.isInstanceOf(SQLException.class)
357+
.hasMessage("Expected value to be a date but is: 00:39:05");
358+
assertEquals(rs.getTime(column), Time.valueOf(LocalTime.of(0, 39, 5)));
359+
assertThatThrownBy(() -> rs.getTimestamp(column))
360+
.isInstanceOf(IllegalArgumentException.class) // TODO (https://github.com/trinodb/trino/issues/5315) SQLException
361+
.hasMessage("Expected column to be a timestamp type but is time(0)");
362+
});
357363

358364
// second fraction could be overflowing to next millisecond
359365
checkRepresentation(connectedStatement.getStatement(), "TIME '10:11:12.1235'", Types.TIME, (rs, column) -> {
@@ -573,11 +579,16 @@ public void testTimestamp()
573579
assertEquals(rs.getTimestamp(column), Timestamp.valueOf(LocalDateTime.of(1583, 1, 1, 0, 0, 0)));
574580
});
575581

576-
// TODO https://github.com/trinodb/trino/issues/37
577-
// TODO line 1:8: '1970-01-01 00:14:15.123' is not a valid timestamp literal; the expected values will pro
578-
// checkRepresentation(statementWrapper.getStatement(), "TIMESTAMP '1970-01-01 00:14:15.123'", Types.TIMESTAMP, (rs, column) -> {
579-
// ...
580-
// });
582+
checkRepresentation(connectedStatement.getStatement(), "TIMESTAMP '1970-01-01 00:14:15.123'", Types.TIMESTAMP, (rs, column) -> {
583+
assertEquals(rs.getObject(column), Timestamp.valueOf(LocalDateTime.of(1970, 1, 1, 0, 14, 15, 123_000_000)));
584+
assertThatThrownBy(() -> rs.getDate(column))
585+
.isInstanceOf(SQLException.class)
586+
.hasMessage("Expected value to be a date but is: 1970-01-01 00:14:15.123");
587+
assertThatThrownBy(() -> rs.getTime(column))
588+
.isInstanceOf(IllegalArgumentException.class) // TODO (https://github.com/trinodb/trino/issues/5315) SQLException
589+
.hasMessage("Expected column to be a time type but is timestamp(3)");
590+
assertEquals(rs.getTimestamp(column), Timestamp.valueOf(LocalDateTime.of(1970, 1, 1, 0, 14, 15, 123_000_000)));
591+
});
581592

582593
checkRepresentation(connectedStatement.getStatement(), "TIMESTAMP '123456-01-23 01:23:45.123456789'", Types.TIMESTAMP, (rs, column) -> {
583594
assertEquals(rs.getObject(column), Timestamp.valueOf(LocalDateTime.of(123456, 1, 23, 1, 23, 45, 123_456_789)));

plugin/trino-hive/src/main/java/io/trino/plugin/hive/s3select/S3SelectPushdown.java

+3-4
Original file line numberDiff line numberDiff line change
@@ -61,10 +61,9 @@ public final class S3SelectPushdown
6161
/*
6262
* Double and Real Types lose precision. Thus, they are not pushed down to S3. Please use Decimal Type if push down is desired.
6363
*
64-
* Pushing down timestamp to s3select is problematic due to following reasons:
65-
* 1) Presto bug: TIMESTAMP behaviour does not match sql standard (https://github.com/trinodb/trino/issues/37)
66-
* 2) Presto uses the timezone from client to convert the timestamp if no timezone is provided, however, s3select is a different service and this could lead to unexpected results.
67-
* 3) ION SQL compare timestamps using precision, timestamps with different precisions are not equal even actually they present the same instant of time. This could lead to unexpected results.
64+
* When S3 select support was added, Trino did not properly implement TIMESTAMP semantic. This was fixed in 2020, and TIMESTAMPS may be supportable now
65+
* (https://github.com/trinodb/trino/issues/10962). Pushing down timestamps to s3select maybe still be problematic due to ION SQL comparing timestamps
66+
* using precision. This means timestamps with different precisions are not equal even actually they present the same instant of time.
6867
*/
6968
private static final Set<String> SUPPORTED_COLUMN_TYPES = ImmutableSet.of(
7069
BOOLEAN_TYPE_NAME,

testing/trino-tests/src/test/java/io/trino/tests/AbstractTestEngineOnlyQueries.java

+11-7
Original file line numberDiff line numberDiff line change
@@ -147,13 +147,16 @@ public void testDateLiterals()
147147
@Test
148148
public void testTimeLiterals()
149149
{
150+
Session chicago = Session.builder(getSession()).setTimeZoneKey(TimeZoneKey.getTimeZoneKey("America/Chicago")).build();
151+
Session kathmandu = Session.builder(getSession()).setTimeZoneKey(TimeZoneKey.getTimeZoneKey("Asia/Kathmandu")).build();
152+
150153
assertEquals(computeScalar("SELECT TIME '3:04:05'"), LocalTime.of(3, 4, 5, 0));
151154
assertEquals(computeScalar("SELECT TIME '3:04:05.123'"), LocalTime.of(3, 4, 5, 123_000_000));
152155
assertQuery("SELECT TIME '3:04:05'");
153156
assertQuery("SELECT TIME '0:04:05'");
154-
// TODO https://github.com/trinodb/trino/issues/37
155-
// TODO assertQuery(chicago, "SELECT TIME '3:04:05'");
156-
// TODO assertQuery(kathmandu, "SELECT TIME '3:04:05'");
157+
158+
assertQuery(chicago, "SELECT TIME '3:04:05'");
159+
assertQuery(kathmandu, "SELECT TIME '3:04:05'");
157160
}
158161

159162
@Test
@@ -168,13 +171,15 @@ public void testTimeWithTimeZoneLiterals()
168171
@Test
169172
public void testTimestampLiterals()
170173
{
174+
Session chicago = Session.builder(getSession()).setTimeZoneKey(TimeZoneKey.getTimeZoneKey("America/Chicago")).build();
175+
Session kathmandu = Session.builder(getSession()).setTimeZoneKey(TimeZoneKey.getTimeZoneKey("Asia/Kathmandu")).build();
176+
171177
assertEquals(computeScalar("SELECT TIMESTAMP '1960-01-22 3:04:05'"), LocalDateTime.of(1960, 1, 22, 3, 4, 5));
172178
assertEquals(computeScalar("SELECT TIMESTAMP '1960-01-22 3:04:05.123'"), LocalDateTime.of(1960, 1, 22, 3, 4, 5, 123_000_000));
173179
assertQuery("SELECT TIMESTAMP '1960-01-22 3:04:05'");
174180
assertQuery("SELECT TIMESTAMP '1960-01-22 3:04:05.123'");
175-
// TODO https://github.com/trinodb/trino/issues/37
176-
// TODO assertQuery(chicago, "SELECT TIMESTAMP '1960-01-22 3:04:05.123'");
177-
// TODO assertQuery(kathmandu, "SELECT TIMESTAMP '1960-01-22 3:04:05.123'");
181+
assertQuery(chicago, "SELECT TIMESTAMP '1960-01-22 3:04:05.123'");
182+
assertQuery(kathmandu, "SELECT TIMESTAMP '1960-01-22 3:04:05.123'");
178183
}
179184

180185
@Test
@@ -577,7 +582,6 @@ public void testAssignUniqueId()
577582
@Test
578583
public void testAtTimeZone()
579584
{
580-
// TODO the expected values here are non-sensical due to https://github.com/trinodb/trino/issues/37
581585
assertEquals(computeScalar("SELECT TIMESTAMP '2012-10-31 01:00' AT TIME ZONE INTERVAL '07:09' hour to minute"), zonedDateTime("2012-10-30 18:09:00.000 +07:09"));
582586
assertEquals(computeScalar("SELECT TIMESTAMP '2012-10-31 01:00' AT TIME ZONE 'Asia/Oral'"), zonedDateTime("2012-10-30 16:00:00.000 Asia/Oral"));
583587
assertEquals(computeScalar("SELECT MIN(x) AT TIME ZONE 'America/Chicago' FROM (VALUES TIMESTAMP '1970-01-01 00:01:00+00:00') t(x)"), zonedDateTime("1969-12-31 18:01:00.000 America/Chicago"));

0 commit comments

Comments
 (0)