From 03418ceaa8f659dfd0eb4aa73b659166b38bff0a Mon Sep 17 00:00:00 2001 From: Piotr Findeisen Date: Thu, 26 Jul 2018 14:32:31 +0200 Subject: [PATCH 1/6] Upgrade Presto hive-apache to 1.2.2-2 This includes a change that prevents failure when JVM zone had change on 1970-01-01. --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 7adace2e9c29..e39b2d958901 100644 --- a/pom.xml +++ b/pom.xml @@ -400,7 +400,7 @@ com.facebook.presto.hive hive-apache - 1.2.0-2 + 1.2.2-2 From 09de4976dbe377237ceeca52f7a4d3351426dd74 Mon Sep 17 00:00:00 2001 From: Piotr Findeisen Date: Thu, 26 Jul 2018 14:32:32 +0200 Subject: [PATCH 2/6] Change JVM time zone in tests to better test corner cases See https://github.com/prestodb/presto/issues/10078 for discussion. --- pom.xml | 10 ++++++++-- .../java/com/facebook/presto/hive/HiveQueryRunner.java | 4 ++-- .../com/facebook/presto/hive/TestHiveFileFormats.java | 6 +++--- .../facebook/presto/hive/parquet/ParquetTester.java | 2 +- .../com/facebook/presto/jdbc/TestJdbcResultSet.java | 8 ++++---- presto-mysql/pom.xml | 8 -------- .../test/java/com/facebook/presto/orc/OrcTester.java | 2 +- presto-postgresql/pom.xml | 8 -------- .../java/com/facebook/presto/rcfile/RcFileTester.java | 2 +- .../presto/tests/AbstractTestEngineOnlyQueries.java | 4 ++-- .../com/facebook/presto/tests/TestH2QueryRunner.java | 2 +- 11 files changed, 23 insertions(+), 33 deletions(-) diff --git a/pom.xml b/pom.xml index e39b2d958901..299a7ef318c3 100644 --- a/pom.xml +++ b/pom.xml @@ -55,8 +55,14 @@ 6.10 3.8.0 - - Asia/Katmandu + + America/Bahia_Banderas methods 2 2g diff --git a/presto-hive/src/test/java/com/facebook/presto/hive/HiveQueryRunner.java b/presto-hive/src/test/java/com/facebook/presto/hive/HiveQueryRunner.java index 0c9e45d4bb5b..36c96fc8c132 100644 --- a/presto-hive/src/test/java/com/facebook/presto/hive/HiveQueryRunner.java +++ b/presto-hive/src/test/java/com/facebook/presto/hive/HiveQueryRunner.java @@ -54,7 +54,7 @@ private HiveQueryRunner() public static final String HIVE_BUCKETED_CATALOG = "hive_bucketed"; public static final String TPCH_SCHEMA = "tpch"; private static final String TPCH_BUCKETED_SCHEMA = "tpch_bucketed"; - private static final DateTimeZone TIME_ZONE = DateTimeZone.forID("Asia/Kathmandu"); + private static final DateTimeZone TIME_ZONE = DateTimeZone.forID("America/Bahia_Banderas"); public static DistributedQueryRunner createQueryRunner(TpchTable... tables) throws Exception @@ -77,7 +77,7 @@ public static DistributedQueryRunner createQueryRunner(Iterable> ta public static DistributedQueryRunner createQueryRunner(Iterable> tables, Map extraProperties, String security, Map extraHiveProperties) throws Exception { - assertEquals(DateTimeZone.getDefault(), TIME_ZONE, "Timezone not configured correctly. Add -Duser.timezone=Asia/Katmandu to your JVM arguments"); + assertEquals(DateTimeZone.getDefault(), TIME_ZONE, "Timezone not configured correctly. Add -Duser.timezone=America/Bahia_Banderas to your JVM arguments"); DistributedQueryRunner queryRunner = new DistributedQueryRunner(createSession(), 4, extraProperties); diff --git a/presto-hive/src/test/java/com/facebook/presto/hive/TestHiveFileFormats.java b/presto-hive/src/test/java/com/facebook/presto/hive/TestHiveFileFormats.java index ae28f77635ea..3d1eaa859ef2 100644 --- a/presto-hive/src/test/java/com/facebook/presto/hive/TestHiveFileFormats.java +++ b/presto-hive/src/test/java/com/facebook/presto/hive/TestHiveFileFormats.java @@ -92,7 +92,7 @@ public class TestHiveFileFormats private static TestingConnectorSession parquetPageSourceSession = new TestingConnectorSession(new HiveSessionProperties(createParquetHiveClientConfig(false), new OrcFileWriterConfig(), new ParquetFileWriterConfig()).getSessionProperties()); private static TestingConnectorSession parquetPageSourceSessionUseName = new TestingConnectorSession(new HiveSessionProperties(createParquetHiveClientConfig(true), new OrcFileWriterConfig(), new ParquetFileWriterConfig()).getSessionProperties()); - private static final DateTimeZone HIVE_STORAGE_TIME_ZONE = DateTimeZone.forID("Asia/Katmandu"); + private static final DateTimeZone HIVE_STORAGE_TIME_ZONE = DateTimeZone.forID("America/Bahia_Banderas"); @DataProvider(name = "rowCount") public static Object[][] rowCountProvider() @@ -105,8 +105,8 @@ public void setUp() { // ensure the expected timezone is configured for this VM assertEquals(TimeZone.getDefault().getID(), - "Asia/Katmandu", - "Timezone not configured correctly. Add -Duser.timezone=Asia/Katmandu to your JVM arguments"); + "America/Bahia_Banderas", + "Timezone not configured correctly. Add -Duser.timezone=America/Bahia_Banderas to your JVM arguments"); } @Test(dataProvider = "rowCount") diff --git a/presto-hive/src/test/java/com/facebook/presto/hive/parquet/ParquetTester.java b/presto-hive/src/test/java/com/facebook/presto/hive/parquet/ParquetTester.java index ff69635d1eee..92011928657e 100644 --- a/presto-hive/src/test/java/com/facebook/presto/hive/parquet/ParquetTester.java +++ b/presto-hive/src/test/java/com/facebook/presto/hive/parquet/ParquetTester.java @@ -110,7 +110,7 @@ public class ParquetTester { - public static final DateTimeZone HIVE_STORAGE_TIME_ZONE = DateTimeZone.forID("Asia/Katmandu"); + public static final DateTimeZone HIVE_STORAGE_TIME_ZONE = DateTimeZone.forID("America/Bahia_Banderas"); private static final boolean OPTIMIZED = true; private static final HiveClientConfig HIVE_CLIENT_CONFIG = createHiveClientConfig(false); private static final HdfsEnvironment HDFS_ENVIRONMENT = createTestHdfsEnvironment(HIVE_CLIENT_CONFIG); diff --git a/presto-jdbc/src/test/java/com/facebook/presto/jdbc/TestJdbcResultSet.java b/presto-jdbc/src/test/java/com/facebook/presto/jdbc/TestJdbcResultSet.java index 769fb8f5ad09..40e61aa9c6cd 100644 --- a/presto-jdbc/src/test/java/com/facebook/presto/jdbc/TestJdbcResultSet.java +++ b/presto-jdbc/src/test/java/com/facebook/presto/jdbc/TestJdbcResultSet.java @@ -132,9 +132,9 @@ public void testObjectTypes() }); checkRepresentation("TIME '09:39:07 +01:00'", Types.TIME /* TODO TIME_WITH_TIMEZONE */, (rs, column) -> { - assertEquals(rs.getObject(column), Time.valueOf(LocalTime.of(14, 9, 7))); // TODO this should represent TIME '09:39:07 +01:00' + assertEquals(rs.getObject(column), Time.valueOf(LocalTime.of(1, 39, 7))); // TODO this should represent TIME '09:39:07 +01:00' assertThrows(() -> rs.getDate(column)); - assertEquals(rs.getTime(column), Time.valueOf(LocalTime.of(14, 9, 7))); // TODO this should fail, or represent TIME '09:39:07 +01:00' + assertEquals(rs.getTime(column), Time.valueOf(LocalTime.of(1, 39, 7))); // TODO this should fail, or represent TIME '09:39:07 +01:00' assertThrows(() -> rs.getTimestamp(column)); }); @@ -146,10 +146,10 @@ public void testObjectTypes() }); checkRepresentation("TIMESTAMP '2018-02-13 13:14:15.227 Europe/Warsaw'", Types.TIMESTAMP /* TODO TIMESTAMP_WITH_TIMEZONE */, (rs, column) -> { - assertEquals(rs.getObject(column), Timestamp.valueOf(LocalDateTime.of(2018, 2, 13, 17, 59, 15, 227_000_000))); // TODO this should represent TIMESTAMP '2018-02-13 13:14:15.227 Europe/Warsaw' + assertEquals(rs.getObject(column), Timestamp.valueOf(LocalDateTime.of(2018, 2, 13, 6, 14, 15, 227_000_000))); // TODO this should represent TIMESTAMP '2018-02-13 13:14:15.227 Europe/Warsaw' assertThrows(() -> rs.getDate(column)); assertThrows(() -> rs.getTime(column)); - assertEquals(rs.getTimestamp(column), Timestamp.valueOf(LocalDateTime.of(2018, 2, 13, 17, 59, 15, 227_000_000))); // TODO this should fail or represent TIMESTAMP '2018-02-13 13:14:15.227 Europe/Warsaw' + assertEquals(rs.getTimestamp(column), Timestamp.valueOf(LocalDateTime.of(2018, 2, 13, 6, 14, 15, 227_000_000))); // TODO this should fail or represent TIMESTAMP '2018-02-13 13:14:15.227 Europe/Warsaw' }); } diff --git a/presto-mysql/pom.xml b/presto-mysql/pom.xml index 851f9c84cb5b..d455353d6add 100644 --- a/presto-mysql/pom.xml +++ b/presto-mysql/pom.xml @@ -14,14 +14,6 @@ ${project.parent.basedir} - - America/Bahia_Banderas diff --git a/presto-orc/src/test/java/com/facebook/presto/orc/OrcTester.java b/presto-orc/src/test/java/com/facebook/presto/orc/OrcTester.java index b4bde0dda928..0936fbd7e2a3 100644 --- a/presto-orc/src/test/java/com/facebook/presto/orc/OrcTester.java +++ b/presto-orc/src/test/java/com/facebook/presto/orc/OrcTester.java @@ -170,7 +170,7 @@ public class OrcTester { public static final DataSize MAX_BLOCK_SIZE = new DataSize(1, Unit.MEGABYTE); - public static final DateTimeZone HIVE_STORAGE_TIME_ZONE = DateTimeZone.forID("Asia/Katmandu"); + public static final DateTimeZone HIVE_STORAGE_TIME_ZONE = DateTimeZone.forID("America/Bahia_Banderas"); private static final TypeManager TYPE_MANAGER = new TypeRegistry(); diff --git a/presto-postgresql/pom.xml b/presto-postgresql/pom.xml index 05470965e392..c4b57822a76e 100644 --- a/presto-postgresql/pom.xml +++ b/presto-postgresql/pom.xml @@ -14,14 +14,6 @@ ${project.parent.basedir} - - America/Bahia_Banderas diff --git a/presto-rcfile/src/test/java/com/facebook/presto/rcfile/RcFileTester.java b/presto-rcfile/src/test/java/com/facebook/presto/rcfile/RcFileTester.java index ee7771b7fbcb..bf4bc506b180 100644 --- a/presto-rcfile/src/test/java/com/facebook/presto/rcfile/RcFileTester.java +++ b/presto-rcfile/src/test/java/com/facebook/presto/rcfile/RcFileTester.java @@ -197,7 +197,7 @@ public class RcFileTester HadoopNative.requireHadoopNative(); } - public static final DateTimeZone HIVE_STORAGE_TIME_ZONE = DateTimeZone.forID("Asia/Katmandu"); + public static final DateTimeZone HIVE_STORAGE_TIME_ZONE = DateTimeZone.forID("America/Bahia_Banderas"); public enum Format { diff --git a/presto-tests/src/test/java/com/facebook/presto/tests/AbstractTestEngineOnlyQueries.java b/presto-tests/src/test/java/com/facebook/presto/tests/AbstractTestEngineOnlyQueries.java index 24bcc48113be..4fe70bb1ce86 100644 --- a/presto-tests/src/test/java/com/facebook/presto/tests/AbstractTestEngineOnlyQueries.java +++ b/presto-tests/src/test/java/com/facebook/presto/tests/AbstractTestEngineOnlyQueries.java @@ -75,14 +75,14 @@ public void testTimeLiterals() @Test public void testLocallyUnrepresentableTimeLiterals() { - LocalDateTime localTimeThatDidNotExist = LocalDateTime.of(1986, 1, 1, 0, 10); + LocalDateTime localTimeThatDidNotExist = LocalDateTime.of(2017, 4, 2, 2, 10); checkState(ZoneId.systemDefault().getRules().getValidOffsets(localTimeThatDidNotExist).isEmpty(), "This test assumes certain JVM time zone"); // This tests that both Presto runner and H2 can return TIMESTAMP value that never happened in JVM's zone (e.g. is not representable using java.sql.Timestamp) @Language("SQL") String sql = DateTimeFormatter.ofPattern("'SELECT TIMESTAMP '''uuuu-MM-dd HH:mm:ss''").format(localTimeThatDidNotExist); assertEquals(computeScalar(sql), localTimeThatDidNotExist); // this tests Presto and the QueryRunner assertQuery(sql); // this tests H2QueryRunner - LocalDate localDateThatDidNotHaveMidnight = LocalDate.of(1986, 1, 1); + LocalDate localDateThatDidNotHaveMidnight = LocalDate.of(1970, 1, 1); checkState(ZoneId.systemDefault().getRules().getValidOffsets(localDateThatDidNotHaveMidnight.atStartOfDay()).isEmpty(), "This test assumes certain JVM time zone"); // This tests that both Presto runner and H2 can return DATE value for a day which midnight never happened in JVM's zone (e.g. is not exactly representable using java.sql.Date) sql = DateTimeFormatter.ofPattern("'SELECT DATE '''uuuu-MM-dd''").format(localDateThatDidNotHaveMidnight); diff --git a/presto-tests/src/test/java/com/facebook/presto/tests/TestH2QueryRunner.java b/presto-tests/src/test/java/com/facebook/presto/tests/TestH2QueryRunner.java index 50cdec4d0942..678450c66d62 100644 --- a/presto-tests/src/test/java/com/facebook/presto/tests/TestH2QueryRunner.java +++ b/presto-tests/src/test/java/com/facebook/presto/tests/TestH2QueryRunner.java @@ -55,7 +55,7 @@ public void testDateToTimestampCoercion() assertEquals(rows.getOnlyValue(), LocalDate.of(2018, 1, 13).atStartOfDay()); // date, which midnight was skipped in JVM zone - LocalDate forwardOffsetChangeAtMidnightInJvmZone = LocalDate.of(1986, 1, 1); + LocalDate forwardOffsetChangeAtMidnightInJvmZone = LocalDate.of(1970, 1, 1); checkState(ZoneId.systemDefault().getRules().getValidOffsets(forwardOffsetChangeAtMidnightInJvmZone.atStartOfDay()).size() == 0, "This test assumes certain JVM time zone"); rows = h2QueryRunner.execute(TEST_SESSION, DateTimeFormatter.ofPattern("'SELECT DATE '''uuuu-MM-dd''").format(forwardOffsetChangeAtMidnightInJvmZone), ImmutableList.of(TIMESTAMP)); assertEquals(rows.getOnlyValue(), forwardOffsetChangeAtMidnightInJvmZone.atStartOfDay()); From d2df42a8a00ae6acfb214314ed3e2ad61e749811 Mon Sep 17 00:00:00 2001 From: Piotr Findeisen Date: Thu, 26 Jul 2018 14:32:33 +0200 Subject: [PATCH 3/6] Clarify expected behavior after representation fixed in JDBC --- .../test/java/com/facebook/presto/jdbc/TestJdbcResultSet.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/presto-jdbc/src/test/java/com/facebook/presto/jdbc/TestJdbcResultSet.java b/presto-jdbc/src/test/java/com/facebook/presto/jdbc/TestJdbcResultSet.java index 40e61aa9c6cd..ce41b514e5f9 100644 --- a/presto-jdbc/src/test/java/com/facebook/presto/jdbc/TestJdbcResultSet.java +++ b/presto-jdbc/src/test/java/com/facebook/presto/jdbc/TestJdbcResultSet.java @@ -134,7 +134,7 @@ public void testObjectTypes() checkRepresentation("TIME '09:39:07 +01:00'", Types.TIME /* TODO TIME_WITH_TIMEZONE */, (rs, column) -> { assertEquals(rs.getObject(column), Time.valueOf(LocalTime.of(1, 39, 7))); // TODO this should represent TIME '09:39:07 +01:00' assertThrows(() -> rs.getDate(column)); - assertEquals(rs.getTime(column), Time.valueOf(LocalTime.of(1, 39, 7))); // TODO this should fail, or represent TIME '09:39:07 +01:00' + assertEquals(rs.getTime(column), Time.valueOf(LocalTime.of(1, 39, 7))); // TODO this should fail, or represent TIME '09:39:07' assertThrows(() -> rs.getTimestamp(column)); }); @@ -149,7 +149,7 @@ public void testObjectTypes() assertEquals(rs.getObject(column), Timestamp.valueOf(LocalDateTime.of(2018, 2, 13, 6, 14, 15, 227_000_000))); // TODO this should represent TIMESTAMP '2018-02-13 13:14:15.227 Europe/Warsaw' assertThrows(() -> rs.getDate(column)); assertThrows(() -> rs.getTime(column)); - assertEquals(rs.getTimestamp(column), Timestamp.valueOf(LocalDateTime.of(2018, 2, 13, 6, 14, 15, 227_000_000))); // TODO this should fail or represent TIMESTAMP '2018-02-13 13:14:15.227 Europe/Warsaw' + assertEquals(rs.getTimestamp(column), Timestamp.valueOf(LocalDateTime.of(2018, 2, 13, 6, 14, 15, 227_000_000))); // TODO this should fail, or represent TIMESTAMP '2018-02-13 13:14:15.227' }); } From c8be026b55eb5e0e51507f04bea08639f73fd393 Mon Sep 17 00:00:00 2001 From: Piotr Findeisen Date: Thu, 26 Jul 2018 14:32:34 +0200 Subject: [PATCH 4/6] Add more DATE/TIME related tests --- .../presto/jdbc/TestJdbcResultSet.java | 51 +++++++++++++++++++ .../tests/AbstractTestEngineOnlyQueries.java | 8 +++ 2 files changed, 59 insertions(+) diff --git a/presto-jdbc/src/test/java/com/facebook/presto/jdbc/TestJdbcResultSet.java b/presto-jdbc/src/test/java/com/facebook/presto/jdbc/TestJdbcResultSet.java index ce41b514e5f9..984f7111b21f 100644 --- a/presto-jdbc/src/test/java/com/facebook/presto/jdbc/TestJdbcResultSet.java +++ b/presto-jdbc/src/test/java/com/facebook/presto/jdbc/TestJdbcResultSet.java @@ -38,6 +38,8 @@ import static com.facebook.presto.jdbc.TestPrestoDriver.closeQuietly; import static java.lang.String.format; +import static java.util.concurrent.TimeUnit.DAYS; +import static java.util.concurrent.TimeUnit.HOURS; import static org.testng.Assert.assertEquals; import static org.testng.Assert.assertFalse; import static org.testng.Assert.assertNotNull; @@ -131,6 +133,11 @@ public void testObjectTypes() assertThrows(() -> rs.getTimestamp(column)); }); + // TODO #7122: line 1:8: '00:39:05' is not a valid time literal +// checkRepresentation("TIME '00:39:05'", Types.TIME, (rs, column) -> { +// ... +// }); + checkRepresentation("TIME '09:39:07 +01:00'", Types.TIME /* TODO TIME_WITH_TIMEZONE */, (rs, column) -> { assertEquals(rs.getObject(column), Time.valueOf(LocalTime.of(1, 39, 7))); // TODO this should represent TIME '09:39:07 +01:00' assertThrows(() -> rs.getDate(column)); @@ -138,6 +145,30 @@ public void testObjectTypes() assertThrows(() -> rs.getTimestamp(column)); }); + checkRepresentation("TIME '01:39:07 +01:00'", Types.TIME /* TODO TIME_WITH_TIMEZONE */, (rs, column) -> { + Time someBogusValue = new Time( + Time.valueOf( + LocalTime.of(16, 39, 7)).getTime() /* 16:39:07 = 01:39:07 - +01:00 shift + Bahia_Banderas's shift (-8) (modulo 24h which we "un-modulo" below) */ + - DAYS.toMillis(1) /* because we use currently 'shifted' representation, not possible to create just using LocalTime */ + + HOURS.toMillis(1) /* because there was offset shift on 1970-01-01 in America/Bahia_Banderas */); + assertEquals(rs.getObject(column), someBogusValue); // TODO this should represent TIME '01:39:07 +01:00' + assertThrows(() -> rs.getDate(column)); + assertEquals(rs.getTime(column), someBogusValue); // TODO this should fail, or represent TIME '01:39:07' + assertThrows(() -> rs.getTimestamp(column)); + }); + + checkRepresentation("TIME '00:39:07 +01:00'", Types.TIME /* TODO TIME_WITH_TIMEZONE */, (rs, column) -> { + Time someBogusValue = new Time( + Time.valueOf( + LocalTime.of(15, 39, 7)).getTime() /* 15:39:07 = 00:39:07 - +01:00 shift + Bahia_Banderas's shift (-8) (modulo 24h which we "un-modulo" below) */ + - DAYS.toMillis(1) /* because we use currently 'shifted' representation, not possible to create just using LocalTime */ + + HOURS.toMillis(1) /* because there was offset shift on 1970-01-01 in America/Bahia_Banderas */); + assertEquals(rs.getObject(column), someBogusValue); // TODO this should represent TIME '00:39:07 +01:00' + assertThrows(() -> rs.getDate(column)); + assertEquals(rs.getTime(column), someBogusValue); // TODO this should fail, as there no java.sql.Time representation for TIME '00:39:07' in America/Bahia_Banderas + assertThrows(() -> rs.getTimestamp(column)); + }); + checkRepresentation("TIMESTAMP '2018-02-13 13:14:15.123'", Types.TIMESTAMP, (rs, column) -> { assertEquals(rs.getObject(column), Timestamp.valueOf(LocalDateTime.of(2018, 2, 13, 13, 14, 15, 123_000_000))); assertThrows(() -> rs.getDate(column)); @@ -145,12 +176,32 @@ public void testObjectTypes() assertEquals(rs.getTimestamp(column), Timestamp.valueOf(LocalDateTime.of(2018, 2, 13, 13, 14, 15, 123_000_000))); }); + // TODO #7122: line 1:8: '1970-01-01 00:14:15.123' is not a valid timestamp literal; the expected values will pro +// checkRepresentation("TIMESTAMP '1970-01-01 00:14:15.123'", Types.TIMESTAMP, (rs, column) -> { +// ... +// }); + checkRepresentation("TIMESTAMP '2018-02-13 13:14:15.227 Europe/Warsaw'", Types.TIMESTAMP /* TODO TIMESTAMP_WITH_TIMEZONE */, (rs, column) -> { assertEquals(rs.getObject(column), Timestamp.valueOf(LocalDateTime.of(2018, 2, 13, 6, 14, 15, 227_000_000))); // TODO this should represent TIMESTAMP '2018-02-13 13:14:15.227 Europe/Warsaw' assertThrows(() -> rs.getDate(column)); assertThrows(() -> rs.getTime(column)); assertEquals(rs.getTimestamp(column), Timestamp.valueOf(LocalDateTime.of(2018, 2, 13, 6, 14, 15, 227_000_000))); // TODO this should fail, or represent TIMESTAMP '2018-02-13 13:14:15.227' }); + + checkRepresentation("TIMESTAMP '1970-01-01 09:14:15.227 Europe/Warsaw'", Types.TIMESTAMP /* TODO TIMESTAMP_WITH_TIMEZONE */, (rs, column) -> { + assertEquals(rs.getObject(column), Timestamp.valueOf(LocalDateTime.of(1970, 1, 1, 1, 14, 15, 227_000_000))); // TODO this should represent TIMESTAMP '1970-01-01 09:14:15.227 Europe/Warsaw' + assertThrows(() -> rs.getDate(column)); + assertThrows(() -> rs.getTime(column)); + assertEquals(rs.getTimestamp(column), Timestamp.valueOf(LocalDateTime.of(1970, 1, 1, 1, 14, 15, 227_000_000))); // TODO this should fail, or represent TIMESTAMP '1970-01-01 09:14:15.227' + }); + + checkRepresentation("TIMESTAMP '1970-01-01 00:14:15.227 Europe/Warsaw'", Types.TIMESTAMP /* TODO TIMESTAMP_WITH_TIMEZONE */, (rs, column) -> { + assertEquals(rs.getObject(column), Timestamp.valueOf(LocalDateTime.of(1969, 12, 31, 15, 14, 15, 227_000_000))); // TODO this should represent TIMESTAMP '1970-01-01 00:14:15.227 Europe/Warsaw' + assertThrows(() -> rs.getDate(column)); + assertThrows(() -> rs.getTime(column)); + // TODO this should fail, as there no java.sql.Timestamp representation for TIMESTAMP '1970-01-01 00:14:15.227ó' in America/Bahia_Banderas + assertEquals(rs.getTimestamp(column), Timestamp.valueOf(LocalDateTime.of(1969, 12, 31, 15, 14, 15, 227_000_000))); + }); } private void checkRepresentation(String expression, int expectedSqlType, Object expectedRepresentation) diff --git a/presto-tests/src/test/java/com/facebook/presto/tests/AbstractTestEngineOnlyQueries.java b/presto-tests/src/test/java/com/facebook/presto/tests/AbstractTestEngineOnlyQueries.java index 4fe70bb1ce86..2134c91f589d 100644 --- a/presto-tests/src/test/java/com/facebook/presto/tests/AbstractTestEngineOnlyQueries.java +++ b/presto-tests/src/test/java/com/facebook/presto/tests/AbstractTestEngineOnlyQueries.java @@ -26,6 +26,7 @@ import java.time.ZoneOffset; import java.time.ZonedDateTime; import java.time.format.DateTimeFormatter; +import java.util.Objects; import static com.google.common.base.Preconditions.checkState; import static org.testng.Assert.assertEquals; @@ -88,5 +89,12 @@ public void testLocallyUnrepresentableTimeLiterals() sql = DateTimeFormatter.ofPattern("'SELECT DATE '''uuuu-MM-dd''").format(localDateThatDidNotHaveMidnight); assertEquals(computeScalar(sql), localDateThatDidNotHaveMidnight); // this tests Presto and the QueryRunner assertQuery(sql); // this tests H2QueryRunner + + LocalTime localTimeThatDidNotOccurOn19700101 = LocalTime.of(0, 10); + checkState(ZoneId.systemDefault().getRules().getValidOffsets(localTimeThatDidNotOccurOn19700101.atDate(LocalDate.ofEpochDay(0))).isEmpty(), "This test assumes certain JVM time zone"); + checkState(!Objects.equals(java.sql.Time.valueOf(localTimeThatDidNotOccurOn19700101).toLocalTime(), localTimeThatDidNotOccurOn19700101), "This test assumes certain JVM time zone"); + sql = DateTimeFormatter.ofPattern("'SELECT TIME '''HH:mm:ss''").format(localTimeThatDidNotOccurOn19700101); + assertEquals(computeScalar(sql), localTimeThatDidNotOccurOn19700101); // this tests Presto and the QueryRunner + assertQuery(sql); // this tests H2QueryRunner } } From 96a8e246ac649b5a1b87b91871a0cf00bb9456c2 Mon Sep 17 00:00:00 2001 From: Piotr Findeisen Date: Thu, 26 Jul 2018 14:32:36 +0200 Subject: [PATCH 5/6] Simplify SqlTimestamp construction in tests --- .../presto/testing/DateTimeTestingUtils.java | 26 +++-- .../scalar/TestDateTimeFunctionsBase.java | 42 +++---- .../sql/gen/TestExpressionCompiler.java | 3 +- .../presto/type/TestArrayOperators.java | 110 +++++++++--------- .../facebook/presto/type/TestDateBase.java | 2 +- .../presto/type/TestDateTimeOperators.java | 30 ++--- .../type/TestDateTimeOperatorsBase.java | 22 ++-- .../type/TestDateTimeOperatorsLegacy.java | 30 ++--- .../presto/type/TestJsonOperators.java | 4 +- .../presto/type/TestMapOperators.java | 18 ++- .../presto/type/TestRowOperators.java | 4 +- .../facebook/presto/type/TestTimeBase.java | 2 +- .../presto/type/TestTimeWithTimeZone.java | 11 ++ .../presto/type/TestTimeWithTimeZoneBase.java | 9 +- .../type/TestTimeWithTimeZoneLegacy.java | 13 ++- .../presto/type/TestTimestampBase.java | 44 +++---- .../presto/type/TestTimestampLegacy.java | 40 +++++-- .../type/TestTimestampWithTimeZone.java | 17 +++ .../type/TestTimestampWithTimeZoneBase.java | 14 +-- .../type/TestTimestampWithTimeZoneLegacy.java | 18 ++- .../functions/TestTeradataDateFunctions.java | 5 +- 21 files changed, 262 insertions(+), 202 deletions(-) diff --git a/presto-main/src/main/java/com/facebook/presto/testing/DateTimeTestingUtils.java b/presto-main/src/main/java/com/facebook/presto/testing/DateTimeTestingUtils.java index 381ac7ff4727..414a7051af89 100644 --- a/presto-main/src/main/java/com/facebook/presto/testing/DateTimeTestingUtils.java +++ b/presto-main/src/main/java/com/facebook/presto/testing/DateTimeTestingUtils.java @@ -26,6 +26,7 @@ import java.time.LocalTime; import java.time.ZoneId; +import static com.facebook.presto.util.DateTimeZoneIndex.getDateTimeZone; import static java.lang.Math.toIntExact; import static java.time.ZoneOffset.UTC; import static java.util.concurrent.TimeUnit.DAYS; @@ -44,11 +45,19 @@ public static SqlTimestamp sqlTimestampOf( int minuteOfHour, int secondOfMinute, int millisOfSecond, - DateTimeZone baseZone, - TimeZoneKey timestampZone, Session session) { - return sqlTimestampOf(year, monthOfYear, dayOfMonth, hourOfDay, minuteOfHour, secondOfMinute, millisOfSecond, baseZone, timestampZone, session.toConnectorSession()); + return sqlTimestampOf( + year, + monthOfYear, + dayOfMonth, + hourOfDay, + minuteOfHour, + secondOfMinute, + millisOfSecond, + getDateTimeZone(session.getTimeZoneKey()), + session.getTimeZoneKey(), + session.toConnectorSession()); } public static SqlTimestamp sqlTimestampOf( @@ -66,9 +75,7 @@ public static SqlTimestamp sqlTimestampOf( if (session.isLegacyTimestamp()) { return new SqlTimestamp(new DateTime(year, monthOfYear, dayOfMonth, hourOfDay, minuteOfHour, secondOfMinute, millisOfSecond, baseZone).getMillis(), timestampZone); } - else { - return new SqlTimestamp(new DateTime(year, monthOfYear, dayOfMonth, hourOfDay, minuteOfHour, secondOfMinute, millisOfSecond, DateTimeZone.UTC).getMillis()); - } + return sqlTimestampOf(LocalDateTime.of(year, monthOfYear, dayOfMonth, hourOfDay, minuteOfHour, secondOfMinute, millisToNanos(millisOfSecond))); } /** @@ -106,7 +113,7 @@ public static SqlTime sqlTimeOf( int millisOfSecond, Session session) { - LocalTime time = LocalTime.of(hourOfDay, minuteOfHour, secondOfMinute, toIntExact(MILLISECONDS.toNanos(millisOfSecond))); + LocalTime time = LocalTime.of(hourOfDay, minuteOfHour, secondOfMinute, millisToNanos(millisOfSecond)); return sqlTimeOf(time, session); } @@ -123,4 +130,9 @@ public static SqlTime sqlTimeOf(LocalTime time, Session session) } return new SqlTime(NANOSECONDS.toMillis(time.toNanoOfDay())); } + + private static int millisToNanos(int millisOfSecond) + { + return toIntExact(MILLISECONDS.toNanos(millisOfSecond)); + } } diff --git a/presto-main/src/test/java/com/facebook/presto/operator/scalar/TestDateTimeFunctionsBase.java b/presto-main/src/test/java/com/facebook/presto/operator/scalar/TestDateTimeFunctionsBase.java index a0853674b696..1459e4697993 100644 --- a/presto-main/src/test/java/com/facebook/presto/operator/scalar/TestDateTimeFunctionsBase.java +++ b/presto-main/src/test/java/com/facebook/presto/operator/scalar/TestDateTimeFunctionsBase.java @@ -778,67 +778,67 @@ public void testDateParse() { assertFunction("date_parse('2013', '%Y')", TimestampType.TIMESTAMP, - sqlTimestampOf(2013, 1, 1, 0, 0, 0, 0, DATE_TIME_ZONE, TIME_ZONE_KEY, session)); + sqlTimestampOf(2013, 1, 1, 0, 0, 0, 0, session)); assertFunction("date_parse('2013-05', '%Y-%m')", TimestampType.TIMESTAMP, - sqlTimestampOf(2013, 5, 1, 0, 0, 0, 0, DATE_TIME_ZONE, TIME_ZONE_KEY, session)); + sqlTimestampOf(2013, 5, 1, 0, 0, 0, 0, session)); assertFunction("date_parse('2013-05-17', '%Y-%m-%d')", TimestampType.TIMESTAMP, - sqlTimestampOf(2013, 5, 17, 0, 0, 0, 0, DATE_TIME_ZONE, TIME_ZONE_KEY, session)); + sqlTimestampOf(2013, 5, 17, 0, 0, 0, 0, session)); assertFunction("date_parse('2013-05-17 12:35:10', '%Y-%m-%d %h:%i:%s')", TimestampType.TIMESTAMP, - sqlTimestampOf(2013, 5, 17, 0, 35, 10, 0, DATE_TIME_ZONE, TIME_ZONE_KEY, session)); + sqlTimestampOf(2013, 5, 17, 0, 35, 10, 0, session)); assertFunction("date_parse('2013-05-17 12:35:10 PM', '%Y-%m-%d %h:%i:%s %p')", TimestampType.TIMESTAMP, - sqlTimestampOf(2013, 5, 17, 12, 35, 10, 0, DATE_TIME_ZONE, TIME_ZONE_KEY, session)); + sqlTimestampOf(2013, 5, 17, 12, 35, 10, 0, session)); assertFunction("date_parse('2013-05-17 12:35:10 AM', '%Y-%m-%d %h:%i:%s %p')", TimestampType.TIMESTAMP, - sqlTimestampOf(2013, 5, 17, 0, 35, 10, 0, DATE_TIME_ZONE, TIME_ZONE_KEY, session)); + sqlTimestampOf(2013, 5, 17, 0, 35, 10, 0, session)); assertFunction("date_parse('2013-05-17 00:35:10', '%Y-%m-%d %H:%i:%s')", TimestampType.TIMESTAMP, - sqlTimestampOf(2013, 5, 17, 0, 35, 10, 0, DATE_TIME_ZONE, TIME_ZONE_KEY, session)); + sqlTimestampOf(2013, 5, 17, 0, 35, 10, 0, session)); assertFunction("date_parse('2013-05-17 23:35:10', '%Y-%m-%d %H:%i:%s')", TimestampType.TIMESTAMP, - sqlTimestampOf(2013, 5, 17, 23, 35, 10, 0, DATE_TIME_ZONE, TIME_ZONE_KEY, session)); + sqlTimestampOf(2013, 5, 17, 23, 35, 10, 0, session)); assertFunction("date_parse('abc 2013-05-17 fff 23:35:10 xyz', 'abc %Y-%m-%d fff %H:%i:%s xyz')", TimestampType.TIMESTAMP, - sqlTimestampOf(2013, 5, 17, 23, 35, 10, 0, DATE_TIME_ZONE, TIME_ZONE_KEY, session)); + sqlTimestampOf(2013, 5, 17, 23, 35, 10, 0, session)); assertFunction("date_parse('2013 14', '%Y %y')", TimestampType.TIMESTAMP, - sqlTimestampOf(2014, 1, 1, 0, 0, 0, 0, DATE_TIME_ZONE, TIME_ZONE_KEY, session)); + sqlTimestampOf(2014, 1, 1, 0, 0, 0, 0, session)); assertFunction("date_parse('1998 53', '%x %v')", TimestampType.TIMESTAMP, - sqlTimestampOf(1998, 12, 28, 0, 0, 0, 0, DATE_TIME_ZONE, TIME_ZONE_KEY, session)); + sqlTimestampOf(1998, 12, 28, 0, 0, 0, 0, session)); assertFunction("date_parse('1.1', '%s.%f')", TimestampType.TIMESTAMP, - sqlTimestampOf(1970, 1, 1, 0, 0, 1, 100, DATE_TIME_ZONE, TIME_ZONE_KEY, session)); + sqlTimestampOf(1970, 1, 1, 0, 0, 1, 100, session)); assertFunction("date_parse('1.01', '%s.%f')", TimestampType.TIMESTAMP, - sqlTimestampOf(1970, 1, 1, 0, 0, 1, 10, DATE_TIME_ZONE, TIME_ZONE_KEY, session)); + sqlTimestampOf(1970, 1, 1, 0, 0, 1, 10, session)); assertFunction("date_parse('1.2006', '%s.%f')", TimestampType.TIMESTAMP, - sqlTimestampOf(1970, 1, 1, 0, 0, 1, 200, DATE_TIME_ZONE, TIME_ZONE_KEY, session)); + sqlTimestampOf(1970, 1, 1, 0, 0, 1, 200, session)); assertFunction("date_parse('59.123456789', '%s.%f')", TimestampType.TIMESTAMP, - sqlTimestampOf(1970, 1, 1, 0, 0, 59, 123, DATE_TIME_ZONE, TIME_ZONE_KEY, session)); + sqlTimestampOf(1970, 1, 1, 0, 0, 59, 123, session)); assertFunction("date_parse('0', '%k')", TimestampType.TIMESTAMP, - sqlTimestampOf(1970, 1, 1, 0, 0, 0, 0, DATE_TIME_ZONE, TIME_ZONE_KEY, session)); + sqlTimestampOf(1970, 1, 1, 0, 0, 0, 0, session)); assertFunction("date_parse('28-JAN-16 11.45.46.421000 PM','%d-%b-%y %l.%i.%s.%f %p')", TimestampType.TIMESTAMP, - sqlTimestampOf(2016, 1, 28, 23, 45, 46, 421, DATE_TIME_ZONE, TIME_ZONE_KEY, session)); + sqlTimestampOf(2016, 1, 28, 23, 45, 46, 421, session)); assertFunction("date_parse('11-DEC-70 11.12.13.456000 AM','%d-%b-%y %l.%i.%s.%f %p')", TimestampType.TIMESTAMP, - sqlTimestampOf(1970, 12, 11, 11, 12, 13, 456, DATE_TIME_ZONE, TIME_ZONE_KEY, session)); + sqlTimestampOf(1970, 12, 11, 11, 12, 13, 456, session)); assertFunction("date_parse('31-MAY-69 04.59.59.999000 AM','%d-%b-%y %l.%i.%s.%f %p')", TimestampType.TIMESTAMP, - sqlTimestampOf(2069, 5, 31, 4, 59, 59, 999, DATE_TIME_ZONE, TIME_ZONE_KEY, session)); + sqlTimestampOf(2069, 5, 31, 4, 59, 59, 999, session)); assertInvalidFunction("date_parse('', '%D')", "%D not supported in date format string"); assertInvalidFunction("date_parse('', '%U')", "%U not supported in date format string"); @@ -878,10 +878,10 @@ public void testLocale() localeAssertions.assertFunction("date_parse('2013-05-17 12:35:10 오후', '%Y-%m-%d %h:%i:%s %p')", TimestampType.TIMESTAMP, - sqlTimestampOf(2013, 5, 17, 12, 35, 10, 0, DATE_TIME_ZONE, TIME_ZONE_KEY, localeSession)); + sqlTimestampOf(2013, 5, 17, 12, 35, 10, 0, localeSession)); localeAssertions.assertFunction("date_parse('2013-05-17 12:35:10 오전', '%Y-%m-%d %h:%i:%s %p')", TimestampType.TIMESTAMP, - sqlTimestampOf(2013, 5, 17, 0, 35, 10, 0, DATE_TIME_ZONE, TIME_ZONE_KEY, localeSession)); + sqlTimestampOf(2013, 5, 17, 0, 35, 10, 0, localeSession)); localeAssertions.assertFunction("parse_datetime('2013-05-17 12:35:10 오후', 'yyyy-MM-dd hh:mm:ss a')", TIMESTAMP_WITH_TIME_ZONE, diff --git a/presto-main/src/test/java/com/facebook/presto/sql/gen/TestExpressionCompiler.java b/presto-main/src/test/java/com/facebook/presto/sql/gen/TestExpressionCompiler.java index b4a11c305933..3bc4e344549c 100644 --- a/presto-main/src/test/java/com/facebook/presto/sql/gen/TestExpressionCompiler.java +++ b/presto-main/src/test/java/com/facebook/presto/sql/gen/TestExpressionCompiler.java @@ -75,7 +75,6 @@ import static com.facebook.presto.spi.type.DoubleType.DOUBLE; import static com.facebook.presto.spi.type.IntegerType.INTEGER; import static com.facebook.presto.spi.type.SmallintType.SMALLINT; -import static com.facebook.presto.spi.type.TimeZoneKey.UTC_KEY; import static com.facebook.presto.spi.type.TimestampType.TIMESTAMP; import static com.facebook.presto.spi.type.TimestampWithTimeZoneType.TIMESTAMP_WITH_TIME_ZONE; import static com.facebook.presto.spi.type.VarbinaryType.VARBINARY; @@ -825,7 +824,7 @@ public void testTryCast() assertExecute("try_cast('foo' as varchar)", VARCHAR, "foo"); assertExecute("try_cast('foo' as bigint)", BIGINT, null); assertExecute("try_cast('foo' as integer)", INTEGER, null); - assertExecute("try_cast('2001-08-22' as timestamp)", TIMESTAMP, sqlTimestampOf(2001, 8, 22, 0, 0, 0, 0, UTC, UTC_KEY, TEST_SESSION)); + assertExecute("try_cast('2001-08-22' as timestamp)", TIMESTAMP, sqlTimestampOf(2001, 8, 22, 0, 0, 0, 0, TEST_SESSION)); assertExecute("try_cast(bound_string as bigint)", BIGINT, null); assertExecute("try_cast(cast(null as varchar) as bigint)", BIGINT, null); assertExecute("try_cast(bound_long / 13 as bigint)", BIGINT, 94L); diff --git a/presto-main/src/test/java/com/facebook/presto/type/TestArrayOperators.java b/presto-main/src/test/java/com/facebook/presto/type/TestArrayOperators.java index 7db7a684e09c..d87419fb3024 100644 --- a/presto-main/src/test/java/com/facebook/presto/type/TestArrayOperators.java +++ b/presto-main/src/test/java/com/facebook/presto/type/TestArrayOperators.java @@ -65,7 +65,6 @@ import static com.facebook.presto.spi.type.IntegerType.INTEGER; import static com.facebook.presto.spi.type.RealType.REAL; import static com.facebook.presto.spi.type.SmallintType.SMALLINT; -import static com.facebook.presto.spi.type.TimeZoneKey.UTC_KEY; import static com.facebook.presto.spi.type.TimestampType.TIMESTAMP; import static com.facebook.presto.spi.type.TinyintType.TINYINT; import static com.facebook.presto.spi.type.VarcharType.VARCHAR; @@ -88,7 +87,6 @@ import static java.util.Arrays.asList; import static java.util.Collections.emptyList; import static java.util.Collections.singletonList; -import static org.joda.time.DateTimeZone.UTC; import static org.testng.Assert.assertEquals; import static org.testng.Assert.assertTrue; import static org.testng.Assert.fail; @@ -213,7 +211,7 @@ public void testArrayToJson() assertFunction( "CAST(ARRAY[TIMESTAMP '1970-01-01 00:00:01', null] AS JSON)", JSON, - format("[\"%s\",null]", sqlTimestampOf(1970, 1, 1, 0, 0, 1, 0, UTC, UTC_KEY, TEST_SESSION))); + format("[\"%s\",null]", sqlTimestampOf(1970, 1, 1, 0, 0, 1, 0, TEST_SESSION))); assertFunction( "CAST(ARRAY[DATE '2001-08-22', DATE '2001-08-23', null] AS JSON)", JSON, @@ -377,8 +375,8 @@ public void testConstructor() "ARRAY [TIMESTAMP '1970-01-01 00:00:01', TIMESTAMP '1973-07-08 22:00:01']", new ArrayType(TIMESTAMP), ImmutableList.of( - sqlTimestampOf(1970, 1, 1, 0, 0, 1, 0, UTC, UTC_KEY, TEST_SESSION), - sqlTimestampOf(1973, 7, 8, 22, 0, 1, 0, UTC, UTC_KEY, TEST_SESSION))); + sqlTimestampOf(1970, 1, 1, 0, 0, 1, 0, TEST_SESSION), + sqlTimestampOf(1973, 7, 8, 22, 0, 1, 0, TEST_SESSION))); assertFunction("ARRAY [sqrt(-1)]", new ArrayType(DOUBLE), ImmutableList.of(NaN)); assertFunction("ARRAY [pow(infinity(), 2)]", new ArrayType(DOUBLE), ImmutableList.of(POSITIVE_INFINITY)); assertFunction("ARRAY [pow(-infinity(), 1)]", new ArrayType(DOUBLE), ImmutableList.of(NEGATIVE_INFINITY)); @@ -413,8 +411,8 @@ public void testArrayToArrayConcat() assertFunction("ARRAY [TRUE] || ARRAY [FALSE]", new ArrayType(BOOLEAN), ImmutableList.of(true, false)); assertFunction("concat(ARRAY [1] , ARRAY[2,3])", new ArrayType(INTEGER), ImmutableList.of(1, 2, 3)); assertFunction("ARRAY [TIMESTAMP '1970-01-01 00:00:01'] || ARRAY[TIMESTAMP '1973-07-08 22:00:01']", new ArrayType(TIMESTAMP), ImmutableList.of( - sqlTimestampOf(1970, 1, 1, 0, 0, 1, 0, UTC, UTC_KEY, TEST_SESSION), - sqlTimestampOf(1973, 7, 8, 22, 0, 1, 0, UTC, UTC_KEY, TEST_SESSION))); + sqlTimestampOf(1970, 1, 1, 0, 0, 1, 0, TEST_SESSION), + sqlTimestampOf(1973, 7, 8, 22, 0, 1, 0, TEST_SESSION))); assertFunction("ARRAY [ARRAY[ARRAY[1]]] || ARRAY [ARRAY[ARRAY[2]]]", new ArrayType(new ArrayType(new ArrayType(INTEGER))), asList(singletonList(Ints.asList(1)), singletonList(Ints.asList(2)))); @@ -475,11 +473,11 @@ public void testElementArrayConcat() assertFunction("'puppies' || ARRAY ['kittens']", new ArrayType(createVarcharType(7)), Lists.newArrayList("puppies", "kittens")); assertFunction("ARRAY ['kittens'] || 'puppies'", new ArrayType(createVarcharType(7)), Lists.newArrayList("kittens", "puppies")); assertFunction("ARRAY [TIMESTAMP '1970-01-01 00:00:01'] || TIMESTAMP '1973-07-08 22:00:01'", new ArrayType(TIMESTAMP), ImmutableList.of( - sqlTimestampOf(1970, 1, 1, 0, 0, 1, 0, UTC, UTC_KEY, TEST_SESSION), - sqlTimestampOf(1973, 7, 8, 22, 0, 1, 0, UTC, UTC_KEY, TEST_SESSION))); + sqlTimestampOf(1970, 1, 1, 0, 0, 1, 0, TEST_SESSION), + sqlTimestampOf(1973, 7, 8, 22, 0, 1, 0, TEST_SESSION))); assertFunction("TIMESTAMP '1973-07-08 22:00:01' || ARRAY [TIMESTAMP '1970-01-01 00:00:01']", new ArrayType(TIMESTAMP), ImmutableList.of( - sqlTimestampOf(1973, 7, 8, 22, 0, 1, 0, UTC, UTC_KEY, TEST_SESSION), - sqlTimestampOf(1970, 1, 1, 0, 0, 1, 0, UTC, UTC_KEY, TEST_SESSION))); + sqlTimestampOf(1973, 7, 8, 22, 0, 1, 0, TEST_SESSION), + sqlTimestampOf(1970, 1, 1, 0, 0, 1, 0, TEST_SESSION))); assertFunction("ARRAY [2, 8] || ARRAY[ARRAY[3, 6], ARRAY[4]]", new ArrayType(new ArrayType(INTEGER)), ImmutableList.of(ImmutableList.of(2, 8), ImmutableList.of(3, 6), ImmutableList.of(4))); assertFunction("ARRAY [ARRAY [1], ARRAY [2, 8]] || ARRAY [3, 6]", new ArrayType(new ArrayType(INTEGER)), ImmutableList.of(ImmutableList.of(1), ImmutableList.of(2, 8), ImmutableList.of(3, 6))); assertFunction( @@ -559,16 +557,16 @@ public void testArrayJoin() assertFunction("ARRAY_JOIN(ARRAY [sqrt(-1), infinity()], ',')", VARCHAR, "NaN,Infinity"); assertFunction("ARRAY_JOIN(ARRAY [TIMESTAMP '1970-01-01 00:00:01', TIMESTAMP '1973-07-08 22:00:01'], '|')", VARCHAR, format( "%s|%s", - sqlTimestampOf(1970, 1, 1, 0, 0, 1, 0, UTC, UTC_KEY, TEST_SESSION), - sqlTimestampOf(1973, 7, 8, 22, 0, 1, 0, UTC, UTC_KEY, TEST_SESSION))); + sqlTimestampOf(1970, 1, 1, 0, 0, 1, 0, TEST_SESSION), + sqlTimestampOf(1973, 7, 8, 22, 0, 1, 0, TEST_SESSION))); assertFunction( "ARRAY_JOIN(ARRAY [null, TIMESTAMP '1970-01-01 00:00:01'], '|')", VARCHAR, - sqlTimestampOf(1970, 1, 1, 0, 0, 1, 0, UTC, UTC_KEY, TEST_SESSION).toString()); + sqlTimestampOf(1970, 1, 1, 0, 0, 1, 0, TEST_SESSION).toString()); assertFunction( "ARRAY_JOIN(ARRAY [null, TIMESTAMP '1970-01-01 00:00:01'], '|', 'XYZ')", VARCHAR, - "XYZ|" + sqlTimestampOf(1970, 1, 1, 0, 0, 1, 0, UTC, UTC_KEY, TEST_SESSION).toString()); + "XYZ|" + sqlTimestampOf(1970, 1, 1, 0, 0, 1, 0, TEST_SESSION).toString()); assertFunction("ARRAY_JOIN(ARRAY [1.0, 2.1, 3.3], 'x')", VARCHAR, "1.0x2.1x3.3"); assertFunction("ARRAY_JOIN(ARRAY [1.0, 2.100, 3.3], 'x')", VARCHAR, "1.000x2.100x3.300"); assertFunction("ARRAY_JOIN(ARRAY [1.0, 2.100, NULL], 'x', 'N/A')", VARCHAR, "1.000x2.100xN/A"); @@ -723,7 +721,7 @@ public void testSubscript() assertFunction( "ARRAY [TIMESTAMP '1970-01-01 00:00:01', TIMESTAMP '1973-07-08 22:00:01'][1]", TIMESTAMP, - sqlTimestampOf(1970, 1, 1, 0, 0, 1, 0, UTC, UTC_KEY, TEST_SESSION)); + sqlTimestampOf(1970, 1, 1, 0, 0, 1, 0, TEST_SESSION)); assertFunction("ARRAY [infinity()][1]", DOUBLE, POSITIVE_INFINITY); assertFunction("ARRAY [-infinity()][1]", DOUBLE, NEGATIVE_INFINITY); assertFunction("ARRAY [sqrt(-1)][1]", DOUBLE, NaN); @@ -775,11 +773,11 @@ public void testElementAt() assertFunction( "ELEMENT_AT(ARRAY [TIMESTAMP '1970-01-01 00:00:01', TIMESTAMP '1973-07-08 22:00:01'], 1)", TIMESTAMP, - sqlTimestampOf(1970, 1, 1, 0, 0, 1, 0, UTC, UTC_KEY, TEST_SESSION)); + sqlTimestampOf(1970, 1, 1, 0, 0, 1, 0, TEST_SESSION)); assertFunction( "ELEMENT_AT(ARRAY [TIMESTAMP '1970-01-01 00:00:01', TIMESTAMP '1973-07-08 22:00:01'], -2)", TIMESTAMP, - sqlTimestampOf(1970, 1, 1, 0, 0, 1, 0, UTC, UTC_KEY, TEST_SESSION)); + sqlTimestampOf(1970, 1, 1, 0, 0, 1, 0, TEST_SESSION)); assertFunction("ELEMENT_AT(ARRAY [infinity()], 1)", DOUBLE, POSITIVE_INFINITY); assertFunction("ELEMENT_AT(ARRAY [infinity()], -1)", DOUBLE, POSITIVE_INFINITY); assertFunction("ELEMENT_AT(ARRAY [-infinity()], 1)", DOUBLE, NEGATIVE_INFINITY); @@ -820,9 +818,9 @@ public void testSort() "ARRAY_SORT(ARRAY [TIMESTAMP '1973-07-08 22:00:01', TIMESTAMP '1970-01-01 00:00:01', TIMESTAMP '1989-02-06 12:00:00'])", new ArrayType(TIMESTAMP), ImmutableList.of( - sqlTimestampOf(1970, 1, 1, 0, 0, 1, 0, UTC, UTC_KEY, TEST_SESSION), - sqlTimestampOf(1973, 7, 8, 22, 0, 1, 0, UTC, UTC_KEY, TEST_SESSION), - sqlTimestampOf(1989, 2, 6, 12, 0, 0, 0, UTC, UTC_KEY, TEST_SESSION))); + sqlTimestampOf(1970, 1, 1, 0, 0, 1, 0, TEST_SESSION), + sqlTimestampOf(1973, 7, 8, 22, 0, 1, 0, TEST_SESSION), + sqlTimestampOf(1989, 2, 6, 12, 0, 0, 0, TEST_SESSION))); assertFunction("ARRAY_SORT(ARRAY [ARRAY [1], ARRAY [2]])", new ArrayType(new ArrayType(INTEGER)), ImmutableList.of(ImmutableList.of(1), ImmutableList.of(2))); @@ -903,9 +901,9 @@ public void testSort() asList( null, null, - sqlTimestampOf(1989, 2, 6, 12, 0, 0, 0, UTC, UTC_KEY, TEST_SESSION), - sqlTimestampOf(1973, 7, 8, 22, 0, 1, 0, UTC, UTC_KEY, TEST_SESSION), - sqlTimestampOf(1970, 1, 1, 0, 0, 1, 0, UTC, UTC_KEY, TEST_SESSION))); + sqlTimestampOf(1989, 2, 6, 12, 0, 0, 0, TEST_SESSION), + sqlTimestampOf(1973, 7, 8, 22, 0, 1, 0, TEST_SESSION), + sqlTimestampOf(1970, 1, 1, 0, 0, 1, 0, TEST_SESSION))); assertFunction( "ARRAY_SORT(ARRAY[ARRAY[2, 3, 1], null, ARRAY[4, null, 2, 1, 4], ARRAY[1, 2], null], (x, y) -> CASE " + "WHEN x IS NULL THEN -1 " + @@ -979,8 +977,8 @@ public void testDistinct() "ARRAY_DISTINCT(ARRAY [TIMESTAMP '1973-07-08 22:00:01', TIMESTAMP '1970-01-01 00:00:01', TIMESTAMP '1973-07-08 22:00:01'])", new ArrayType(TIMESTAMP), ImmutableList.of( - sqlTimestampOf(1973, 7, 8, 22, 0, 1, 0, UTC, UTC_KEY, TEST_SESSION), - sqlTimestampOf(1970, 1, 1, 0, 0, 1, 0, UTC, UTC_KEY, TEST_SESSION))); + sqlTimestampOf(1973, 7, 8, 22, 0, 1, 0, TEST_SESSION), + sqlTimestampOf(1970, 1, 1, 0, 0, 1, 0, TEST_SESSION))); assertFunction("ARRAY_DISTINCT(ARRAY ['2', '3', '2'])", new ArrayType(createVarcharType(1)), ImmutableList.of("2", "3")); assertFunction("ARRAY_DISTINCT(ARRAY ['BB', 'CCC', 'BB'])", new ArrayType(createVarcharType(3)), ImmutableList.of("BB", "CCC")); assertFunction( @@ -1555,46 +1553,46 @@ public void testSequenceDateTimeDayToSecond() "SEQUENCE(timestamp '2016-04-16 01:00:10', timestamp '2016-04-16 01:07:00', interval '3' minute)", new ArrayType(TIMESTAMP), ImmutableList.of( - sqlTimestampOf(2016, 4, 16, 1, 0, 10, 0, UTC, UTC_KEY, TEST_SESSION), - sqlTimestampOf(2016, 4, 16, 1, 3, 10, 0, UTC, UTC_KEY, TEST_SESSION), - sqlTimestampOf(2016, 4, 16, 1, 6, 10, 0, UTC, UTC_KEY, TEST_SESSION))); + sqlTimestampOf(2016, 4, 16, 1, 0, 10, 0, TEST_SESSION), + sqlTimestampOf(2016, 4, 16, 1, 3, 10, 0, TEST_SESSION), + sqlTimestampOf(2016, 4, 16, 1, 6, 10, 0, TEST_SESSION))); assertFunction( "SEQUENCE(timestamp '2016-04-16 01:10:10', timestamp '2016-04-16 01:03:00', interval '-3' minute)", new ArrayType(TIMESTAMP), ImmutableList.of( - sqlTimestampOf(2016, 4, 16, 1, 10, 10, 0, UTC, UTC_KEY, TEST_SESSION), - sqlTimestampOf(2016, 4, 16, 1, 7, 10, 0, UTC, UTC_KEY, TEST_SESSION), - sqlTimestampOf(2016, 4, 16, 1, 4, 10, 0, UTC, UTC_KEY, TEST_SESSION))); + sqlTimestampOf(2016, 4, 16, 1, 10, 10, 0, TEST_SESSION), + sqlTimestampOf(2016, 4, 16, 1, 7, 10, 0, TEST_SESSION), + sqlTimestampOf(2016, 4, 16, 1, 4, 10, 0, TEST_SESSION))); assertFunction( "SEQUENCE(timestamp '2016-04-16 01:00:10', timestamp '2016-04-16 01:01:00', interval '20' second)", new ArrayType(TIMESTAMP), ImmutableList.of( - sqlTimestampOf(2016, 4, 16, 1, 0, 10, 0, UTC, UTC_KEY, TEST_SESSION), - sqlTimestampOf(2016, 4, 16, 1, 0, 30, 0, UTC, UTC_KEY, TEST_SESSION), - sqlTimestampOf(2016, 4, 16, 1, 0, 50, 0, UTC, UTC_KEY, TEST_SESSION))); + sqlTimestampOf(2016, 4, 16, 1, 0, 10, 0, TEST_SESSION), + sqlTimestampOf(2016, 4, 16, 1, 0, 30, 0, TEST_SESSION), + sqlTimestampOf(2016, 4, 16, 1, 0, 50, 0, TEST_SESSION))); assertFunction( "SEQUENCE(timestamp '2016-04-16 01:01:10', timestamp '2016-04-16 01:00:20', interval '-20' second)", new ArrayType(TIMESTAMP), ImmutableList.of( - sqlTimestampOf(2016, 4, 16, 1, 1, 10, 0, UTC, UTC_KEY, TEST_SESSION), - sqlTimestampOf(2016, 4, 16, 1, 0, 50, 0, UTC, UTC_KEY, TEST_SESSION), - sqlTimestampOf(2016, 4, 16, 1, 0, 30, 0, UTC, UTC_KEY, TEST_SESSION))); + sqlTimestampOf(2016, 4, 16, 1, 1, 10, 0, TEST_SESSION), + sqlTimestampOf(2016, 4, 16, 1, 0, 50, 0, TEST_SESSION), + sqlTimestampOf(2016, 4, 16, 1, 0, 30, 0, TEST_SESSION))); assertFunction( "SEQUENCE(timestamp '2016-04-16 01:00:10', timestamp '2016-04-18 01:01:00', interval '19' hour)", new ArrayType(TIMESTAMP), ImmutableList.of( - sqlTimestampOf(2016, 4, 16, 1, 0, 10, 0, UTC, UTC_KEY, TEST_SESSION), - sqlTimestampOf(2016, 4, 16, 20, 0, 10, 0, UTC, UTC_KEY, TEST_SESSION), - sqlTimestampOf(2016, 4, 17, 15, 0, 10, 0, UTC, UTC_KEY, TEST_SESSION))); + sqlTimestampOf(2016, 4, 16, 1, 0, 10, 0, TEST_SESSION), + sqlTimestampOf(2016, 4, 16, 20, 0, 10, 0, TEST_SESSION), + sqlTimestampOf(2016, 4, 17, 15, 0, 10, 0, TEST_SESSION))); assertFunction( "SEQUENCE(timestamp '2016-04-16 01:00:10', timestamp '2016-04-14 01:00:20', interval '-19' hour)", new ArrayType(TIMESTAMP), ImmutableList.of( - sqlTimestampOf(2016, 4, 16, 1, 0, 10, 0, UTC, UTC_KEY, TEST_SESSION), - sqlTimestampOf(2016, 4, 15, 6, 0, 10, 0, UTC, UTC_KEY, TEST_SESSION), - sqlTimestampOf(2016, 4, 14, 11, 0, 10, 0, UTC, UTC_KEY, TEST_SESSION))); + sqlTimestampOf(2016, 4, 16, 1, 0, 10, 0, TEST_SESSION), + sqlTimestampOf(2016, 4, 15, 6, 0, 10, 0, TEST_SESSION), + sqlTimestampOf(2016, 4, 14, 11, 0, 10, 0, TEST_SESSION))); // failure modes assertInvalidFunction( @@ -1662,31 +1660,31 @@ public void testSequenceDateTimeYearToMonth() "SEQUENCE(timestamp '2016-04-16 01:00:10', timestamp '2016-09-16 01:10:00', interval '2' month)", new ArrayType(TIMESTAMP), ImmutableList.of( - sqlTimestampOf(2016, 4, 16, 1, 0, 10, 0, UTC, UTC_KEY, TEST_SESSION), - sqlTimestampOf(2016, 6, 16, 1, 0, 10, 0, UTC, UTC_KEY, TEST_SESSION), - sqlTimestampOf(2016, 8, 16, 1, 0, 10, 0, UTC, UTC_KEY, TEST_SESSION))); + sqlTimestampOf(2016, 4, 16, 1, 0, 10, 0, TEST_SESSION), + sqlTimestampOf(2016, 6, 16, 1, 0, 10, 0, TEST_SESSION), + sqlTimestampOf(2016, 8, 16, 1, 0, 10, 0, TEST_SESSION))); assertFunction( "SEQUENCE(timestamp '2016-09-16 01:10:10', timestamp '2016-04-16 01:00:00', interval '-2' month)", new ArrayType(TIMESTAMP), ImmutableList.of( - sqlTimestampOf(2016, 9, 16, 1, 10, 10, 0, UTC, UTC_KEY, TEST_SESSION), - sqlTimestampOf(2016, 7, 16, 1, 10, 10, 0, UTC, UTC_KEY, TEST_SESSION), - sqlTimestampOf(2016, 5, 16, 1, 10, 10, 0, UTC, UTC_KEY, TEST_SESSION))); + sqlTimestampOf(2016, 9, 16, 1, 10, 10, 0, TEST_SESSION), + sqlTimestampOf(2016, 7, 16, 1, 10, 10, 0, TEST_SESSION), + sqlTimestampOf(2016, 5, 16, 1, 10, 10, 0, TEST_SESSION))); assertFunction( "SEQUENCE(timestamp '2016-04-16 01:00:10', timestamp '2021-04-16 01:01:00', interval '2' year)", new ArrayType(TIMESTAMP), ImmutableList.of( - sqlTimestampOf(2016, 4, 16, 1, 0, 10, 0, UTC, UTC_KEY, TEST_SESSION), - sqlTimestampOf(2018, 4, 16, 1, 0, 10, 0, UTC, UTC_KEY, TEST_SESSION), - sqlTimestampOf(2020, 4, 16, 1, 0, 10, 0, UTC, UTC_KEY, TEST_SESSION))); + sqlTimestampOf(2016, 4, 16, 1, 0, 10, 0, TEST_SESSION), + sqlTimestampOf(2018, 4, 16, 1, 0, 10, 0, TEST_SESSION), + sqlTimestampOf(2020, 4, 16, 1, 0, 10, 0, TEST_SESSION))); assertFunction( "SEQUENCE(timestamp '2016-04-16 01:01:10', timestamp '2011-04-16 01:00:00', interval '-2' year)", new ArrayType(TIMESTAMP), ImmutableList.of( - sqlTimestampOf(2016, 4, 16, 1, 1, 10, 0, UTC, UTC_KEY, TEST_SESSION), - sqlTimestampOf(2014, 4, 16, 1, 1, 10, 0, UTC, UTC_KEY, TEST_SESSION), - sqlTimestampOf(2012, 4, 16, 1, 1, 10, 0, UTC, UTC_KEY, TEST_SESSION))); + sqlTimestampOf(2016, 4, 16, 1, 1, 10, 0, TEST_SESSION), + sqlTimestampOf(2014, 4, 16, 1, 1, 10, 0, TEST_SESSION), + sqlTimestampOf(2012, 4, 16, 1, 1, 10, 0, TEST_SESSION))); // failure modes assertInvalidFunction( diff --git a/presto-main/src/test/java/com/facebook/presto/type/TestDateBase.java b/presto-main/src/test/java/com/facebook/presto/type/TestDateBase.java index a72e909c6294..67212fb11439 100644 --- a/presto-main/src/test/java/com/facebook/presto/type/TestDateBase.java +++ b/presto-main/src/test/java/com/facebook/presto/type/TestDateBase.java @@ -129,7 +129,7 @@ public void testCastToTimestamp() { assertFunction("cast(DATE '2001-1-22' as timestamp)", TIMESTAMP, - sqlTimestampOf(2001, 1, 22, 0, 0, 0, 0, DATE_TIME_ZONE, TIME_ZONE_KEY, session)); + sqlTimestampOf(2001, 1, 22, 0, 0, 0, 0, session)); } @Test diff --git a/presto-main/src/test/java/com/facebook/presto/type/TestDateTimeOperators.java b/presto-main/src/test/java/com/facebook/presto/type/TestDateTimeOperators.java index 0f3dfd00b617..a6b15fdbaa49 100644 --- a/presto-main/src/test/java/com/facebook/presto/type/TestDateTimeOperators.java +++ b/presto-main/src/test/java/com/facebook/presto/type/TestDateTimeOperators.java @@ -50,28 +50,28 @@ public void testTimeZoneGap() assertFunction( "TIMESTAMP '2013-03-31 00:05' + INTERVAL '1' hour", TIMESTAMP, - sqlTimestampOf(2013, 3, 31, 1, 5, 0, 0, TIME_ZONE, TIME_ZONE_KEY, session.toConnectorSession())); + sqlTimestampOf(2013, 3, 31, 1, 5, 0, 0, DATE_TIME_ZONE, TIME_ZONE_KEY, session.toConnectorSession())); assertFunction( "TIMESTAMP '2013-03-31 00:05' + INTERVAL '2' hour", TIMESTAMP, - sqlTimestampOf(2013, 3, 31, 2, 5, 0, 0, TIME_ZONE, TIME_ZONE_KEY, session.toConnectorSession())); + sqlTimestampOf(2013, 3, 31, 2, 5, 0, 0, DATE_TIME_ZONE, TIME_ZONE_KEY, session.toConnectorSession())); assertFunction( "TIMESTAMP '2013-03-31 00:05' + INTERVAL '3' hour", TIMESTAMP, - sqlTimestampOf(2013, 3, 31, 3, 5, 0, 0, TIME_ZONE, TIME_ZONE_KEY, session.toConnectorSession())); + sqlTimestampOf(2013, 3, 31, 3, 5, 0, 0, DATE_TIME_ZONE, TIME_ZONE_KEY, session.toConnectorSession())); assertFunction( "TIMESTAMP '2013-03-31 04:05' - INTERVAL '3' hour", TIMESTAMP, - sqlTimestampOf(2013, 3, 31, 1, 5, 0, 0, TIME_ZONE, TIME_ZONE_KEY, session.toConnectorSession())); + sqlTimestampOf(2013, 3, 31, 1, 5, 0, 0, DATE_TIME_ZONE, TIME_ZONE_KEY, session.toConnectorSession())); assertFunction( "TIMESTAMP '2013-03-31 03:05' - INTERVAL '2' hour", TIMESTAMP, - sqlTimestampOf(2013, 3, 31, 1, 5, 0, 0, TIME_ZONE, TIME_ZONE_KEY, session.toConnectorSession())); + sqlTimestampOf(2013, 3, 31, 1, 5, 0, 0, DATE_TIME_ZONE, TIME_ZONE_KEY, session.toConnectorSession())); assertFunction( "TIMESTAMP '2013-03-31 01:05' - INTERVAL '1' hour", TIMESTAMP, - sqlTimestampOf(2013, 3, 31, 0, 5, 0, 0, TIME_ZONE, TIME_ZONE_KEY, session.toConnectorSession())); + sqlTimestampOf(2013, 3, 31, 0, 5, 0, 0, DATE_TIME_ZONE, TIME_ZONE_KEY, session.toConnectorSession())); } @Test @@ -80,42 +80,42 @@ public void testDaylightTimeSaving() assertFunction( "TIMESTAMP '2013-10-27 00:05' + INTERVAL '1' hour", TIMESTAMP, - sqlTimestampOf(2013, 10, 27, 1, 5, 0, 0, TIME_ZONE, TIME_ZONE_KEY, session.toConnectorSession())); + sqlTimestampOf(2013, 10, 27, 1, 5, 0, 0, DATE_TIME_ZONE, TIME_ZONE_KEY, session.toConnectorSession())); assertFunction( "TIMESTAMP '2013-10-27 00:05' + INTERVAL '2' hour", TIMESTAMP, - sqlTimestampOf(2013, 10, 27, 2, 5, 0, 0, TIME_ZONE, TIME_ZONE_KEY, session.toConnectorSession())); + sqlTimestampOf(2013, 10, 27, 2, 5, 0, 0, DATE_TIME_ZONE, TIME_ZONE_KEY, session.toConnectorSession())); assertFunction( "TIMESTAMP '2013-10-27 00:05' + INTERVAL '3' hour", TIMESTAMP, - sqlTimestampOf(2013, 10, 27, 3, 5, 0, 0, TIME_ZONE, TIME_ZONE_KEY, session.toConnectorSession())); + sqlTimestampOf(2013, 10, 27, 3, 5, 0, 0, DATE_TIME_ZONE, TIME_ZONE_KEY, session.toConnectorSession())); assertFunction( "TIMESTAMP '2013-10-27 00:05' + INTERVAL '4' hour", TIMESTAMP, - sqlTimestampOf(2013, 10, 27, 4, 5, 0, 0, TIME_ZONE, TIME_ZONE_KEY, session.toConnectorSession())); + sqlTimestampOf(2013, 10, 27, 4, 5, 0, 0, DATE_TIME_ZONE, TIME_ZONE_KEY, session.toConnectorSession())); assertFunction( "TIMESTAMP '2013-10-27 03:05' - INTERVAL '4' hour", TIMESTAMP, - sqlTimestampOf(2013, 10, 26, 23, 5, 0, 0, TIME_ZONE, TIME_ZONE_KEY, session.toConnectorSession())); + sqlTimestampOf(2013, 10, 26, 23, 5, 0, 0, DATE_TIME_ZONE, TIME_ZONE_KEY, session.toConnectorSession())); assertFunction( "TIMESTAMP '2013-10-27 02:05' - INTERVAL '2' hour", TIMESTAMP, - sqlTimestampOf(2013, 10, 27, 0, 5, 0, 0, TIME_ZONE, TIME_ZONE_KEY, session.toConnectorSession())); + sqlTimestampOf(2013, 10, 27, 0, 5, 0, 0, DATE_TIME_ZONE, TIME_ZONE_KEY, session.toConnectorSession())); assertFunction( "TIMESTAMP '2013-10-27 01:05' - INTERVAL '1' hour", TIMESTAMP, - sqlTimestampOf(2013, 10, 27, 0, 5, 0, 0, TIME_ZONE, TIME_ZONE_KEY, session.toConnectorSession())); + sqlTimestampOf(2013, 10, 27, 0, 5, 0, 0, DATE_TIME_ZONE, TIME_ZONE_KEY, session.toConnectorSession())); assertFunction( "TIMESTAMP '2013-10-27 03:05' - INTERVAL '1' hour", TIMESTAMP, - sqlTimestampOf(2013, 10, 27, 2, 5, 0, 0, TIME_ZONE, TIME_ZONE_KEY, session.toConnectorSession())); + sqlTimestampOf(2013, 10, 27, 2, 5, 0, 0, DATE_TIME_ZONE, TIME_ZONE_KEY, session.toConnectorSession())); assertFunction( "TIMESTAMP '2013-10-27 03:05' - INTERVAL '2' hour", TIMESTAMP, - sqlTimestampOf(2013, 10, 27, 1, 5, 0, 0, TIME_ZONE, TIME_ZONE_KEY, session.toConnectorSession())); + sqlTimestampOf(2013, 10, 27, 1, 5, 0, 0, DATE_TIME_ZONE, TIME_ZONE_KEY, session.toConnectorSession())); } @Test diff --git a/presto-main/src/test/java/com/facebook/presto/type/TestDateTimeOperatorsBase.java b/presto-main/src/test/java/com/facebook/presto/type/TestDateTimeOperatorsBase.java index 41591d5ad191..40650815126d 100644 --- a/presto-main/src/test/java/com/facebook/presto/type/TestDateTimeOperatorsBase.java +++ b/presto-main/src/test/java/com/facebook/presto/type/TestDateTimeOperatorsBase.java @@ -43,7 +43,7 @@ public abstract class TestDateTimeOperatorsBase extends AbstractTestFunctions { protected static final TimeZoneKey TIME_ZONE_KEY = getTimeZoneKey("Europe/Berlin"); - protected static final DateTimeZone TIME_ZONE = getDateTimeZone(TIME_ZONE_KEY); + protected static final DateTimeZone DATE_TIME_ZONE = getDateTimeZone(TIME_ZONE_KEY); protected static final DateTimeZone WEIRD_TIME_ZONE = DateTimeZone.forOffsetHoursMinutes(5, 9); protected static final TimeZoneKey WEIRD_TIME_ZONE_KEY = getTimeZoneKeyForOffset(5 * 60 + 9); @@ -122,28 +122,28 @@ public void testTimestampPlusInterval() { assertFunction("TIMESTAMP '2001-1-22 03:04:05.321' + INTERVAL '3' hour", TIMESTAMP, - sqlTimestampOf(2001, 1, 22, 6, 4, 5, 321, TIME_ZONE, TIME_ZONE_KEY, session)); + sqlTimestampOf(2001, 1, 22, 6, 4, 5, 321, session)); assertFunction("INTERVAL '3' hour + TIMESTAMP '2001-1-22 03:04:05.321'", TIMESTAMP, - sqlTimestampOf(2001, 1, 22, 6, 4, 5, 321, TIME_ZONE, TIME_ZONE_KEY, session)); + sqlTimestampOf(2001, 1, 22, 6, 4, 5, 321, session)); assertFunction("TIMESTAMP '2001-1-22 03:04:05.321' + INTERVAL '3' day", TIMESTAMP, - sqlTimestampOf(2001, 1, 25, 3, 4, 5, 321, TIME_ZONE, TIME_ZONE_KEY, session)); + sqlTimestampOf(2001, 1, 25, 3, 4, 5, 321, session)); assertFunction("INTERVAL '3' day + TIMESTAMP '2001-1-22 03:04:05.321'", TIMESTAMP, - sqlTimestampOf(2001, 1, 25, 3, 4, 5, 321, TIME_ZONE, TIME_ZONE_KEY, session)); + sqlTimestampOf(2001, 1, 25, 3, 4, 5, 321, session)); assertFunction("TIMESTAMP '2001-1-22 03:04:05.321' + INTERVAL '3' month", TIMESTAMP, - sqlTimestampOf(2001, 4, 22, 3, 4, 5, 321, TIME_ZONE, TIME_ZONE_KEY, session)); + sqlTimestampOf(2001, 4, 22, 3, 4, 5, 321, session)); assertFunction("INTERVAL '3' month + TIMESTAMP '2001-1-22 03:04:05.321'", TIMESTAMP, - sqlTimestampOf(2001, 4, 22, 3, 4, 5, 321, TIME_ZONE, TIME_ZONE_KEY, session)); + sqlTimestampOf(2001, 4, 22, 3, 4, 5, 321, session)); assertFunction("TIMESTAMP '2001-1-22 03:04:05.321' + INTERVAL '3' year", TIMESTAMP, - sqlTimestampOf(2004, 1, 22, 3, 4, 5, 321, TIME_ZONE, TIME_ZONE_KEY, session)); + sqlTimestampOf(2004, 1, 22, 3, 4, 5, 321, session)); assertFunction("INTERVAL '3' year + TIMESTAMP '2001-1-22 03:04:05.321'", TIMESTAMP, - sqlTimestampOf(2004, 1, 22, 3, 4, 5, 321, TIME_ZONE, TIME_ZONE_KEY, session)); + sqlTimestampOf(2004, 1, 22, 3, 4, 5, 321, session)); assertFunction("TIMESTAMP '2001-1-22 03:04:05.321 +05:09' + INTERVAL '3' hour", TIMESTAMP_WITH_TIME_ZONE, @@ -211,13 +211,13 @@ public void testTimestampMinusInterval() { assertFunction("TIMESTAMP '2001-1-22 03:04:05.321' - INTERVAL '3' day", TIMESTAMP, - sqlTimestampOf(2001, 1, 19, 3, 4, 5, 321, TIME_ZONE, TIME_ZONE_KEY, session)); + sqlTimestampOf(2001, 1, 19, 3, 4, 5, 321, session)); assertFunction("TIMESTAMP '2001-1-22 03:04:05.321 +05:09' - INTERVAL '3' day", TIMESTAMP_WITH_TIME_ZONE, new SqlTimestampWithTimeZone(new DateTime(2001, 1, 19, 3, 4, 5, 321, WEIRD_TIME_ZONE).getMillis(), WEIRD_TIME_ZONE_KEY)); assertFunction("TIMESTAMP '2001-1-22 03:04:05.321' - INTERVAL '3' month", TIMESTAMP, - sqlTimestampOf(2000, 10, 22, 3, 4, 5, 321, TIME_ZONE, TIME_ZONE_KEY, session)); + sqlTimestampOf(2000, 10, 22, 3, 4, 5, 321, session)); assertFunction("TIMESTAMP '2001-1-22 03:04:05.321 +05:09' - INTERVAL '3' month", TIMESTAMP_WITH_TIME_ZONE, new SqlTimestampWithTimeZone(new DateTime(2000, 10, 22, 3, 4, 5, 321, WEIRD_TIME_ZONE).getMillis(), WEIRD_TIME_ZONE_KEY)); diff --git a/presto-main/src/test/java/com/facebook/presto/type/TestDateTimeOperatorsLegacy.java b/presto-main/src/test/java/com/facebook/presto/type/TestDateTimeOperatorsLegacy.java index ac17ac3c718b..44cfa8e8d7ab 100644 --- a/presto-main/src/test/java/com/facebook/presto/type/TestDateTimeOperatorsLegacy.java +++ b/presto-main/src/test/java/com/facebook/presto/type/TestDateTimeOperatorsLegacy.java @@ -51,28 +51,28 @@ public void testTimeZoneGap() assertFunction( "TIMESTAMP '2013-03-31 00:05' + INTERVAL '1' hour", TIMESTAMP, - sqlTimestampOf(2013, 3, 31, 1, 5, 0, 0, TIME_ZONE, TIME_ZONE_KEY, session)); + sqlTimestampOf(2013, 3, 31, 1, 5, 0, 0, session)); assertFunction( "TIMESTAMP '2013-03-31 00:05' + INTERVAL '2' hour", TIMESTAMP, - sqlTimestampOf(2013, 3, 31, 3, 5, 0, 0, TIME_ZONE, TIME_ZONE_KEY, session)); + sqlTimestampOf(2013, 3, 31, 3, 5, 0, 0, session)); assertFunction( "TIMESTAMP '2013-03-31 00:05' + INTERVAL '3' hour", TIMESTAMP, - sqlTimestampOf(2013, 3, 31, 4, 5, 0, 0, TIME_ZONE, TIME_ZONE_KEY, session)); + sqlTimestampOf(2013, 3, 31, 4, 5, 0, 0, session)); assertFunction( "TIMESTAMP '2013-03-31 04:05' - INTERVAL '3' hour", TIMESTAMP, - sqlTimestampOf(2013, 3, 31, 0, 5, 0, 0, TIME_ZONE, TIME_ZONE_KEY, session)); + sqlTimestampOf(2013, 3, 31, 0, 5, 0, 0, session)); assertFunction( "TIMESTAMP '2013-03-31 03:05' - INTERVAL '2' hour", TIMESTAMP, - sqlTimestampOf(2013, 3, 31, 0, 5, 0, 0, TIME_ZONE, TIME_ZONE_KEY, session)); + sqlTimestampOf(2013, 3, 31, 0, 5, 0, 0, session)); assertFunction( "TIMESTAMP '2013-03-31 01:05' - INTERVAL '1' hour", TIMESTAMP, - sqlTimestampOf(2013, 3, 31, 0, 5, 0, 0, TIME_ZONE, TIME_ZONE_KEY, session)); + sqlTimestampOf(2013, 3, 31, 0, 5, 0, 0, session)); } @Test @@ -82,42 +82,42 @@ public void testDaylightTimeSaving() assertFunction( "TIMESTAMP '2013-10-27 00:05' + INTERVAL '1' hour", TIMESTAMP, - sqlTimestampOf(2013, 10, 27, 1, 5, 0, 0, TIME_ZONE, TIME_ZONE_KEY, session)); + sqlTimestampOf(2013, 10, 27, 1, 5, 0, 0, session)); assertFunction( "TIMESTAMP '2013-10-27 00:05' + INTERVAL '2' hour", TIMESTAMP, - sqlTimestampOf(2013, 10, 27, 2, 5, 0, 0, TIME_ZONE, TIME_ZONE_KEY, session)); + sqlTimestampOf(2013, 10, 27, 2, 5, 0, 0, session)); // we need to manipulate millis directly here because 2 am has two representations in out time zone, and we need the second one assertFunction( "TIMESTAMP '2013-10-27 00:05' + INTERVAL '3' hour", TIMESTAMP, - sqlTimestampOf(new DateTime(2013, 10, 27, 0, 5, 0, 0, TIME_ZONE).plus(HOURS.toMillis(3)), session)); + sqlTimestampOf(new DateTime(2013, 10, 27, 0, 5, 0, 0, DATE_TIME_ZONE).plus(HOURS.toMillis(3)), session)); assertFunction( "TIMESTAMP '2013-10-27 00:05' + INTERVAL '4' hour", TIMESTAMP, - sqlTimestampOf(2013, 10, 27, 3, 5, 0, 0, TIME_ZONE, TIME_ZONE_KEY, session)); + sqlTimestampOf(2013, 10, 27, 3, 5, 0, 0, session)); assertFunction( "TIMESTAMP '2013-10-27 03:05' - INTERVAL '4' hour", TIMESTAMP, - sqlTimestampOf(2013, 10, 27, 0, 5, 0, 0, TIME_ZONE, TIME_ZONE_KEY, session)); + sqlTimestampOf(2013, 10, 27, 0, 5, 0, 0, session)); assertFunction( "TIMESTAMP '2013-10-27 02:05' - INTERVAL '2' hour", TIMESTAMP, - sqlTimestampOf(2013, 10, 27, 0, 5, 0, 0, TIME_ZONE, TIME_ZONE_KEY, session)); + sqlTimestampOf(2013, 10, 27, 0, 5, 0, 0, session)); assertFunction( "TIMESTAMP '2013-10-27 01:05' - INTERVAL '1' hour", TIMESTAMP, - sqlTimestampOf(2013, 10, 27, 0, 5, 0, 0, TIME_ZONE, TIME_ZONE_KEY, session)); + sqlTimestampOf(2013, 10, 27, 0, 5, 0, 0, session)); assertFunction( "TIMESTAMP '2013-10-27 03:05' - INTERVAL '1' hour", TIMESTAMP, - sqlTimestampOf(new DateTime(2013, 10, 27, 0, 5, 0, 0, TIME_ZONE).plus(HOURS.toMillis(3)), session)); + sqlTimestampOf(new DateTime(2013, 10, 27, 0, 5, 0, 0, DATE_TIME_ZONE).plus(HOURS.toMillis(3)), session)); assertFunction( "TIMESTAMP '2013-10-27 03:05' - INTERVAL '2' hour", TIMESTAMP, - sqlTimestampOf(2013, 10, 27, 2, 5, 0, 0, TIME_ZONE, TIME_ZONE_KEY, session)); + sqlTimestampOf(2013, 10, 27, 2, 5, 0, 0, session)); } @Test diff --git a/presto-main/src/test/java/com/facebook/presto/type/TestJsonOperators.java b/presto-main/src/test/java/com/facebook/presto/type/TestJsonOperators.java index 166cfecb4284..94bf9162be41 100644 --- a/presto-main/src/test/java/com/facebook/presto/type/TestJsonOperators.java +++ b/presto-main/src/test/java/com/facebook/presto/type/TestJsonOperators.java @@ -36,7 +36,6 @@ import static com.facebook.presto.spi.type.IntegerType.INTEGER; import static com.facebook.presto.spi.type.RealType.REAL; import static com.facebook.presto.spi.type.SmallintType.SMALLINT; -import static com.facebook.presto.spi.type.TimeZoneKey.UTC_KEY; import static com.facebook.presto.spi.type.TinyintType.TINYINT; import static com.facebook.presto.spi.type.VarcharType.VARCHAR; import static com.facebook.presto.testing.DateTimeTestingUtils.sqlTimestampOf; @@ -45,7 +44,6 @@ import static java.lang.Double.NEGATIVE_INFINITY; import static java.lang.Double.POSITIVE_INFINITY; import static java.lang.String.format; -import static org.joda.time.DateTimeZone.UTC; import static org.testng.Assert.assertEquals; import static org.testng.Assert.fail; @@ -391,7 +389,7 @@ public void testCastFromVarchar() public void testCastFromTimestamp() { assertFunction("cast(cast (null as timestamp) as JSON)", JSON, null); - assertFunction("CAST(TIMESTAMP '1970-01-01 00:00:01' AS JSON)", JSON, format("\"%s\"", sqlTimestampOf(1970, 1, 1, 0, 0, 1, 0, UTC, UTC_KEY, TEST_SESSION))); + assertFunction("CAST(TIMESTAMP '1970-01-01 00:00:01' AS JSON)", JSON, format("\"%s\"", sqlTimestampOf(1970, 1, 1, 0, 0, 1, 0, TEST_SESSION))); } @Test diff --git a/presto-main/src/test/java/com/facebook/presto/type/TestMapOperators.java b/presto-main/src/test/java/com/facebook/presto/type/TestMapOperators.java index 230dfb08667d..13f181ac7851 100644 --- a/presto-main/src/test/java/com/facebook/presto/type/TestMapOperators.java +++ b/presto-main/src/test/java/com/facebook/presto/type/TestMapOperators.java @@ -46,7 +46,6 @@ import static com.facebook.presto.spi.type.IntegerType.INTEGER; import static com.facebook.presto.spi.type.RealType.REAL; import static com.facebook.presto.spi.type.SmallintType.SMALLINT; -import static com.facebook.presto.spi.type.TimeZoneKey.UTC_KEY; import static com.facebook.presto.spi.type.TimestampType.TIMESTAMP; import static com.facebook.presto.spi.type.TinyintType.TINYINT; import static com.facebook.presto.spi.type.VarbinaryType.VARBINARY; @@ -65,7 +64,6 @@ import static java.util.Arrays.asList; import static java.util.Collections.emptyList; import static java.util.Collections.singletonList; -import static org.joda.time.DateTimeZone.UTC; public class TestMapOperators extends AbstractTestFunctions @@ -107,16 +105,16 @@ public void testConstructor() mapType(createVarcharType(3), TIMESTAMP), ImmutableMap.of( "1", - sqlTimestampOf(1970, 1, 1, 0, 0, 1, 0, UTC, UTC_KEY, TEST_SESSION), + sqlTimestampOf(1970, 1, 1, 0, 0, 1, 0, TEST_SESSION), "100", - sqlTimestampOf(1973, 7, 8, 22, 0, 1, 0, UTC, UTC_KEY, TEST_SESSION))); + sqlTimestampOf(1973, 7, 8, 22, 0, 1, 0, TEST_SESSION))); assertFunction( "MAP(ARRAY[TIMESTAMP '1970-01-01 00:00:01', TIMESTAMP '1973-07-08 22:00:01'], ARRAY[1.0E0, 100.0E0])", mapType(TIMESTAMP, DOUBLE), ImmutableMap.of( - sqlTimestampOf(1970, 1, 1, 0, 0, 1, 0, UTC, UTC_KEY, TEST_SESSION), + sqlTimestampOf(1970, 1, 1, 0, 0, 1, 0, TEST_SESSION), 1.0, - sqlTimestampOf(1973, 7, 8, 22, 0, 1, 0, UTC, UTC_KEY, TEST_SESSION), + sqlTimestampOf(1973, 7, 8, 22, 0, 1, 0, TEST_SESSION), 100.0)); assertInvalidFunction("MAP(ARRAY [1], ARRAY [2, 4])", "Key and value arrays must be the same length"); @@ -249,7 +247,7 @@ public void testMapToJson() assertFunction( "CAST(MAP(ARRAY[1, 2], ARRAY[TIMESTAMP '1970-01-01 00:00:01', null]) AS JSON)", JSON, - format("{\"1\":\"%s\",\"2\":null}", sqlTimestampOf(1970, 1, 1, 0, 0, 1, 0, UTC, UTC_KEY, TEST_SESSION).toString())); + format("{\"1\":\"%s\",\"2\":null}", sqlTimestampOf(1970, 1, 1, 0, 0, 1, 0, TEST_SESSION).toString())); assertFunction( "CAST(MAP(ARRAY[2, 5, 3], ARRAY[DATE '2001-08-22', DATE '2001-08-23', null]) AS JSON)", JSON, @@ -521,7 +519,7 @@ public void testElementAt() assertFunction( "element_at(MAP(ARRAY ['1', '100'], ARRAY [TIMESTAMP '1970-01-01 00:00:01', TIMESTAMP '2005-09-10 13:00:00']), '1')", TIMESTAMP, - sqlTimestampOf(1970, 1, 1, 0, 0, 1, 0, UTC, UTC_KEY, TEST_SESSION)); + sqlTimestampOf(1970, 1, 1, 0, 0, 1, 0, TEST_SESSION)); assertFunction("element_at(MAP(ARRAY [from_unixtime(1), from_unixtime(100)], ARRAY [1.0E0, 100.0E0]), from_unixtime(1))", DOUBLE, 1.0); } @@ -546,7 +544,7 @@ public void testSubscript() assertFunction( "MAP(ARRAY['1', '100'], ARRAY[TIMESTAMP '1970-01-01 00:00:01', TIMESTAMP '1973-07-08 22:00:01'])['1']", TIMESTAMP, - sqlTimestampOf(1970, 1, 1, 0, 0, 1, 0, UTC, UTC_KEY, TEST_SESSION)); + sqlTimestampOf(1970, 1, 1, 0, 0, 1, 0, TEST_SESSION)); assertFunction("MAP(ARRAY[from_unixtime(1), from_unixtime(100)], ARRAY[1.0E0, 100.0E0])[from_unixtime(1)]", DOUBLE, 1.0); assertInvalidFunction("MAP(ARRAY [BIGINT '1'], ARRAY [BIGINT '2'])[3]", "Key not present in map: 3"); assertInvalidFunction("MAP(ARRAY ['hi'], ARRAY [2])['missing']", "Key not present in map: missing"); @@ -566,7 +564,7 @@ public void testMapKeys() assertFunction( "MAP_KEYS(MAP(ARRAY[TIMESTAMP '1970-01-01 00:00:01'], ARRAY[1.0E0]))", new ArrayType(TIMESTAMP), - ImmutableList.of(sqlTimestampOf(1970, 1, 1, 0, 0, 1, 0, UTC, UTC_KEY, TEST_SESSION))); + ImmutableList.of(sqlTimestampOf(1970, 1, 1, 0, 0, 1, 0, TEST_SESSION))); assertFunction("MAP_KEYS(MAP(ARRAY[CAST('puppies' as varbinary)], ARRAY['kittens']))", new ArrayType(VARBINARY), ImmutableList.of(new SqlVarbinary("puppies".getBytes(UTF_8)))); assertFunction("MAP_KEYS(MAP(ARRAY[1,2], ARRAY[ARRAY[1, 2], ARRAY[3]]))", new ArrayType(INTEGER), ImmutableList.of(1, 2)); assertFunction("MAP_KEYS(MAP(ARRAY[1,4], ARRAY[MAP(ARRAY[2], ARRAY[3]), MAP(ARRAY[5], ARRAY[6])]))", new ArrayType(INTEGER), ImmutableList.of(1, 4)); diff --git a/presto-main/src/test/java/com/facebook/presto/type/TestRowOperators.java b/presto-main/src/test/java/com/facebook/presto/type/TestRowOperators.java index 8dd4ad15e8e8..477883d66c88 100644 --- a/presto-main/src/test/java/com/facebook/presto/type/TestRowOperators.java +++ b/presto-main/src/test/java/com/facebook/presto/type/TestRowOperators.java @@ -52,7 +52,6 @@ import static com.facebook.presto.spi.type.IntegerType.INTEGER; import static com.facebook.presto.spi.type.RealType.REAL; import static com.facebook.presto.spi.type.SmallintType.SMALLINT; -import static com.facebook.presto.spi.type.TimeZoneKey.UTC_KEY; import static com.facebook.presto.spi.type.TinyintType.TINYINT; import static com.facebook.presto.spi.type.TypeSignature.parseTypeSignature; import static com.facebook.presto.spi.type.VarcharType.VARCHAR; @@ -67,7 +66,6 @@ import static java.lang.String.format; import static java.util.Arrays.asList; import static java.util.Collections.emptyList; -import static org.joda.time.DateTimeZone.UTC; import static org.testng.Assert.assertEquals; public class TestRowOperators @@ -142,7 +140,7 @@ public void testRowToJson() assertFunction( "CAST(ROW(TIMESTAMP '1970-01-01 00:00:01', cast(null as TIMESTAMP)) AS JSON)", JSON, - format("[\"%s\",null]", sqlTimestampOf(1970, 1, 1, 0, 0, 1, 0, UTC, UTC_KEY, TEST_SESSION))); + format("[\"%s\",null]", sqlTimestampOf(1970, 1, 1, 0, 0, 1, 0, TEST_SESSION))); assertFunction( "cast(ROW(ARRAY[1, 2], ARRAY[3, null], ARRAY[], ARRAY[null, null], CAST(null AS ARRAY)) AS JSON)", diff --git a/presto-main/src/test/java/com/facebook/presto/type/TestTimeBase.java b/presto-main/src/test/java/com/facebook/presto/type/TestTimeBase.java index a5ed57d26d63..909499d0e911 100644 --- a/presto-main/src/test/java/com/facebook/presto/type/TestTimeBase.java +++ b/presto-main/src/test/java/com/facebook/presto/type/TestTimeBase.java @@ -177,7 +177,7 @@ public void testCastToTimestamp() { assertFunction("cast(TIME '03:04:05.321' as timestamp)", TIMESTAMP, - sqlTimestampOf(1970, 1, 1, 3, 4, 5, 321, DATE_TIME_ZONE, TIME_ZONE_KEY, session)); + sqlTimestampOf(1970, 1, 1, 3, 4, 5, 321, session)); } @Test diff --git a/presto-main/src/test/java/com/facebook/presto/type/TestTimeWithTimeZone.java b/presto-main/src/test/java/com/facebook/presto/type/TestTimeWithTimeZone.java index ca0f285114b9..b8d061229fee 100644 --- a/presto-main/src/test/java/com/facebook/presto/type/TestTimeWithTimeZone.java +++ b/presto-main/src/test/java/com/facebook/presto/type/TestTimeWithTimeZone.java @@ -16,7 +16,9 @@ import org.testng.annotations.Test; import static com.facebook.presto.spi.type.TimeType.TIME; +import static com.facebook.presto.spi.type.TimestampType.TIMESTAMP; import static com.facebook.presto.testing.DateTimeTestingUtils.sqlTimeOf; +import static com.facebook.presto.testing.DateTimeTestingUtils.sqlTimestampOf; public class TestTimeWithTimeZone extends TestTimeWithTimeZoneBase @@ -34,4 +36,13 @@ public void testCastToTime() TIME, sqlTimeOf(3, 4, 5, 321, session)); } + + @Test + @Override + public void testCastToTimestamp() + { + assertFunction("cast(TIME '03:04:05.321 +07:09' as timestamp)", + TIMESTAMP, + sqlTimestampOf(1970, 1, 1, 3, 4, 5, 321, session)); + } } diff --git a/presto-main/src/test/java/com/facebook/presto/type/TestTimeWithTimeZoneBase.java b/presto-main/src/test/java/com/facebook/presto/type/TestTimeWithTimeZoneBase.java index d36a3afb13c4..a407fe7fd8ac 100644 --- a/presto-main/src/test/java/com/facebook/presto/type/TestTimeWithTimeZoneBase.java +++ b/presto-main/src/test/java/com/facebook/presto/type/TestTimeWithTimeZoneBase.java @@ -26,10 +26,8 @@ import static com.facebook.presto.spi.type.TimeWithTimeZoneType.TIME_WITH_TIME_ZONE; import static com.facebook.presto.spi.type.TimeZoneKey.getTimeZoneKey; import static com.facebook.presto.spi.type.TimeZoneKey.getTimeZoneKeyForOffset; -import static com.facebook.presto.spi.type.TimestampType.TIMESTAMP; import static com.facebook.presto.spi.type.TimestampWithTimeZoneType.TIMESTAMP_WITH_TIME_ZONE; import static com.facebook.presto.spi.type.VarcharType.VARCHAR; -import static com.facebook.presto.testing.DateTimeTestingUtils.sqlTimestampOf; import static com.facebook.presto.testing.TestingSession.testSessionBuilder; import static com.facebook.presto.type.IntervalDayTimeType.INTERVAL_DAY_TIME; @@ -203,12 +201,7 @@ public void testBetween() public abstract void testCastToTime(); @Test - public void testCastToTimestamp() - { - assertFunction("cast(TIME '03:04:05.321 +07:09' as timestamp)", - TIMESTAMP, - sqlTimestampOf(1970, 1, 1, 3, 4, 5, 321, WEIRD_ZONE, session.getTimeZoneKey(), session)); - } + public abstract void testCastToTimestamp(); @Test public void testCastToTimestampWithTimeZone() diff --git a/presto-main/src/test/java/com/facebook/presto/type/TestTimeWithTimeZoneLegacy.java b/presto-main/src/test/java/com/facebook/presto/type/TestTimeWithTimeZoneLegacy.java index 9bcd01aed5a0..bc66169c182e 100644 --- a/presto-main/src/test/java/com/facebook/presto/type/TestTimeWithTimeZoneLegacy.java +++ b/presto-main/src/test/java/com/facebook/presto/type/TestTimeWithTimeZoneLegacy.java @@ -16,7 +16,9 @@ import org.testng.annotations.Test; import static com.facebook.presto.spi.type.TimeType.TIME; +import static com.facebook.presto.spi.type.TimestampType.TIMESTAMP; import static com.facebook.presto.testing.DateTimeTestingUtils.sqlTimeOf; +import static com.facebook.presto.testing.DateTimeTestingUtils.sqlTimestampOf; public class TestTimeWithTimeZoneLegacy extends TestTimeWithTimeZoneBase @@ -32,6 +34,15 @@ public void testCastToTime() { assertFunction("cast(TIME '03:04:05.321 +07:09' as time)", TIME, - sqlTimeOf(2, 4, 5, 321, session)); + sqlTimeOf(2 /* not 3 */, 4, 5, 321, session)); + } + + @Test + @Override + public void testCastToTimestamp() + { + assertFunction("cast(TIME '03:04:05.321 +07:09' as timestamp)", + TIMESTAMP, + sqlTimestampOf(1970, 1, 1, 2 /* not 3 */, 4, 5, 321, session)); } } diff --git a/presto-main/src/test/java/com/facebook/presto/type/TestTimestampBase.java b/presto-main/src/test/java/com/facebook/presto/type/TestTimestampBase.java index c0f3d66eb096..1094815b4c84 100644 --- a/presto-main/src/test/java/com/facebook/presto/type/TestTimestampBase.java +++ b/presto-main/src/test/java/com/facebook/presto/type/TestTimestampBase.java @@ -75,19 +75,19 @@ public void testSubtract() @Test public void testLiteral() { - assertFunction("TIMESTAMP '2013-03-30 01:05'", TIMESTAMP, sqlTimestampOf(2013, 3, 30, 1, 5, 0, 0, DATE_TIME_ZONE, TIME_ZONE_KEY, session)); - assertFunction("TIMESTAMP '2013-03-30 02:05'", TIMESTAMP, sqlTimestampOf(2013, 3, 30, 2, 5, 0, 0, DATE_TIME_ZONE, TIME_ZONE_KEY, session)); - assertFunction("TIMESTAMP '2013-03-30 03:05'", TIMESTAMP, sqlTimestampOf(2013, 3, 30, 3, 5, 0, 0, DATE_TIME_ZONE, TIME_ZONE_KEY, session)); + assertFunction("TIMESTAMP '2013-03-30 01:05'", TIMESTAMP, sqlTimestampOf(2013, 3, 30, 1, 5, 0, 0, session)); + assertFunction("TIMESTAMP '2013-03-30 02:05'", TIMESTAMP, sqlTimestampOf(2013, 3, 30, 2, 5, 0, 0, session)); + assertFunction("TIMESTAMP '2013-03-30 03:05'", TIMESTAMP, sqlTimestampOf(2013, 3, 30, 3, 5, 0, 0, session)); - assertFunction("TIMESTAMP '2001-01-22 03:04:05.321'", TIMESTAMP, sqlTimestampOf(2001, 1, 22, 3, 4, 5, 321, DATE_TIME_ZONE, TIME_ZONE_KEY, session)); - assertFunction("TIMESTAMP '2001-01-22 03:04:05'", TIMESTAMP, sqlTimestampOf(2001, 1, 22, 3, 4, 5, 0, DATE_TIME_ZONE, TIME_ZONE_KEY, session)); - assertFunction("TIMESTAMP '2001-01-22 03:04'", TIMESTAMP, sqlTimestampOf(2001, 1, 22, 3, 4, 0, 0, DATE_TIME_ZONE, TIME_ZONE_KEY, session)); - assertFunction("TIMESTAMP '2001-01-22'", TIMESTAMP, sqlTimestampOf(2001, 1, 22, 0, 0, 0, 0, DATE_TIME_ZONE, TIME_ZONE_KEY, session)); + assertFunction("TIMESTAMP '2001-01-22 03:04:05.321'", TIMESTAMP, sqlTimestampOf(2001, 1, 22, 3, 4, 5, 321, session)); + assertFunction("TIMESTAMP '2001-01-22 03:04:05'", TIMESTAMP, sqlTimestampOf(2001, 1, 22, 3, 4, 5, 0, session)); + assertFunction("TIMESTAMP '2001-01-22 03:04'", TIMESTAMP, sqlTimestampOf(2001, 1, 22, 3, 4, 0, 0, session)); + assertFunction("TIMESTAMP '2001-01-22'", TIMESTAMP, sqlTimestampOf(2001, 1, 22, 0, 0, 0, 0, session)); - assertFunction("TIMESTAMP '2001-1-2 3:4:5.321'", TIMESTAMP, sqlTimestampOf(2001, 1, 2, 3, 4, 5, 321, DATE_TIME_ZONE, TIME_ZONE_KEY, session)); - assertFunction("TIMESTAMP '2001-1-2 3:4:5'", TIMESTAMP, sqlTimestampOf(2001, 1, 2, 3, 4, 5, 0, DATE_TIME_ZONE, TIME_ZONE_KEY, session)); - assertFunction("TIMESTAMP '2001-1-2 3:4'", TIMESTAMP, sqlTimestampOf(2001, 1, 2, 3, 4, 0, 0, DATE_TIME_ZONE, TIME_ZONE_KEY, session)); - assertFunction("TIMESTAMP '2001-1-2'", TIMESTAMP, sqlTimestampOf(2001, 1, 2, 0, 0, 0, 0, DATE_TIME_ZONE, TIME_ZONE_KEY, session)); + assertFunction("TIMESTAMP '2001-1-2 3:4:5.321'", TIMESTAMP, sqlTimestampOf(2001, 1, 2, 3, 4, 5, 321, session)); + assertFunction("TIMESTAMP '2001-1-2 3:4:5'", TIMESTAMP, sqlTimestampOf(2001, 1, 2, 3, 4, 5, 0, session)); + assertFunction("TIMESTAMP '2001-1-2 3:4'", TIMESTAMP, sqlTimestampOf(2001, 1, 2, 3, 4, 0, 0, session)); + assertFunction("TIMESTAMP '2001-1-2'", TIMESTAMP, sqlTimestampOf(2001, 1, 2, 0, 0, 0, 0, session)); assertInvalidFunction("TIMESTAMP 'text'", SemanticErrorCode.INVALID_LITERAL, "line 1:1: 'text' is not a valid timestamp literal"); } @@ -222,25 +222,25 @@ public void testCastFromSlice() { assertFunction("cast('2001-1-22 03:04:05.321' as timestamp)", TIMESTAMP, - sqlTimestampOf(2001, 1, 22, 3, 4, 5, 321, DATE_TIME_ZONE, TIME_ZONE_KEY, session)); + sqlTimestampOf(2001, 1, 22, 3, 4, 5, 321, session)); assertFunction("cast('2001-1-22 03:04:05' as timestamp)", TIMESTAMP, - sqlTimestampOf(2001, 1, 22, 3, 4, 5, 0, DATE_TIME_ZONE, TIME_ZONE_KEY, session)); + sqlTimestampOf(2001, 1, 22, 3, 4, 5, 0, session)); assertFunction("cast('2001-1-22 03:04' as timestamp)", TIMESTAMP, - sqlTimestampOf(2001, 1, 22, 3, 4, 0, 0, DATE_TIME_ZONE, TIME_ZONE_KEY, session)); + sqlTimestampOf(2001, 1, 22, 3, 4, 0, 0, session)); assertFunction("cast('2001-1-22' as timestamp)", TIMESTAMP, - sqlTimestampOf(2001, 1, 22, 0, 0, 0, 0, DATE_TIME_ZONE, TIME_ZONE_KEY, session)); + sqlTimestampOf(2001, 1, 22, 0, 0, 0, 0, session)); assertFunction("cast('\n\t 2001-1-22 03:04:05.321' as timestamp)", TIMESTAMP, - sqlTimestampOf(2001, 1, 22, 3, 4, 5, 321, DATE_TIME_ZONE, TIME_ZONE_KEY, session)); + sqlTimestampOf(2001, 1, 22, 3, 4, 5, 321, session)); assertFunction("cast('2001-1-22 03:04:05.321 \t\n' as timestamp)", TIMESTAMP, - sqlTimestampOf(2001, 1, 22, 3, 4, 5, 321, DATE_TIME_ZONE, TIME_ZONE_KEY, session)); + sqlTimestampOf(2001, 1, 22, 3, 4, 5, 321, session)); assertFunction("cast('\n\t 2001-1-22 03:04:05.321 \t\n' as timestamp)", TIMESTAMP, - sqlTimestampOf(2001, 1, 22, 3, 4, 5, 321, DATE_TIME_ZONE, TIME_ZONE_KEY, session)); + sqlTimestampOf(2001, 1, 22, 3, 4, 5, 321, session)); } @Test @@ -248,10 +248,10 @@ public void testGreatest() { assertFunction("greatest(TIMESTAMP '2013-03-30 01:05', TIMESTAMP '2012-03-30 01:05')", TIMESTAMP, - sqlTimestampOf(2013, 3, 30, 1, 5, 0, 0, DATE_TIME_ZONE, TIME_ZONE_KEY, session)); + sqlTimestampOf(2013, 3, 30, 1, 5, 0, 0, session)); assertFunction("greatest(TIMESTAMP '2013-03-30 01:05', TIMESTAMP '2012-03-30 01:05', TIMESTAMP '2012-05-01 01:05')", TIMESTAMP, - sqlTimestampOf(2013, 3, 30, 1, 5, 0, 0, DATE_TIME_ZONE, TIME_ZONE_KEY, session)); + sqlTimestampOf(2013, 3, 30, 1, 5, 0, 0, session)); } @Test @@ -259,10 +259,10 @@ public void testLeast() { assertFunction("least(TIMESTAMP '2013-03-30 01:05', TIMESTAMP '2012-03-30 01:05')", TIMESTAMP, - sqlTimestampOf(2012, 3, 30, 1, 5, 0, 0, DATE_TIME_ZONE, TIME_ZONE_KEY, session)); + sqlTimestampOf(2012, 3, 30, 1, 5, 0, 0, session)); assertFunction("least(TIMESTAMP '2013-03-30 01:05', TIMESTAMP '2012-03-30 01:05', TIMESTAMP '2012-05-01 01:05')", TIMESTAMP, - sqlTimestampOf(2012, 3, 30, 1, 5, 0, 0, DATE_TIME_ZONE, TIME_ZONE_KEY, session)); + sqlTimestampOf(2012, 3, 30, 1, 5, 0, 0, session)); } @Test diff --git a/presto-main/src/test/java/com/facebook/presto/type/TestTimestampLegacy.java b/presto-main/src/test/java/com/facebook/presto/type/TestTimestampLegacy.java index 031d4461580e..7dd58635e1dd 100644 --- a/presto-main/src/test/java/com/facebook/presto/type/TestTimestampLegacy.java +++ b/presto-main/src/test/java/com/facebook/presto/type/TestTimestampLegacy.java @@ -28,14 +28,38 @@ public TestTimestampLegacy() public void testCastFromSlice() { super.testCastFromSlice(); - assertFunction("cast('2001-1-22 03:04:05.321 +07:09' as timestamp)", TIMESTAMP, sqlTimestampOf(2001, 1, 22, 3, 4, 5, 321, WEIRD_ZONE, TIME_ZONE_KEY, session)); - assertFunction("cast('2001-1-22 03:04:05 +07:09' as timestamp)", TIMESTAMP, sqlTimestampOf(2001, 1, 22, 3, 4, 5, 0, WEIRD_ZONE, TIME_ZONE_KEY, session)); - assertFunction("cast('2001-1-22 03:04 +07:09' as timestamp)", TIMESTAMP, sqlTimestampOf(2001, 1, 22, 3, 4, 0, 0, WEIRD_ZONE, TIME_ZONE_KEY, session)); - assertFunction("cast('2001-1-22 +07:09' as timestamp)", TIMESTAMP, sqlTimestampOf(2001, 1, 22, 0, 0, 0, 0, WEIRD_ZONE, TIME_ZONE_KEY, session)); + assertFunction( + "cast('2001-1-22 03:04:05.321 +07:09' as timestamp)", + TIMESTAMP, + sqlTimestampOf(2001, 1, 21, 20, 55, 5, 321, session)); + assertFunction( + "cast('2001-1-22 03:04:05 +07:09' as timestamp)", + TIMESTAMP, + sqlTimestampOf(2001, 1, 21, 20, 55, 5, 0, session)); + assertFunction( + "cast('2001-1-22 03:04 +07:09' as timestamp)", + TIMESTAMP, + sqlTimestampOf(2001, 1, 21, 20, 55, 0, 0, session)); + assertFunction( + "cast('2001-1-22 +07:09' as timestamp)", + TIMESTAMP, + sqlTimestampOf(2001, 1, 21, 17, 51, 0, 0, session)); - assertFunction("cast('2001-1-22 03:04:05.321 Asia/Oral' as timestamp)", TIMESTAMP, sqlTimestampOf(2001, 1, 22, 3, 4, 5, 321, ORAL_ZONE, TIME_ZONE_KEY, session)); - assertFunction("cast('2001-1-22 03:04:05 Asia/Oral' as timestamp)", TIMESTAMP, sqlTimestampOf(2001, 1, 22, 3, 4, 5, 0, ORAL_ZONE, TIME_ZONE_KEY, session)); - assertFunction("cast('2001-1-22 03:04 Asia/Oral' as timestamp)", TIMESTAMP, sqlTimestampOf(2001, 1, 22, 3, 4, 0, 0, ORAL_ZONE, TIME_ZONE_KEY, session)); - assertFunction("cast('2001-1-22 Asia/Oral' as timestamp)", TIMESTAMP, sqlTimestampOf(2001, 1, 22, 0, 0, 0, 0, ORAL_ZONE, TIME_ZONE_KEY, session)); + assertFunction( + "cast('2001-1-22 03:04:05.321 Asia/Oral' as timestamp)", + TIMESTAMP, + sqlTimestampOf(2001, 1, 22, 0, 4, 5, 321, session)); + assertFunction( + "cast('2001-1-22 03:04:05 Asia/Oral' as timestamp)", + TIMESTAMP, + sqlTimestampOf(2001, 1, 22, 0, 4, 5, 0, session)); + assertFunction( + "cast('2001-1-22 03:04 Asia/Oral' as timestamp)", + TIMESTAMP, + sqlTimestampOf(2001, 1, 22, 0, 4, 0, 0, session)); + assertFunction( + "cast('2001-1-22 Asia/Oral' as timestamp)", + TIMESTAMP, + sqlTimestampOf(2001, 1, 21, 21, 0, 0, 0, session)); } } diff --git a/presto-main/src/test/java/com/facebook/presto/type/TestTimestampWithTimeZone.java b/presto-main/src/test/java/com/facebook/presto/type/TestTimestampWithTimeZone.java index feee20cac567..acfa1b231d34 100644 --- a/presto-main/src/test/java/com/facebook/presto/type/TestTimestampWithTimeZone.java +++ b/presto-main/src/test/java/com/facebook/presto/type/TestTimestampWithTimeZone.java @@ -17,7 +17,9 @@ import static com.facebook.presto.spi.type.TimeType.TIME; import static com.facebook.presto.spi.type.TimeWithTimeZoneType.TIME_WITH_TIME_ZONE; +import static com.facebook.presto.spi.type.TimestampType.TIMESTAMP; import static com.facebook.presto.testing.DateTimeTestingUtils.sqlTimeOf; +import static com.facebook.presto.testing.DateTimeTestingUtils.sqlTimestampOf; public class TestTimestampWithTimeZone extends TestTimestampWithTimeZoneBase @@ -41,6 +43,7 @@ public void testCastToTime() } @Test + @Override public void testCastToTimeWithTimeZone() { super.testCastToTimeWithTimeZone(); @@ -52,4 +55,18 @@ public void testCastToTimeWithTimeZone() TIME_WITH_TIME_ZONE, "10:00:00.000 Asia/Kathmandu"); } + + @Test + @Override + public void testCastToTimestamp() + { + assertFunction("cast(TIMESTAMP '2001-1-22 03:04:05.321 +07:09' as timestamp)", + TIMESTAMP, + sqlTimestampOf(2001, 1, 22, 3, 4, 5, 321, session)); + + // This TZ had switch in 2014, so if we test for 2014 and used unpacked value we would use wrong shift + assertFunction("cast(TIMESTAMP '2001-1-22 03:04:05.321 Pacific/Bougainville' as timestamp)", + TIMESTAMP, + sqlTimestampOf(2001, 1, 22, 3, 4, 5, 321, session)); + } } diff --git a/presto-main/src/test/java/com/facebook/presto/type/TestTimestampWithTimeZoneBase.java b/presto-main/src/test/java/com/facebook/presto/type/TestTimestampWithTimeZoneBase.java index bb634efa8eb4..f99e50629e08 100644 --- a/presto-main/src/test/java/com/facebook/presto/type/TestTimestampWithTimeZoneBase.java +++ b/presto-main/src/test/java/com/facebook/presto/type/TestTimestampWithTimeZoneBase.java @@ -30,10 +30,8 @@ import static com.facebook.presto.spi.type.TimeWithTimeZoneType.TIME_WITH_TIME_ZONE; import static com.facebook.presto.spi.type.TimeZoneKey.getTimeZoneKey; import static com.facebook.presto.spi.type.TimeZoneKey.getTimeZoneKeyForOffset; -import static com.facebook.presto.spi.type.TimestampType.TIMESTAMP; import static com.facebook.presto.spi.type.TimestampWithTimeZoneType.TIMESTAMP_WITH_TIME_ZONE; import static com.facebook.presto.spi.type.VarcharType.VARCHAR; -import static com.facebook.presto.testing.DateTimeTestingUtils.sqlTimestampOf; import static com.facebook.presto.testing.TestingSession.testSessionBuilder; import static com.facebook.presto.type.IntervalDayTimeType.INTERVAL_DAY_TIME; import static com.facebook.presto.util.DateTimeZoneIndex.getDateTimeZone; @@ -266,17 +264,7 @@ public void testCastToTimeWithTimeZone() } @Test - public void testCastToTimestamp() - { - assertFunction("cast(TIMESTAMP '2001-1-22 03:04:05.321 +07:09' as timestamp)", - TIMESTAMP, - sqlTimestampOf(2001, 1, 22, 3, 4, 5, 321, WEIRD_ZONE, session.getTimeZoneKey(), session)); - - // This TZ had switch in 2014, so if we test for 2014 and used unpacked value we would use wrong shift - assertFunction("cast(TIMESTAMP '2001-1-22 03:04:05.321 Pacific/Bougainville' as timestamp)", - TIMESTAMP, - sqlTimestampOf(2001, 1, 22, 3, 4, 5, 321, getDateTimeZone(getTimeZoneKey("Pacific/Bougainville")), session.getTimeZoneKey(), session)); - } + public abstract void testCastToTimestamp(); @Test public void testCastToSlice() diff --git a/presto-main/src/test/java/com/facebook/presto/type/TestTimestampWithTimeZoneLegacy.java b/presto-main/src/test/java/com/facebook/presto/type/TestTimestampWithTimeZoneLegacy.java index e01307fd3f23..53728f21971f 100644 --- a/presto-main/src/test/java/com/facebook/presto/type/TestTimestampWithTimeZoneLegacy.java +++ b/presto-main/src/test/java/com/facebook/presto/type/TestTimestampWithTimeZoneLegacy.java @@ -16,7 +16,9 @@ import org.testng.annotations.Test; import static com.facebook.presto.spi.type.TimeType.TIME; +import static com.facebook.presto.spi.type.TimestampType.TIMESTAMP; import static com.facebook.presto.testing.DateTimeTestingUtils.sqlTimeOf; +import static com.facebook.presto.testing.DateTimeTestingUtils.sqlTimestampOf; public class TestTimestampWithTimeZoneLegacy extends TestTimestampWithTimeZoneBase @@ -32,6 +34,20 @@ public void testCastToTime() { assertFunction("cast(TIMESTAMP '2001-1-22 03:04:05.321 +07:09' as time)", TIME, - sqlTimeOf(2, 4, 5, 321, session)); + sqlTimeOf(2 /* not 3 */, 4, 5, 321, session)); + } + + @Test + @Override + public void testCastToTimestamp() + { + assertFunction("cast(TIMESTAMP '2001-1-22 03:04:05.321 +07:09' as timestamp)", + TIMESTAMP, + sqlTimestampOf(2001, 1, 22, 2 /* not 3 */, 4, 5, 321, session)); + + // This TZ had switch in 2014 + assertFunction("cast(TIMESTAMP '2001-1-22 03:04:05.321 Pacific/Bougainville' as timestamp)", + TIMESTAMP, + sqlTimestampOf(2001, 1, 21 /* not 22 */, 23 /* not 3 */, 13, 5, 321, session)); } } diff --git a/presto-teradata-functions/src/test/java/com/facebook/presto/teradata/functions/TestTeradataDateFunctions.java b/presto-teradata-functions/src/test/java/com/facebook/presto/teradata/functions/TestTeradataDateFunctions.java index 69c8dd42b651..0ee6cedb932f 100644 --- a/presto-teradata-functions/src/test/java/com/facebook/presto/teradata/functions/TestTeradataDateFunctions.java +++ b/presto-teradata-functions/src/test/java/com/facebook/presto/teradata/functions/TestTeradataDateFunctions.java @@ -20,7 +20,6 @@ import com.facebook.presto.spi.type.TimeZoneKey; import com.facebook.presto.spi.type.TimestampType; import org.joda.time.DateTime; -import org.joda.time.DateTimeZone; import org.testng.annotations.BeforeClass; import org.testng.annotations.Test; @@ -31,14 +30,12 @@ import static com.facebook.presto.spi.type.VarcharType.VARCHAR; import static com.facebook.presto.testing.DateTimeTestingUtils.sqlTimestampOf; import static com.facebook.presto.testing.TestingSession.testSessionBuilder; -import static com.facebook.presto.util.DateTimeZoneIndex.getDateTimeZone; import static java.lang.Math.toIntExact; public class TestTeradataDateFunctions extends AbstractTestFunctions { private static final TimeZoneKey TIME_ZONE_KEY = getTimeZoneKey("Asia/Kathmandu"); - private static final DateTimeZone DATE_TIME_ZONE = getDateTimeZone(TIME_ZONE_KEY); private static final Session SESSION = testSessionBuilder() .setCatalog("catalog") .setSchema("schema") @@ -139,7 +136,7 @@ private void assertTimestamp(String projection, int year, int month, int day, in assertFunction( projection, TimestampType.TIMESTAMP, - sqlTimestampOf(year, month, day, hour, minutes, seconds, 0, DATE_TIME_ZONE, SESSION.getTimeZoneKey(), SESSION)); + sqlTimestampOf(year, month, day, hour, minutes, seconds, 0, SESSION)); } private void assertDate(String projection, int year, int month, int day) From ade4339602eb959e07e94cd9c480dd64dc4a2e9a Mon Sep 17 00:00:00 2001 From: Piotr Findeisen Date: Thu, 26 Jul 2018 14:32:37 +0200 Subject: [PATCH 6/6] Change default session zone in tests to non-UTC --- .../plugin/blackhole/TestBlackHoleSmoke.java | 2 +- .../TestCassandraIntegrationSmokeTest.java | 21 ++++++++----------- .../presto/testing/TestingSession.java | 13 ++++++++++-- .../scalar/TestDateTimeFunctions.java | 4 ++-- .../scalar/TestDateTimeFunctionsBase.java | 20 +++++++++++------- .../scalar/TestDateTimeFunctionsLegacy.java | 8 +++---- .../presto/sql/TestExpressionInterpreter.java | 11 +++++----- .../sql/gen/TestExpressionCompiler.java | 11 +++++++++- .../facebook/presto/type/TestTimeBase.java | 3 ++- .../presto/type/TestTimestampBase.java | 7 ++++--- .../presto/type/TestTimestampLegacy.java | 16 +++++++------- .../TestRaptorIntegrationSmokeTest.java | 4 ++-- .../functions/TestTeradataDateFunctions.java | 4 ---- .../tests/AbstractTestAggregations.java | 16 +++++++------- .../presto/tests/AbstractTestQueries.java | 18 ++++++++-------- 15 files changed, 88 insertions(+), 70 deletions(-) diff --git a/presto-blackhole/src/test/java/com/facebook/presto/plugin/blackhole/TestBlackHoleSmoke.java b/presto-blackhole/src/test/java/com/facebook/presto/plugin/blackhole/TestBlackHoleSmoke.java index ab6e719a4381..ab4e119b1b8b 100644 --- a/presto-blackhole/src/test/java/com/facebook/presto/plugin/blackhole/TestBlackHoleSmoke.java +++ b/presto-blackhole/src/test/java/com/facebook/presto/plugin/blackhole/TestBlackHoleSmoke.java @@ -258,7 +258,7 @@ public void testSelectAllTypes() assertEquals(row.getField(6), 0.0); assertEquals(row.getField(7), false); assertEquals(row.getField(8), LocalDate.ofEpochDay(0)); - assertEquals(row.getField(9), LocalDateTime.of(1970, 1, 1, 0, 0, 0)); + assertEquals(row.getField(9), LocalDateTime.of(1969, 12, 31, 13, 0, 0)); // TODO #7122 should be 1970-01-01 00:00:00 assertEquals(row.getField(10), "****************".getBytes()); assertEquals(row.getField(11), new BigDecimal("0.00")); assertEquals(row.getField(12), new BigDecimal("00000000000000000000.0000000000")); diff --git a/presto-cassandra/src/test/java/com/facebook/presto/cassandra/TestCassandraIntegrationSmokeTest.java b/presto-cassandra/src/test/java/com/facebook/presto/cassandra/TestCassandraIntegrationSmokeTest.java index b55cfc2a8679..33415534de14 100644 --- a/presto-cassandra/src/test/java/com/facebook/presto/cassandra/TestCassandraIntegrationSmokeTest.java +++ b/presto-cassandra/src/test/java/com/facebook/presto/cassandra/TestCassandraIntegrationSmokeTest.java @@ -20,14 +20,13 @@ import com.facebook.presto.tests.AbstractTestIntegrationSmokeTest; import com.google.common.collect.ImmutableList; import io.airlift.units.Duration; -import org.joda.time.DateTime; import org.testng.annotations.BeforeClass; import org.testng.annotations.Test; import java.math.BigInteger; import java.nio.ByteBuffer; +import java.sql.Timestamp; import java.time.LocalDateTime; -import java.util.Date; import java.util.List; import static com.datastax.driver.core.utils.Bytes.toRawHexString; @@ -56,7 +55,6 @@ import static com.google.common.primitives.Ints.toByteArray; import static java.util.concurrent.TimeUnit.MINUTES; import static java.util.stream.Collectors.toList; -import static org.joda.time.DateTimeZone.UTC; import static org.testng.Assert.assertEquals; @Test(singleThreaded = true) @@ -66,9 +64,8 @@ public class TestCassandraIntegrationSmokeTest private static final String KEYSPACE = "smoke_test"; private static final Session SESSION = createCassandraSession(KEYSPACE); - private static final DateTime DATE_TIME_UTC = new DateTime(1970, 1, 1, 3, 4, 5, UTC); - private static final Date DATE_LOCAL = new Date(DATE_TIME_UTC.getMillis()); - private static final LocalDateTime TIMESTAMP_LOCAL = LocalDateTime.of(1970, 1, 1, 3, 4, 5); + private static final Timestamp DATE_TIME_LOCAL = Timestamp.valueOf(LocalDateTime.of(1970, 1, 1, 3, 4, 5, 0)); + private static final LocalDateTime TIMESTAMP_LOCAL = LocalDateTime.of(1969, 12, 31, 23, 4, 5); // TODO #7122 should match DATE_TIME_LOCAL private CassandraSession session; @@ -81,7 +78,7 @@ public TestCassandraIntegrationSmokeTest() public void setUp() { session = EmbeddedCassandra.getSession(); - createTestTables(session, KEYSPACE, DATE_LOCAL); + createTestTables(session, KEYSPACE, DATE_TIME_LOCAL); } @Override @@ -106,7 +103,7 @@ public void testPartitionKeyPredicate() " AND typeinteger = 7" + " AND typelong = 1007" + " AND typebytes = from_hex('" + toRawHexString(ByteBuffer.wrap(toByteArray(7))) + "')" + - " AND typetimestamp = TIMESTAMP '1970-01-01 03:04:05'" + + " AND typetimestamp = TIMESTAMP '1969-12-31 23:04:05'" + " AND typeansi = 'ansi 7'" + " AND typeboolean = false" + " AND typedecimal = 128.0" + @@ -237,17 +234,17 @@ public void testClusteringKeyPushdownInequality() assertEquals(execute(sql).getRowCount(), 4); sql = "SELECT * FROM " + TABLE_CLUSTERING_KEYS_INEQUALITY + " WHERE key='key_1' AND clust_one='clust_one' AND clust_two=2"; assertEquals(execute(sql).getRowCount(), 1); - sql = "SELECT * FROM " + TABLE_CLUSTERING_KEYS_INEQUALITY + " WHERE key='key_1' AND clust_one='clust_one' AND clust_two=2 AND clust_three = timestamp '1970-01-01 03:04:05.020'"; + sql = "SELECT * FROM " + TABLE_CLUSTERING_KEYS_INEQUALITY + " WHERE key='key_1' AND clust_one='clust_one' AND clust_two=2 AND clust_three = timestamp '1969-12-31 23:04:05.020'"; assertEquals(execute(sql).getRowCount(), 1); - sql = "SELECT * FROM " + TABLE_CLUSTERING_KEYS_INEQUALITY + " WHERE key='key_1' AND clust_one='clust_one' AND clust_two=2 AND clust_three = timestamp '1970-01-01 03:04:05.010'"; + sql = "SELECT * FROM " + TABLE_CLUSTERING_KEYS_INEQUALITY + " WHERE key='key_1' AND clust_one='clust_one' AND clust_two=2 AND clust_three = timestamp '1969-12-31 23:04:05.010'"; assertEquals(execute(sql).getRowCount(), 0); sql = "SELECT * FROM " + TABLE_CLUSTERING_KEYS_INEQUALITY + " WHERE key='key_1' AND clust_one='clust_one' AND clust_two IN (1,2)"; assertEquals(execute(sql).getRowCount(), 2); sql = "SELECT * FROM " + TABLE_CLUSTERING_KEYS_INEQUALITY + " WHERE key='key_1' AND clust_one='clust_one' AND clust_two > 1 AND clust_two < 3"; assertEquals(execute(sql).getRowCount(), 1); - sql = "SELECT * FROM " + TABLE_CLUSTERING_KEYS_INEQUALITY + " WHERE key='key_1' AND clust_one='clust_one' AND clust_two=2 AND clust_three >= timestamp '1970-01-01 03:04:05.010' AND clust_three <= timestamp '1970-01-01 03:04:05.020'"; + sql = "SELECT * FROM " + TABLE_CLUSTERING_KEYS_INEQUALITY + " WHERE key='key_1' AND clust_one='clust_one' AND clust_two=2 AND clust_three >= timestamp '1969-12-31 23:04:05.010' AND clust_three <= timestamp '1969-12-31 23:04:05.020'"; assertEquals(execute(sql).getRowCount(), 1); - sql = "SELECT * FROM " + TABLE_CLUSTERING_KEYS_INEQUALITY + " WHERE key='key_1' AND clust_one='clust_one' AND clust_two IN (1,2) AND clust_three >= timestamp '1970-01-01 03:04:05.010' AND clust_three <= timestamp '1970-01-01 03:04:05.020'"; + sql = "SELECT * FROM " + TABLE_CLUSTERING_KEYS_INEQUALITY + " WHERE key='key_1' AND clust_one='clust_one' AND clust_two IN (1,2) AND clust_three >= timestamp '1969-12-31 23:04:05.010' AND clust_three <= timestamp '1969-12-31 23:04:05.020'"; assertEquals(execute(sql).getRowCount(), 2); sql = "SELECT * FROM " + TABLE_CLUSTERING_KEYS_INEQUALITY + " WHERE key='key_1' AND clust_one='clust_one' AND clust_two IN (1,2,3) AND clust_two < 2"; assertEquals(execute(sql).getRowCount(), 1); diff --git a/presto-main/src/main/java/com/facebook/presto/testing/TestingSession.java b/presto-main/src/main/java/com/facebook/presto/testing/TestingSession.java index 73a630010629..6d764c95a9a9 100644 --- a/presto-main/src/main/java/com/facebook/presto/testing/TestingSession.java +++ b/presto-main/src/main/java/com/facebook/presto/testing/TestingSession.java @@ -27,6 +27,7 @@ import com.facebook.presto.spi.connector.ConnectorTransactionHandle; import com.facebook.presto.spi.security.Identity; import com.facebook.presto.spi.transaction.IsolationLevel; +import com.facebook.presto.spi.type.TimeZoneKey; import com.facebook.presto.sql.SqlPath; import com.google.common.collect.ImmutableSet; @@ -34,7 +35,6 @@ import static com.facebook.presto.connector.ConnectorId.createInformationSchemaConnectorId; import static com.facebook.presto.connector.ConnectorId.createSystemTablesConnectorId; -import static com.facebook.presto.spi.type.TimeZoneKey.UTC_KEY; import static java.util.Locale.ENGLISH; public final class TestingSession @@ -42,6 +42,15 @@ public final class TestingSession public static final String TESTING_CATALOG = "testing_catalog"; private static final QueryIdGenerator queryIdGenerator = new QueryIdGenerator(); + /* + * Pacific/Apia + * - has DST (e.g. January 2017) + * - had DST change at midnight (on Sunday, 26 September 2010, 00:00:00 clocks were turned forward 1 hour) + * - had offset change since 1970 (offset in January 1970: -11:00, offset in January 2017: +14:00, offset in June 2017: +13:00) + * - a whole day was skipped during policy change (on Friday, 30 December 2011, 00:00:00 clocks were turned forward 24 hours) + */ + public static final TimeZoneKey DEFAULT_TIME_ZONE_KEY = TimeZoneKey.getTimeZoneKey("Pacific/Apia"); + private TestingSession() {} public static SessionBuilder testSessionBuilder() @@ -58,7 +67,7 @@ public static SessionBuilder testSessionBuilder(SessionPropertyManager sessionPr .setCatalog("catalog") .setSchema("schema") .setPath(new SqlPath(Optional.of("path"))) - .setTimeZoneKey(UTC_KEY) + .setTimeZoneKey(DEFAULT_TIME_ZONE_KEY) .setLocale(ENGLISH) .setRemoteUserAddress("address") .setUserAgent("agent"); diff --git a/presto-main/src/test/java/com/facebook/presto/operator/scalar/TestDateTimeFunctions.java b/presto-main/src/test/java/com/facebook/presto/operator/scalar/TestDateTimeFunctions.java index 28eba3ccd583..38469441e013 100644 --- a/presto-main/src/test/java/com/facebook/presto/operator/scalar/TestDateTimeFunctions.java +++ b/presto-main/src/test/java/com/facebook/presto/operator/scalar/TestDateTimeFunctions.java @@ -89,8 +89,8 @@ public void testCurrentTimestamp() .setStartTime(new DateTime(2017, 3, 1, 14, 30, 0, 0, DATE_TIME_ZONE).getMillis()) .build(); try (FunctionAssertions localAssertion = new FunctionAssertions(localSession)) { - localAssertion.assertFunctionString("CURRENT_TIMESTAMP", TIMESTAMP_WITH_TIME_ZONE, "2017-03-01 14:30:00.000 Asia/Kabul"); - localAssertion.assertFunctionString("NOW()", TIMESTAMP_WITH_TIME_ZONE, "2017-03-01 14:30:00.000 Asia/Kabul"); + localAssertion.assertFunctionString("CURRENT_TIMESTAMP", TIMESTAMP_WITH_TIME_ZONE, "2017-03-01 14:30:00.000 " + DATE_TIME_ZONE.getID()); + localAssertion.assertFunctionString("NOW()", TIMESTAMP_WITH_TIME_ZONE, "2017-03-01 14:30:00.000 " + DATE_TIME_ZONE.getID()); } } } diff --git a/presto-main/src/test/java/com/facebook/presto/operator/scalar/TestDateTimeFunctionsBase.java b/presto-main/src/test/java/com/facebook/presto/operator/scalar/TestDateTimeFunctionsBase.java index 1459e4697993..e32fd4fac870 100644 --- a/presto-main/src/test/java/com/facebook/presto/operator/scalar/TestDateTimeFunctionsBase.java +++ b/presto-main/src/test/java/com/facebook/presto/operator/scalar/TestDateTimeFunctionsBase.java @@ -26,6 +26,7 @@ import com.facebook.presto.spi.type.TimestampType; import com.facebook.presto.spi.type.Type; import com.facebook.presto.testing.TestingConnectorSession; +import com.facebook.presto.testing.TestingSession; import com.facebook.presto.type.SqlIntervalDayTime; import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableMap; @@ -85,10 +86,10 @@ public abstract class TestDateTimeFunctionsBase extends AbstractTestFunctions { - protected static final TimeZoneKey TIME_ZONE_KEY = getTimeZoneKey("Asia/Kabul"); + protected static final TimeZoneKey TIME_ZONE_KEY = TestingSession.DEFAULT_TIME_ZONE_KEY; protected static final DateTimeZone DATE_TIME_ZONE = getDateTimeZone(TIME_ZONE_KEY); protected static final DateTimeZone UTC_TIME_ZONE = getDateTimeZone(UTC_KEY); - protected static final DateTimeZone DATE_TIME_ZONE_NUMERICAL = getDateTimeZone(getTimeZoneKey("+04:30")); + protected static final DateTimeZone DATE_TIME_ZONE_NUMERICAL = getDateTimeZone(getTimeZoneKey("-11:00")); protected static final TimeZoneKey KATHMANDU_ZONE_KEY = getTimeZoneKey("Asia/Kathmandu"); protected static final DateTimeZone KATHMANDU_ZONE = getDateTimeZone(KATHMANDU_ZONE_KEY); protected static final ZoneOffset WEIRD_ZONE = ZoneOffset.ofHoursMinutes(7, 9); @@ -107,7 +108,7 @@ public abstract class TestDateTimeFunctionsBase protected static final DateTime LEGACY_TIMESTAMP = new DateTime(2001, 8, 22, 3, 4, 5, 321, DATE_TIME_ZONE); protected static final DateTime TIMESTAMP_WITH_NUMERICAL_ZONE = new DateTime(2001, 8, 22, 3, 4, 5, 321, DATE_TIME_ZONE_NUMERICAL); protected static final String TIMESTAMP_LITERAL = "TIMESTAMP '2001-08-22 03:04:05.321'"; - protected static final String TIMESTAMP_ISO8601_STRING = "2001-08-22T03:04:05.321+04:30"; + protected static final String TIMESTAMP_ISO8601_STRING = "2001-08-22T03:04:05.321-11:00"; protected static final String TIMESTAMP_ISO8601_STRING_NO_TIME_ZONE = "2001-08-22T03:04:05.321"; protected static final DateTime WEIRD_TIMESTAMP = new DateTime(2001, 8, 22, 3, 4, 5, 321, WEIRD_DATE_TIME_ZONE); protected static final String WEIRD_TIMESTAMP_LITERAL = "TIMESTAMP '2001-08-22 03:04:05.321 +07:09'"; @@ -278,9 +279,9 @@ public void testPartFunctions() assertFunction("month(" + TIMESTAMP_LITERAL + ")", BIGINT, (long) TIMESTAMP.getMonthOfYear()); assertFunction("quarter(" + TIMESTAMP_LITERAL + ")", BIGINT, (long) TIMESTAMP.getMonthOfYear() / 4 + 1); assertFunction("year(" + TIMESTAMP_LITERAL + ")", BIGINT, (long) TIMESTAMP.getYear()); - assertFunction("timezone_hour(" + TIMESTAMP_LITERAL + ")", BIGINT, 4L); - assertFunction("timezone_hour(localtimestamp)", BIGINT, 4L); - assertFunction("timezone_hour(current_timestamp)", BIGINT, 4L); + assertFunction("timezone_hour(" + TIMESTAMP_LITERAL + ")", BIGINT, -11L); + assertFunction("timezone_hour(localtimestamp)", BIGINT, 14L); + assertFunction("timezone_hour(current_timestamp)", BIGINT, 14L); assertFunction("second(" + WEIRD_TIMESTAMP_LITERAL + ")", BIGINT, (long) WEIRD_TIMESTAMP.getSecondOfMinute()); assertFunction("minute(" + WEIRD_TIMESTAMP_LITERAL + ")", BIGINT, (long) WEIRD_TIMESTAMP.getMinuteOfHour()); @@ -560,6 +561,7 @@ public void testAddFieldToTimestamp() @Test public void testAddFieldToDate() { + assertFunction("date_add('day', 0, " + DATE_LITERAL + ")", DateType.DATE, toDate(DATE)); assertFunction("date_add('day', 3, " + DATE_LITERAL + ")", DateType.DATE, toDate(DATE.plusDays(3))); assertFunction("date_add('week', 3, " + DATE_LITERAL + ")", DateType.DATE, toDate(DATE.plusWeeks(3))); assertFunction("date_add('month', 3, " + DATE_LITERAL + ")", DateType.DATE, toDate(DATE.plusMonths(3))); @@ -570,6 +572,7 @@ public void testAddFieldToDate() @Test public void testAddFieldToTime() { + assertFunction("date_add('millisecond', 0, " + TIME_LITERAL + ")", TimeType.TIME, toTime(TIME)); assertFunction("date_add('millisecond', 3, " + TIME_LITERAL + ")", TimeType.TIME, toTime(TIME.plusNanos(3_000_000))); assertFunction("date_add('second', 3, " + TIME_LITERAL + ")", TimeType.TIME, toTime(TIME.plusSeconds(3))); assertFunction("date_add('minute', 3, " + TIME_LITERAL + ")", TimeType.TIME, toTime(TIME.plusMinutes(3))); @@ -1022,10 +1025,11 @@ public void testTimeWithTimeZoneAtTimeZone() TIME_WITH_TIME_ZONE, new SqlTimeWithTimeZone(new DateTime(1970, 1, 1, 4, 15, 0, 0, UTC_TIME_ZONE).getMillis(), TimeZoneKey.UTC_KEY)); - // Noop on Asia/Kabul + // Noop when time zone doesn't change + TimeZoneKey kabul = TimeZoneKey.getTimeZoneKey("Asia/Kabul"); assertFunction("at_timezone(TIME '10:00 Asia/Kabul', 'Asia/Kabul')", TIME_WITH_TIME_ZONE, - new SqlTimeWithTimeZone(new DateTime(1970, 1, 1, 10, 0, 0, 0, DATE_TIME_ZONE).getMillis(), TIME_ZONE_KEY)); + new SqlTimeWithTimeZone(new DateTime(1970, 1, 1, 10, 0, 0, 0, getDateTimeZone(kabul)).getMillis(), kabul)); // This test checks if the TZ offset isn't calculated on other fixed point in time by checking if // session started in 1980 would get historical Asia/Kathmandu offset. diff --git a/presto-main/src/test/java/com/facebook/presto/operator/scalar/TestDateTimeFunctionsLegacy.java b/presto-main/src/test/java/com/facebook/presto/operator/scalar/TestDateTimeFunctionsLegacy.java index 6027d7f60f4d..77cfd0699f6f 100644 --- a/presto-main/src/test/java/com/facebook/presto/operator/scalar/TestDateTimeFunctionsLegacy.java +++ b/presto-main/src/test/java/com/facebook/presto/operator/scalar/TestDateTimeFunctionsLegacy.java @@ -42,7 +42,7 @@ public void testToIso8601ForTimestampWithoutTimeZone() @Test public void testFormatDateCanImplicitlyAddTimeZoneToTimestampLiteral() { - assertFunction("format_datetime(" + TIMESTAMP_LITERAL + ", 'YYYY/MM/dd HH:mm ZZZZ')", VARCHAR, "2001/08/22 03:04 Asia/Kabul"); + assertFunction("format_datetime(" + TIMESTAMP_LITERAL + ", 'YYYY/MM/dd HH:mm ZZZZ')", VARCHAR, "2001/08/22 03:04 " + DATE_TIME_ZONE.getID()); } @Test @@ -52,7 +52,7 @@ public void testLocalTime() .setStartTime(new DateTime(2017, 3, 1, 14, 30, 0, 0, DATE_TIME_ZONE).getMillis()) .build(); try (FunctionAssertions localAssertion = new FunctionAssertions(localSession)) { - localAssertion.assertFunctionString("LOCALTIME", TimeType.TIME, "14:30:00.000"); + localAssertion.assertFunctionString("LOCALTIME", TimeType.TIME, "13:30:00.000"); } } @@ -88,8 +88,8 @@ public void testCurrentTimestamp() .setStartTime(new DateTime(2017, 3, 1, 14, 30, 0, 0, DATE_TIME_ZONE).getMillis()) .build(); try (FunctionAssertions localAssertion = new FunctionAssertions(localSession)) { - localAssertion.assertFunctionString("CURRENT_TIMESTAMP", TIMESTAMP_WITH_TIME_ZONE, "2017-03-01 14:30:00.000 Asia/Kabul"); - localAssertion.assertFunctionString("NOW()", TIMESTAMP_WITH_TIME_ZONE, "2017-03-01 14:30:00.000 Asia/Kabul"); + localAssertion.assertFunctionString("CURRENT_TIMESTAMP", TIMESTAMP_WITH_TIME_ZONE, "2017-03-01 14:30:00.000 " + DATE_TIME_ZONE.getID()); + localAssertion.assertFunctionString("NOW()", TIMESTAMP_WITH_TIME_ZONE, "2017-03-01 14:30:00.000 " + DATE_TIME_ZONE.getID()); } } } diff --git a/presto-main/src/test/java/com/facebook/presto/sql/TestExpressionInterpreter.java b/presto-main/src/test/java/com/facebook/presto/sql/TestExpressionInterpreter.java index 5cde022cb9d2..d3324e949312 100644 --- a/presto-main/src/test/java/com/facebook/presto/sql/TestExpressionInterpreter.java +++ b/presto-main/src/test/java/com/facebook/presto/sql/TestExpressionInterpreter.java @@ -72,6 +72,7 @@ import static com.facebook.presto.sql.planner.ExpressionInterpreter.expressionInterpreter; import static com.facebook.presto.sql.planner.ExpressionInterpreter.expressionOptimizer; import static com.facebook.presto.type.IntervalDayTimeType.INTERVAL_DAY_TIME; +import static com.facebook.presto.util.DateTimeZoneIndex.getDateTimeZone; import static io.airlift.slice.Slices.utf8Slice; import static java.lang.String.format; import static java.util.Collections.emptyList; @@ -374,7 +375,7 @@ public void testBetween() @Test public void testExtract() { - DateTime dateTime = new DateTime(2001, 8, 22, 3, 4, 5, 321, DateTimeZone.UTC); + DateTime dateTime = new DateTime(2001, 8, 22, 3, 4, 5, 321, getDateTimeZone(TEST_SESSION.getTimeZoneKey())); double seconds = dateTime.getMillis() / 1000.0; assertOptimizedEquals("extract (YEAR from from_unixtime(" + seconds + "))", "2001"); @@ -394,10 +395,10 @@ public void testExtract() assertOptimizedEquals("extract (QUARTER from bound_timestamp)", "3"); assertOptimizedEquals("extract (MONTH from bound_timestamp)", "8"); assertOptimizedEquals("extract (WEEK from bound_timestamp)", "34"); - assertOptimizedEquals("extract (DOW from bound_timestamp)", "3"); - assertOptimizedEquals("extract (DOY from bound_timestamp)", "234"); - assertOptimizedEquals("extract (DAY from bound_timestamp)", "22"); - assertOptimizedEquals("extract (HOUR from bound_timestamp)", "3"); + assertOptimizedEquals("extract (DOW from bound_timestamp)", "2"); + assertOptimizedEquals("extract (DOY from bound_timestamp)", "233"); + assertOptimizedEquals("extract (DAY from bound_timestamp)", "21"); + assertOptimizedEquals("extract (HOUR from bound_timestamp)", "16"); assertOptimizedEquals("extract (MINUTE from bound_timestamp)", "4"); assertOptimizedEquals("extract (SECOND from bound_timestamp)", "5"); // todo reenable when cast as timestamp with time zone is implemented diff --git a/presto-main/src/test/java/com/facebook/presto/sql/gen/TestExpressionCompiler.java b/presto-main/src/test/java/com/facebook/presto/sql/gen/TestExpressionCompiler.java index 3bc4e344549c..cd9bc6a05e12 100644 --- a/presto-main/src/test/java/com/facebook/presto/sql/gen/TestExpressionCompiler.java +++ b/presto-main/src/test/java/com/facebook/presto/sql/gen/TestExpressionCompiler.java @@ -84,6 +84,7 @@ import static com.facebook.presto.testing.DateTimeTestingUtils.sqlTimestampOf; import static com.facebook.presto.type.JsonType.JSON; import static com.facebook.presto.type.UnknownType.UNKNOWN; +import static com.facebook.presto.util.DateTimeZoneIndex.getDateTimeZone; import static com.facebook.presto.util.StructuralTestUtil.mapType; import static com.google.common.util.concurrent.MoreExecutors.listeningDecorator; import static com.google.common.util.concurrent.MoreExecutors.newDirectExecutorService; @@ -95,6 +96,7 @@ import static java.lang.String.format; import static java.util.Collections.singletonList; import static java.util.concurrent.Executors.newFixedThreadPool; +import static java.util.concurrent.TimeUnit.MILLISECONDS; import static java.util.stream.Collectors.joining; import static java.util.stream.IntStream.range; import static org.joda.time.DateTimeZone.UTC; @@ -1460,7 +1462,14 @@ public void testExtract() millis = left.getMillis(); expected = callExtractFunction(TEST_SESSION.toConnectorSession(), millis, field); } - assertExecute(generateExpression("extract(" + field.toString() + " from from_unixtime(%s / 1000.0E0, 0, 0))", millis), BIGINT, expected); + DateTimeZone zone = getDateTimeZone(TEST_SESSION.getTimeZoneKey()); + long zoneOffsetMinutes = millis != null ? MILLISECONDS.toMinutes(zone.getOffset(millis)) : 0; + String expressionPattern = format( + "extract(%s from from_unixtime(%%s / 1000.0E0, %s, %s))", + field, + zoneOffsetMinutes / 60, + zoneOffsetMinutes % 60); + assertExecute(generateExpression(expressionPattern, millis), BIGINT, expected); } } diff --git a/presto-main/src/test/java/com/facebook/presto/type/TestTimeBase.java b/presto-main/src/test/java/com/facebook/presto/type/TestTimeBase.java index 909499d0e911..036ca96ba7e6 100644 --- a/presto-main/src/test/java/com/facebook/presto/type/TestTimeBase.java +++ b/presto-main/src/test/java/com/facebook/presto/type/TestTimeBase.java @@ -20,6 +20,7 @@ import com.facebook.presto.spi.type.SqlTimestampWithTimeZone; import com.facebook.presto.spi.type.TimeZoneKey; import com.facebook.presto.sql.analyzer.SemanticErrorCode; +import com.facebook.presto.testing.TestingSession; import org.joda.time.DateTime; import org.joda.time.DateTimeZone; import org.testng.annotations.Test; @@ -41,7 +42,7 @@ public abstract class TestTimeBase extends AbstractTestFunctions { - protected static final TimeZoneKey TIME_ZONE_KEY = getTimeZoneKey("Europe/Berlin"); + protected static final TimeZoneKey TIME_ZONE_KEY = TestingSession.DEFAULT_TIME_ZONE_KEY; protected static final DateTimeZone DATE_TIME_ZONE = getDateTimeZone(TIME_ZONE_KEY); public TestTimeBase(boolean legacyTimestamp) diff --git a/presto-main/src/test/java/com/facebook/presto/type/TestTimestampBase.java b/presto-main/src/test/java/com/facebook/presto/type/TestTimestampBase.java index 1094815b4c84..cf4634ab669c 100644 --- a/presto-main/src/test/java/com/facebook/presto/type/TestTimestampBase.java +++ b/presto-main/src/test/java/com/facebook/presto/type/TestTimestampBase.java @@ -19,6 +19,7 @@ import com.facebook.presto.spi.type.SqlTimestampWithTimeZone; import com.facebook.presto.spi.type.TimeZoneKey; import com.facebook.presto.sql.analyzer.SemanticErrorCode; +import com.facebook.presto.testing.TestingSession; import org.joda.time.DateTime; import org.joda.time.DateTimeZone; import org.testng.annotations.Test; @@ -45,7 +46,7 @@ public abstract class TestTimestampBase extends AbstractTestFunctions { - protected static final TimeZoneKey TIME_ZONE_KEY = getTimeZoneKey("Europe/Berlin"); + protected static final TimeZoneKey TIME_ZONE_KEY = TestingSession.DEFAULT_TIME_ZONE_KEY; protected static final DateTimeZone DATE_TIME_ZONE = getDateTimeZone(TIME_ZONE_KEY); protected static final TimeZoneKey WEIRD_TIME_ZONE_KEY = getTimeZoneKeyForOffset(7 * 60 + 9); protected static final DateTimeZone WEIRD_ZONE = getDateTimeZone(WEIRD_TIME_ZONE_KEY); @@ -194,7 +195,7 @@ public void testCastToTimeWithTimeZone() new SqlTimeWithTimeZone(new DateTime(1970, 1, 1, 3, 4, 5, 321, DATE_TIME_ZONE).getMillis(), TIME_ZONE_KEY)); functionAssertions.assertFunctionString("cast(TIMESTAMP '2001-1-22 03:04:05.321' as time with time zone)", TIME_WITH_TIME_ZONE, - "03:04:05.321 Europe/Berlin"); + "03:04:05.321 " + DATE_TIME_ZONE.getID()); } @Test @@ -205,7 +206,7 @@ public void testCastToTimestampWithTimeZone() new SqlTimestampWithTimeZone(new DateTime(2001, 1, 22, 3, 4, 5, 321, DATE_TIME_ZONE).getMillis(), DATE_TIME_ZONE.toTimeZone())); functionAssertions.assertFunctionString("cast(TIMESTAMP '2001-1-22 03:04:05.321' as timestamp with time zone)", TIMESTAMP_WITH_TIME_ZONE, - "2001-01-22 03:04:05.321 Europe/Berlin"); + "2001-01-22 03:04:05.321 " + DATE_TIME_ZONE.getID()); } @Test diff --git a/presto-main/src/test/java/com/facebook/presto/type/TestTimestampLegacy.java b/presto-main/src/test/java/com/facebook/presto/type/TestTimestampLegacy.java index 7dd58635e1dd..cfab5201f2f5 100644 --- a/presto-main/src/test/java/com/facebook/presto/type/TestTimestampLegacy.java +++ b/presto-main/src/test/java/com/facebook/presto/type/TestTimestampLegacy.java @@ -31,35 +31,35 @@ public void testCastFromSlice() assertFunction( "cast('2001-1-22 03:04:05.321 +07:09' as timestamp)", TIMESTAMP, - sqlTimestampOf(2001, 1, 21, 20, 55, 5, 321, session)); + sqlTimestampOf(2001, 1, 21, 8, 55, 5, 321, session)); assertFunction( "cast('2001-1-22 03:04:05 +07:09' as timestamp)", TIMESTAMP, - sqlTimestampOf(2001, 1, 21, 20, 55, 5, 0, session)); + sqlTimestampOf(2001, 1, 21, 8, 55, 5, 0, session)); assertFunction( "cast('2001-1-22 03:04 +07:09' as timestamp)", TIMESTAMP, - sqlTimestampOf(2001, 1, 21, 20, 55, 0, 0, session)); + sqlTimestampOf(2001, 1, 21, 8, 55, 0, 0, session)); assertFunction( "cast('2001-1-22 +07:09' as timestamp)", TIMESTAMP, - sqlTimestampOf(2001, 1, 21, 17, 51, 0, 0, session)); + sqlTimestampOf(2001, 1, 21, 5, 51, 0, 0, session)); assertFunction( "cast('2001-1-22 03:04:05.321 Asia/Oral' as timestamp)", TIMESTAMP, - sqlTimestampOf(2001, 1, 22, 0, 4, 5, 321, session)); + sqlTimestampOf(2001, 1, 21, 12, 4, 5, 321, session)); assertFunction( "cast('2001-1-22 03:04:05 Asia/Oral' as timestamp)", TIMESTAMP, - sqlTimestampOf(2001, 1, 22, 0, 4, 5, 0, session)); + sqlTimestampOf(2001, 1, 21, 12, 4, 5, 0, session)); assertFunction( "cast('2001-1-22 03:04 Asia/Oral' as timestamp)", TIMESTAMP, - sqlTimestampOf(2001, 1, 22, 0, 4, 0, 0, session)); + sqlTimestampOf(2001, 1, 21, 12, 4, 0, 0, session)); assertFunction( "cast('2001-1-22 Asia/Oral' as timestamp)", TIMESTAMP, - sqlTimestampOf(2001, 1, 21, 21, 0, 0, 0, session)); + sqlTimestampOf(2001, 1, 21, 9, 0, 0, 0, session)); } } diff --git a/presto-raptor/src/test/java/com/facebook/presto/raptor/TestRaptorIntegrationSmokeTest.java b/presto-raptor/src/test/java/com/facebook/presto/raptor/TestRaptorIntegrationSmokeTest.java index 5a70912b3a4d..9378f647ff9d 100644 --- a/presto-raptor/src/test/java/com/facebook/presto/raptor/TestRaptorIntegrationSmokeTest.java +++ b/presto-raptor/src/test/java/com/facebook/presto/raptor/TestRaptorIntegrationSmokeTest.java @@ -239,7 +239,7 @@ public void testShardingByTemporalTimestampColumn() assertUpdate(joiner.toString(), format("VALUES(%s)", rows)); - MaterializedResult results = computeActual("SELECT format_datetime(col2, 'yyyyMMdd'), \"$shard_uuid\" FROM test_shard_temporal_timestamp"); + MaterializedResult results = computeActual("SELECT format_datetime(col2 AT TIME ZONE 'UTC', 'yyyyMMdd'), \"$shard_uuid\" FROM test_shard_temporal_timestamp"); assertEquals(results.getRowCount(), rows); // Each shard will only contain data of one date. @@ -272,7 +272,7 @@ public void testShardingByTemporalTimestampColumnBucketed() assertUpdate(joiner.toString(), format("VALUES(%s)", rows)); MaterializedResult results = computeActual("" + - "SELECT format_datetime(col2, 'yyyyMMdd'), \"$shard_uuid\" " + + "SELECT format_datetime(col2 AT TIME ZONE 'UTC', 'yyyyMMdd'), \"$shard_uuid\" " + "FROM test_shard_temporal_timestamp_bucketed"); assertEquals(results.getRowCount(), rows); diff --git a/presto-teradata-functions/src/test/java/com/facebook/presto/teradata/functions/TestTeradataDateFunctions.java b/presto-teradata-functions/src/test/java/com/facebook/presto/teradata/functions/TestTeradataDateFunctions.java index 0ee6cedb932f..1b626233e782 100644 --- a/presto-teradata-functions/src/test/java/com/facebook/presto/teradata/functions/TestTeradataDateFunctions.java +++ b/presto-teradata-functions/src/test/java/com/facebook/presto/teradata/functions/TestTeradataDateFunctions.java @@ -17,7 +17,6 @@ import com.facebook.presto.operator.scalar.AbstractTestFunctions; import com.facebook.presto.spi.type.DateType; import com.facebook.presto.spi.type.SqlDate; -import com.facebook.presto.spi.type.TimeZoneKey; import com.facebook.presto.spi.type.TimestampType; import org.joda.time.DateTime; import org.testng.annotations.BeforeClass; @@ -26,7 +25,6 @@ import java.time.LocalDate; import static com.facebook.presto.metadata.FunctionExtractor.extractFunctions; -import static com.facebook.presto.spi.type.TimeZoneKey.getTimeZoneKey; import static com.facebook.presto.spi.type.VarcharType.VARCHAR; import static com.facebook.presto.testing.DateTimeTestingUtils.sqlTimestampOf; import static com.facebook.presto.testing.TestingSession.testSessionBuilder; @@ -35,11 +33,9 @@ public class TestTeradataDateFunctions extends AbstractTestFunctions { - private static final TimeZoneKey TIME_ZONE_KEY = getTimeZoneKey("Asia/Kathmandu"); private static final Session SESSION = testSessionBuilder() .setCatalog("catalog") .setSchema("schema") - .setTimeZoneKey(TIME_ZONE_KEY) .build(); protected TestTeradataDateFunctions() diff --git a/presto-tests/src/main/java/com/facebook/presto/tests/AbstractTestAggregations.java b/presto-tests/src/main/java/com/facebook/presto/tests/AbstractTestAggregations.java index 9a15c0d97932..25529183611c 100644 --- a/presto-tests/src/main/java/com/facebook/presto/tests/AbstractTestAggregations.java +++ b/presto-tests/src/main/java/com/facebook/presto/tests/AbstractTestAggregations.java @@ -687,20 +687,20 @@ public void testApproximateCountDistinct() assertQuery("SELECT approx_distinct(orderdate, 0.023) FROM orders", "SELECT 2443"); // test timestamp - assertQuery("SELECT approx_distinct(CAST(orderdate AS TIMESTAMP)) FROM orders", "SELECT 2384"); - assertQuery("SELECT approx_distinct(CAST(orderdate AS TIMESTAMP), 0.023) FROM orders", "SELECT 2384"); + assertQuery("SELECT approx_distinct(CAST(orderdate AS TIMESTAMP)) FROM orders", "SELECT 2347"); + assertQuery("SELECT approx_distinct(CAST(orderdate AS TIMESTAMP), 0.023) FROM orders", "SELECT 2347"); // test timestamp with time zone - assertQuery("SELECT approx_distinct(CAST((orderdate) AS TIMESTAMP WITH TIME ZONE)) FROM orders", "SELECT 2384"); - assertQuery("SELECT approx_distinct(CAST((orderdate) AS TIMESTAMP WITH TIME ZONE), 0.023) FROM orders", "SELECT 2384"); + assertQuery("SELECT approx_distinct(CAST(orderdate AS TIMESTAMP WITH TIME ZONE)) FROM orders", "SELECT 2347"); + assertQuery("SELECT approx_distinct(CAST(orderdate AS TIMESTAMP WITH TIME ZONE), 0.023) FROM orders", "SELECT 2347"); // test time - assertQuery("SELECT approx_distinct(CAST(from_unixtime(custkey) AS TIME)) FROM orders", "SELECT 993"); - assertQuery("SELECT approx_distinct(CAST(from_unixtime(custkey) AS TIME), 0.023) FROM orders", "SELECT 993"); + assertQuery("SELECT approx_distinct(CAST(from_unixtime(custkey) AS TIME)) FROM orders", "SELECT 996"); + assertQuery("SELECT approx_distinct(CAST(from_unixtime(custkey) AS TIME), 0.023) FROM orders", "SELECT 996"); // test time with time zone - assertQuery("SELECT approx_distinct(CAST(from_unixtime(custkey) AS TIME WITH TIME ZONE)) FROM orders", "SELECT 993"); - assertQuery("SELECT approx_distinct(CAST(from_unixtime(custkey) AS TIME WITH TIME ZONE), 0.023) FROM orders", "SELECT 993"); + assertQuery("SELECT approx_distinct(CAST(from_unixtime(custkey) AS TIME WITH TIME ZONE)) FROM orders", "SELECT 996"); + assertQuery("SELECT approx_distinct(CAST(from_unixtime(custkey) AS TIME WITH TIME ZONE), 0.023) FROM orders", "SELECT 996"); // test short decimal assertQuery("SELECT approx_distinct(CAST(custkey AS DECIMAL(18, 0))) FROM orders", "SELECT 990"); diff --git a/presto-tests/src/main/java/com/facebook/presto/tests/AbstractTestQueries.java b/presto-tests/src/main/java/com/facebook/presto/tests/AbstractTestQueries.java index a2ad80f92711..873422ca210c 100644 --- a/presto-tests/src/main/java/com/facebook/presto/tests/AbstractTestQueries.java +++ b/presto-tests/src/main/java/com/facebook/presto/tests/AbstractTestQueries.java @@ -4707,28 +4707,28 @@ public void testShowColumns() public void testAtTimeZone() { // TODO the expected values here are non-sensical due to https://github.com/prestodb/presto/issues/7122 - assertEquals(computeScalar("SELECT TIMESTAMP '2012-10-31 01:00' AT TIME ZONE INTERVAL '07:09' hour to minute"), zonedDateTime("2012-10-31 08:09:00.000 +07:09")); - assertEquals(computeScalar("SELECT TIMESTAMP '2012-10-31 01:00' AT TIME ZONE 'Asia/Oral'"), zonedDateTime("2012-10-31 06:00:00.000 Asia/Oral")); + 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")); + assertEquals(computeScalar("SELECT TIMESTAMP '2012-10-31 01:00' AT TIME ZONE 'Asia/Oral'"), zonedDateTime("2012-10-30 16:00:00.000 Asia/Oral")); 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")); - assertEquals(computeScalar("SELECT TIMESTAMP '2012-10-31 01:00' AT TIME ZONE '+07:09'"), zonedDateTime("2012-10-31 08:09:00.000 +07:09")); + assertEquals(computeScalar("SELECT TIMESTAMP '2012-10-31 01:00' AT TIME ZONE '+07:09'"), zonedDateTime("2012-10-30 18:09:00.000 +07:09")); assertEquals(computeScalar("SELECT TIMESTAMP '2012-10-31 01:00 UTC' AT TIME ZONE 'America/Los_Angeles'"), zonedDateTime("2012-10-30 18:00:00.000 America/Los_Angeles")); - assertEquals(computeScalar("SELECT TIMESTAMP '2012-10-31 01:00' AT TIME ZONE 'America/Los_Angeles'"), zonedDateTime("2012-10-30 18:00:00.000 America/Los_Angeles")); + assertEquals(computeScalar("SELECT TIMESTAMP '2012-10-31 01:00' AT TIME ZONE 'America/Los_Angeles'"), zonedDateTime("2012-10-30 04:00:00.000 America/Los_Angeles")); assertEquals(computeActual("SELECT x AT TIME ZONE 'America/Los_Angeles' FROM (values TIMESTAMP '1970-01-01 00:01:00+00:00', TIMESTAMP '1970-01-01 08:01:00+08:00', TIMESTAMP '1969-12-31 16:01:00-08:00') t(x)").getOnlyColumnAsSet(), ImmutableSet.of(zonedDateTime("1969-12-31 16:01:00.000 America/Los_Angeles"))); assertEquals(computeActual("SELECT x AT TIME ZONE 'America/Los_Angeles' FROM (values TIMESTAMP '1970-01-01 00:01:00', TIMESTAMP '1970-01-01 08:01:00', TIMESTAMP '1969-12-31 16:01:00') t(x)").getOnlyColumn().collect(toList()), - ImmutableList.of(zonedDateTime("1969-12-31 16:01:00.000 America/Los_Angeles"), zonedDateTime("1970-01-01 00:01:00.000 America/Los_Angeles"), zonedDateTime("1969-12-31 08:01:00.000 America/Los_Angeles"))); + ImmutableList.of(zonedDateTime("1970-01-01 03:01:00.000 America/Los_Angeles"), zonedDateTime("1970-01-01 11:01:00.000 America/Los_Angeles"), zonedDateTime("1969-12-31 19:01:00.000 America/Los_Angeles"))); assertEquals(computeScalar("SELECT min(x) AT TIME ZONE 'America/Los_Angeles' FROM (values TIMESTAMP '1970-01-01 00:01:00+00:00', TIMESTAMP '1970-01-01 08:01:00+08:00', TIMESTAMP '1969-12-31 16:01:00-08:00') t(x)"), zonedDateTime("1969-12-31 16:01:00.000 America/Los_Angeles")); // with chained AT TIME ZONE - assertEquals(computeScalar("SELECT TIMESTAMP '2012-10-31 01:00' AT TIME ZONE 'America/Los_Angeles' AT TIME ZONE 'UTC'"), zonedDateTime("2012-10-31 01:00:00.000 UTC")); - assertEquals(computeScalar("SELECT TIMESTAMP '2012-10-31 01:00' AT TIME ZONE 'Asia/Tokyo' AT TIME ZONE 'America/Los_Angeles'"), zonedDateTime("2012-10-30 18:00:00.000 America/Los_Angeles")); - assertEquals(computeScalar("SELECT TIMESTAMP '2012-10-31 01:00' AT TIME ZONE 'America/Los_Angeles' AT TIME ZONE 'Asia/Shanghai'"), zonedDateTime("2012-10-31 09:00:00.000 Asia/Shanghai")); + assertEquals(computeScalar("SELECT TIMESTAMP '2012-10-31 01:00' AT TIME ZONE 'America/Los_Angeles' AT TIME ZONE 'UTC'"), zonedDateTime("2012-10-30 11:00:00.000 UTC")); + assertEquals(computeScalar("SELECT TIMESTAMP '2012-10-31 01:00' AT TIME ZONE 'Asia/Tokyo' AT TIME ZONE 'America/Los_Angeles'"), zonedDateTime("2012-10-30 04:00:00.000 America/Los_Angeles")); + assertEquals(computeScalar("SELECT TIMESTAMP '2012-10-31 01:00' AT TIME ZONE 'America/Los_Angeles' AT TIME ZONE 'Asia/Shanghai'"), zonedDateTime("2012-10-30 19:00:00.000 Asia/Shanghai")); assertEquals(computeScalar("SELECT min(x) AT TIME ZONE 'America/Los_Angeles' AT TIME ZONE 'UTC' FROM (values TIMESTAMP '1970-01-01 00:01:00+00:00', TIMESTAMP '1970-01-01 08:01:00+08:00', TIMESTAMP '1969-12-31 16:01:00-08:00') t(x)"), zonedDateTime("1970-01-01 00:01:00.000 UTC")); // with AT TIME ZONE in VALUES - assertEquals(computeScalar("SELECT * FROM (VALUES TIMESTAMP '2012-10-31 01:00' AT TIME ZONE 'Asia/Oral')"), zonedDateTime("2012-10-31 06:00:00.000 Asia/Oral")); + assertEquals(computeScalar("SELECT * FROM (VALUES TIMESTAMP '2012-10-31 01:00' AT TIME ZONE 'Asia/Oral')"), zonedDateTime("2012-10-30 16:00:00.000 Asia/Oral")); } private ZonedDateTime zonedDateTime(String value)