From bb460c0b3a3b7857e0484a0960eee28b29680534 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Osipiuk?= Date: Thu, 27 Aug 2020 14:18:38 +0200 Subject: [PATCH] Guard JDBC tests against Presto server version --- .../prestosql/jdbc/BaseTestJdbcResultSet.java | 77 +++++++++++-------- .../io/prestosql/jdbc/TestJdbcResultSet.java | 7 ++ 2 files changed, 54 insertions(+), 30 deletions(-) diff --git a/presto-jdbc/src/test/java/io/prestosql/jdbc/BaseTestJdbcResultSet.java b/presto-jdbc/src/test/java/io/prestosql/jdbc/BaseTestJdbcResultSet.java index 45fe143112e6..c857c5ac2e8c 100644 --- a/presto-jdbc/src/test/java/io/prestosql/jdbc/BaseTestJdbcResultSet.java +++ b/presto-jdbc/src/test/java/io/prestosql/jdbc/BaseTestJdbcResultSet.java @@ -14,6 +14,7 @@ package io.prestosql.jdbc; import com.google.common.collect.ImmutableMap; +import io.airlift.log.Logger; import org.testng.annotations.Test; import java.math.BigDecimal; @@ -42,8 +43,12 @@ public abstract class BaseTestJdbcResultSet { + private static final Logger log = Logger.get(BaseTestJdbcResultSet.class); + protected abstract Connection createConnection() throws SQLException; + protected abstract int getTestedPrestoServerVersion(); + @Test public void testDuplicateColumnLabels() throws Exception @@ -202,19 +207,23 @@ public void testTimestamp() assertEquals(rs.getTimestamp(column), Timestamp.valueOf(LocalDateTime.of(2018, 2, 13, 13, 14, 15, 123_000_000))); }); - checkRepresentation(connectedStatement.getStatement(), "TIMESTAMP '2018-02-13 13:14:15.111111111111'", Types.TIMESTAMP, (rs, column) -> { - assertEquals(rs.getObject(column), Timestamp.valueOf(LocalDateTime.of(2018, 2, 13, 13, 14, 15, 111_111_111))); - assertThrows(() -> rs.getDate(column)); - assertThrows(() -> rs.getTime(column)); - assertEquals(rs.getTimestamp(column), Timestamp.valueOf(LocalDateTime.of(2018, 2, 13, 13, 14, 15, 111_111_111))); - }); + if (serverSupportsVariablePrecisionTimestamp()) { + checkRepresentation(connectedStatement.getStatement(), "TIMESTAMP '2018-02-13 13:14:15.111111111111'", Types.TIMESTAMP, (rs, column) -> { + assertEquals(rs.getObject(column), Timestamp.valueOf(LocalDateTime.of(2018, 2, 13, 13, 14, 15, 111_111_111))); + assertThrows(() -> rs.getDate(column)); + assertThrows(() -> rs.getTime(column)); + assertEquals(rs.getTimestamp(column), Timestamp.valueOf(LocalDateTime.of(2018, 2, 13, 13, 14, 15, 111_111_111))); + }); + } - checkRepresentation(connectedStatement.getStatement(), "TIMESTAMP '2018-02-13 13:14:15.555555555555'", Types.TIMESTAMP, (rs, column) -> { - assertEquals(rs.getObject(column), Timestamp.valueOf(LocalDateTime.of(2018, 2, 13, 13, 14, 15, 555_555_556))); - assertThrows(() -> rs.getDate(column)); - assertThrows(() -> rs.getTime(column)); - assertEquals(rs.getTimestamp(column), Timestamp.valueOf(LocalDateTime.of(2018, 2, 13, 13, 14, 15, 555_555_556))); - }); + if (serverSupportsVariablePrecisionTimestamp()) { + checkRepresentation(connectedStatement.getStatement(), "TIMESTAMP '2018-02-13 13:14:15.555555555555'", Types.TIMESTAMP, (rs, column) -> { + assertEquals(rs.getObject(column), Timestamp.valueOf(LocalDateTime.of(2018, 2, 13, 13, 14, 15, 555_555_556))); + assertThrows(() -> rs.getDate(column)); + assertThrows(() -> rs.getTime(column)); + assertEquals(rs.getTimestamp(column), Timestamp.valueOf(LocalDateTime.of(2018, 2, 13, 13, 14, 15, 555_555_556))); + }); + } // distant past, but apparently not an uncommon value in practice checkRepresentation(connectedStatement.getStatement(), "TIMESTAMP '0001-01-01 00:00:00'", Types.TIMESTAMP, (rs, column) -> { @@ -261,18 +270,14 @@ public void testTimestamp() // ... // }); - // TODO https://github.com/prestosql/presto/issues/4363 -// checkRepresentation(statementWrapper.getStatement(), "TIMESTAMP '-123456-01-23 01:23:45.123456789'", Types.TIMESTAMP, (rs, column) -> { -// ... -// }); - - checkRepresentation(connectedStatement.getStatement(), "TIMESTAMP '123456-01-23 01:23:45.123456789'", Types.TIMESTAMP, (rs, column) -> { - assertEquals(rs.getObject(column), Timestamp.valueOf(LocalDateTime.of(123456, 1, 23, 1, 23, 45, 123_456_789))); - assertThrows(() -> rs.getDate(column)); - assertThrows(() -> rs.getTime(column)); - assertEquals(rs.getTimestamp(column), Timestamp.valueOf(LocalDateTime.of(123456, 1, 23, 1, 23, 45, 123_456_789))); - }); - + if (serverSupportsVariablePrecisionTimestamp()) { + checkRepresentation(connectedStatement.getStatement(), "TIMESTAMP '123456-01-23 01:23:45.123456789'", Types.TIMESTAMP, (rs, column) -> { + assertEquals(rs.getObject(column), Timestamp.valueOf(LocalDateTime.of(123456, 1, 23, 1, 23, 45, 123_456_789))); + assertThrows(() -> rs.getDate(column)); + assertThrows(() -> rs.getTime(column)); + assertEquals(rs.getTimestamp(column), Timestamp.valueOf(LocalDateTime.of(123456, 1, 23, 1, 23, 45, 123_456_789))); + }); + } checkRepresentation(connectedStatement.getStatement(), "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)); @@ -300,12 +305,14 @@ public void testTimestamp() // ... // }); - checkRepresentation(connectedStatement.getStatement(), "TIMESTAMP '12345-01-23 01:23:45.123456789 Europe/Warsaw'", Types.TIMESTAMP /* TODO TIMESTAMP_WITH_TIMEZONE */, (rs, column) -> { - assertEquals(rs.getObject(column), Timestamp.valueOf(LocalDateTime.of(12345, 1, 22, 18, 23, 45, 123_456_789))); // TODO this should contain the zone - assertThrows(() -> rs.getDate(column)); - assertThrows(() -> rs.getTime(column)); - assertEquals(rs.getTimestamp(column), Timestamp.valueOf(LocalDateTime.of(12345, 1, 22, 18, 23, 45, 123_456_789))); - }); + if (serverSupportsVariablePrecisionTimestampWithTimeZone()) { + checkRepresentation(connectedStatement.getStatement(), "TIMESTAMP '12345-01-23 01:23:45.123456789 Europe/Warsaw'", Types.TIMESTAMP /* TODO TIMESTAMP_WITH_TIMEZONE */, (rs, column) -> { + assertEquals(rs.getObject(column), Timestamp.valueOf(LocalDateTime.of(12345, 1, 22, 18, 23, 45, 123_456_789))); // TODO this should contain the zone + assertThrows(() -> rs.getDate(column)); + assertThrows(() -> rs.getTime(column)); + assertEquals(rs.getTimestamp(column), Timestamp.valueOf(LocalDateTime.of(12345, 1, 22, 18, 23, 45, 123_456_789))); + }); + } } } @@ -596,4 +603,14 @@ public Statement getStatement() return statement; } } + + private boolean serverSupportsVariablePrecisionTimestamp() + { + return getTestedPrestoServerVersion() >= 335; + } + + private boolean serverSupportsVariablePrecisionTimestampWithTimeZone() + { + return getTestedPrestoServerVersion() >= 337; + } } diff --git a/presto-jdbc/src/test/java/io/prestosql/jdbc/TestJdbcResultSet.java b/presto-jdbc/src/test/java/io/prestosql/jdbc/TestJdbcResultSet.java index 594292ed77f6..8af6c5ce6dc5 100644 --- a/presto-jdbc/src/test/java/io/prestosql/jdbc/TestJdbcResultSet.java +++ b/presto-jdbc/src/test/java/io/prestosql/jdbc/TestJdbcResultSet.java @@ -50,4 +50,11 @@ protected Connection createConnection() String url = format("jdbc:presto://%s", server.getAddress()); return DriverManager.getConnection(url, "test", null); } + + @Override + protected int getTestedPrestoServerVersion() + { + // Lastest version + return Integer.MAX_VALUE; + } }