From 7718da3beb8da2259c7369c16c5e7ebc4e01996f Mon Sep 17 00:00:00 2001 From: Piotr Findeisen Date: Fri, 29 Jun 2018 12:04:10 +0200 Subject: [PATCH] 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 849a65fd63fb..51cfcc9f8a79 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 6724c794dde7..e98b6b483a74 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 93f82def99ae..ea89e4a4af4f 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 @@ -106,7 +106,7 @@ public class TestHiveFileFormats private static TestingConnectorSession parquetPageSourceSession = new TestingConnectorSession(new HiveSessionProperties(new HiveClientConfig().setParquetOptimizedReaderEnabled(true).setParquetPredicatePushdownEnabled(false), new OrcFileWriterConfig()).getSessionProperties()); private static TestingConnectorSession parquetPageSourcePushdown = new TestingConnectorSession(new HiveSessionProperties(new HiveClientConfig().setParquetOptimizedReaderEnabled(true).setParquetPredicatePushdownEnabled(true), new OrcFileWriterConfig()).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() @@ -119,8 +119,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 e48457fa59bb..86f8ca757358 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 @@ -108,7 +108,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 = getHiveClientConfig(); 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 d135ad108bd1..bbf7af14c87f 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 e33e609922d5..02a50acf68d2 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 @@ -168,7 +168,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 24a07a9a7839..f25faac80483 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());