From d5dfb31d85ca044d5d84d32049954ac866c7c879 Mon Sep 17 00:00:00 2001 From: David Phillips Date: Sun, 23 Dec 2018 16:53:48 -0800 Subject: [PATCH] Convert JDBC driver from TimeZoneKey to ZoneId --- .../benchmark/driver/BenchmarkDriverOptions.java | 4 ++-- .../main/java/io/prestosql/cli/ClientOptions.java | 4 ++-- .../java/io/prestosql/cli/TestQueryRunner.java | 3 ++- .../java/io/prestosql/client/ClientSession.java | 14 +++++++------- .../java/io/prestosql/client/StatementClient.java | 5 ++--- .../io/prestosql/client/StatementClientV1.java | 6 +++--- .../java/io/prestosql/jdbc/PrestoConnection.java | 11 +++++------ .../tests/AbstractTestingPrestoClient.java | 3 ++- .../io/prestosql/execution/TestFinalQueryInfo.java | 3 ++- 9 files changed, 27 insertions(+), 26 deletions(-) diff --git a/presto-benchmark-driver/src/main/java/io/prestosql/benchmark/driver/BenchmarkDriverOptions.java b/presto-benchmark-driver/src/main/java/io/prestosql/benchmark/driver/BenchmarkDriverOptions.java index 8e73bcf799a0..77adc89f7044 100644 --- a/presto-benchmark-driver/src/main/java/io/prestosql/benchmark/driver/BenchmarkDriverOptions.java +++ b/presto-benchmark-driver/src/main/java/io/prestosql/benchmark/driver/BenchmarkDriverOptions.java @@ -24,13 +24,13 @@ import java.net.URI; import java.net.URISyntaxException; import java.nio.charset.CharsetEncoder; +import java.time.ZoneId; import java.util.ArrayList; import java.util.List; import java.util.Locale; import java.util.Map; import java.util.Objects; import java.util.Optional; -import java.util.TimeZone; import static com.google.common.base.Preconditions.checkArgument; import static java.nio.charset.StandardCharsets.US_ASCII; @@ -97,7 +97,7 @@ public ClientSession getClientSession() catalog, schema, null, - TimeZone.getDefault().getID(), + ZoneId.systemDefault(), Locale.getDefault(), ImmutableMap.of(), toProperties(this.sessionProperties), diff --git a/presto-cli/src/main/java/io/prestosql/cli/ClientOptions.java b/presto-cli/src/main/java/io/prestosql/cli/ClientOptions.java index df603a84a9eb..12f8b0bc1147 100644 --- a/presto-cli/src/main/java/io/prestosql/cli/ClientOptions.java +++ b/presto-cli/src/main/java/io/prestosql/cli/ClientOptions.java @@ -25,6 +25,7 @@ import java.net.URI; import java.net.URISyntaxException; +import java.time.ZoneId; import java.util.ArrayList; import java.util.List; import java.util.Locale; @@ -32,7 +33,6 @@ import java.util.Objects; import java.util.Optional; import java.util.Set; -import java.util.TimeZone; import static com.google.common.base.Preconditions.checkArgument; import static com.google.common.base.Strings.nullToEmpty; @@ -160,7 +160,7 @@ public ClientSession toClientSession() catalog, schema, null, - TimeZone.getDefault().getID(), + ZoneId.systemDefault(), Locale.getDefault(), toResourceEstimates(resourceEstimates), toProperties(sessionProperties), diff --git a/presto-cli/src/test/java/io/prestosql/cli/TestQueryRunner.java b/presto-cli/src/test/java/io/prestosql/cli/TestQueryRunner.java index 3bc11150947f..bd5df05a1e81 100644 --- a/presto-cli/src/test/java/io/prestosql/cli/TestQueryRunner.java +++ b/presto-cli/src/test/java/io/prestosql/cli/TestQueryRunner.java @@ -32,6 +32,7 @@ import java.io.IOException; import java.io.PrintStream; import java.sql.SQLException; +import java.time.ZoneId; import java.util.Locale; import java.util.Optional; @@ -92,7 +93,7 @@ public void testCookie() "catalog", "schema", "path", - "America/Los_Angeles", + ZoneId.of("America/Los_Angeles"), Locale.ENGLISH, ImmutableMap.of(), ImmutableMap.of(), diff --git a/presto-client/src/main/java/io/prestosql/client/ClientSession.java b/presto-client/src/main/java/io/prestosql/client/ClientSession.java index a06fd00c779a..9701775bf5e2 100644 --- a/presto-client/src/main/java/io/prestosql/client/ClientSession.java +++ b/presto-client/src/main/java/io/prestosql/client/ClientSession.java @@ -16,10 +16,10 @@ import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableSet; import io.airlift.units.Duration; -import io.prestosql.spi.type.TimeZoneKey; import java.net.URI; import java.nio.charset.CharsetEncoder; +import java.time.ZoneId; import java.util.Locale; import java.util.Map; import java.util.Map.Entry; @@ -42,7 +42,7 @@ public class ClientSession private final String catalog; private final String schema; private final String path; - private final TimeZoneKey timeZone; + private final ZoneId timeZone; private final Locale locale; private final Map resourceEstimates; private final Map properties; @@ -72,7 +72,7 @@ public ClientSession( String catalog, String schema, String path, - String timeZoneId, + ZoneId timeZone, Locale locale, Map resourceEstimates, Map properties, @@ -90,7 +90,7 @@ public ClientSession( this.schema = schema; this.path = path; this.locale = locale; - this.timeZone = TimeZoneKey.getTimeZoneKey(timeZoneId); + this.timeZone = requireNonNull(timeZone, "timeZone is null"); this.transactionId = transactionId; this.resourceEstimates = ImmutableMap.copyOf(requireNonNull(resourceEstimates, "resourceEstimates is null")); this.properties = ImmutableMap.copyOf(requireNonNull(properties, "properties is null")); @@ -163,7 +163,7 @@ public String getPath() return path; } - public TimeZoneKey getTimeZone() + public ZoneId getTimeZone() { return timeZone; } @@ -234,7 +234,7 @@ public static final class Builder private String catalog; private String schema; private String path; - private TimeZoneKey timeZone; + private ZoneId timeZone; private Locale locale; private Map resourceEstimates; private Map properties; @@ -317,7 +317,7 @@ public ClientSession build() catalog, schema, path, - timeZone.getId(), + timeZone, locale, resourceEstimates, properties, diff --git a/presto-client/src/main/java/io/prestosql/client/StatementClient.java b/presto-client/src/main/java/io/prestosql/client/StatementClient.java index 6bd15d3d1c36..3ce9689bc323 100644 --- a/presto-client/src/main/java/io/prestosql/client/StatementClient.java +++ b/presto-client/src/main/java/io/prestosql/client/StatementClient.java @@ -13,11 +13,10 @@ */ package io.prestosql.client; -import io.prestosql.spi.type.TimeZoneKey; - import javax.annotation.Nullable; import java.io.Closeable; +import java.time.ZoneId; import java.util.Map; import java.util.Optional; import java.util.Set; @@ -27,7 +26,7 @@ public interface StatementClient { String getQuery(); - TimeZoneKey getTimeZone(); + ZoneId getTimeZone(); boolean isRunning(); diff --git a/presto-client/src/main/java/io/prestosql/client/StatementClientV1.java b/presto-client/src/main/java/io/prestosql/client/StatementClientV1.java index 988882264f1f..361faa8a5d15 100644 --- a/presto-client/src/main/java/io/prestosql/client/StatementClientV1.java +++ b/presto-client/src/main/java/io/prestosql/client/StatementClientV1.java @@ -21,7 +21,6 @@ import io.airlift.json.JsonCodec; import io.airlift.units.Duration; import io.prestosql.client.OkHttpUtil.NullCallback; -import io.prestosql.spi.type.TimeZoneKey; import okhttp3.Headers; import okhttp3.HttpUrl; import okhttp3.MediaType; @@ -36,6 +35,7 @@ import java.net.URI; import java.net.URLDecoder; import java.net.URLEncoder; +import java.time.ZoneId; import java.util.List; import java.util.Map; import java.util.Map.Entry; @@ -104,7 +104,7 @@ class StatementClientV1 private final Set deallocatedPreparedStatements = Sets.newConcurrentHashSet(); private final AtomicReference startedTransactionId = new AtomicReference<>(); private final AtomicBoolean clearTransactionId = new AtomicBoolean(); - private final TimeZoneKey timeZone; + private final ZoneId timeZone; private final Duration requestTimeoutNanos; private final String user; private final String clientCapabilities; @@ -201,7 +201,7 @@ public String getQuery() } @Override - public TimeZoneKey getTimeZone() + public ZoneId getTimeZone() { return timeZone; } diff --git a/presto-jdbc/src/main/java/io/prestosql/jdbc/PrestoConnection.java b/presto-jdbc/src/main/java/io/prestosql/jdbc/PrestoConnection.java index df8f5510c3a6..c9cb73a57f4b 100644 --- a/presto-jdbc/src/main/java/io/prestosql/jdbc/PrestoConnection.java +++ b/presto-jdbc/src/main/java/io/prestosql/jdbc/PrestoConnection.java @@ -41,12 +41,12 @@ import java.sql.Savepoint; import java.sql.Statement; import java.sql.Struct; +import java.time.ZoneId; import java.util.HashMap; import java.util.Locale; import java.util.Map; import java.util.Optional; import java.util.Properties; -import java.util.TimeZone; import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.Executor; import java.util.concurrent.atomic.AtomicBoolean; @@ -74,7 +74,7 @@ public class PrestoConnection private final AtomicReference catalog = new AtomicReference<>(); private final AtomicReference schema = new AtomicReference<>(); private final AtomicReference path = new AtomicReference<>(); - private final AtomicReference timeZoneId = new AtomicReference<>(); + private final AtomicReference timeZoneId = new AtomicReference<>(); private final AtomicReference locale = new AtomicReference<>(); private final AtomicReference networkTimeoutMillis = new AtomicReference<>(Ints.saturatedCast(MINUTES.toMillis(2))); private final AtomicReference serverInfo = new AtomicReference<>(); @@ -104,7 +104,7 @@ public class PrestoConnection this.queryExecutor = requireNonNull(queryExecutor, "queryExecutor is null"); - timeZoneId.set(TimeZone.getDefault().getID()); + timeZoneId.set(ZoneId.systemDefault()); locale.set(Locale.getDefault()); } @@ -519,13 +519,12 @@ public String getSchema() public String getTimeZoneId() { - return timeZoneId.get(); + return timeZoneId.get().getId(); } public void setTimeZoneId(String timeZoneId) { - requireNonNull(timeZoneId, "timeZoneId is null"); - this.timeZoneId.set(timeZoneId); + this.timeZoneId.set(ZoneId.of(timeZoneId)); } public Locale getLocale() diff --git a/presto-tests/src/main/java/io/prestosql/tests/AbstractTestingPrestoClient.java b/presto-tests/src/main/java/io/prestosql/tests/AbstractTestingPrestoClient.java index cb97f9a50eb9..ea531e7f9b52 100644 --- a/presto-tests/src/main/java/io/prestosql/tests/AbstractTestingPrestoClient.java +++ b/presto-tests/src/main/java/io/prestosql/tests/AbstractTestingPrestoClient.java @@ -35,6 +35,7 @@ import java.io.Closeable; import java.net.URI; +import java.time.ZoneId; import java.util.List; import java.util.Map; import java.util.Map.Entry; @@ -146,7 +147,7 @@ private static ClientSession toClientSession(Session session, URI server, Durati session.getCatalog().orElse(null), session.getSchema().orElse(null), session.getPath().toString(), - session.getTimeZoneKey().getId(), + ZoneId.of(session.getTimeZoneKey().getId()), session.getLocale(), resourceEstimates.build(), properties.build(), diff --git a/presto-tests/src/test/java/io/prestosql/execution/TestFinalQueryInfo.java b/presto-tests/src/test/java/io/prestosql/execution/TestFinalQueryInfo.java index 2b606ce8a902..5abda15e9ed7 100644 --- a/presto-tests/src/test/java/io/prestosql/execution/TestFinalQueryInfo.java +++ b/presto-tests/src/test/java/io/prestosql/execution/TestFinalQueryInfo.java @@ -26,6 +26,7 @@ import okhttp3.OkHttpClient; import org.testng.annotations.Test; +import java.time.ZoneId; import java.util.Locale; import java.util.Optional; @@ -72,7 +73,7 @@ private static QueryId startQuery(String sql, DistributedQueryRunner queryRunner null, null, null, - "America/Los_Angeles", + ZoneId.of("America/Los_Angeles"), Locale.ENGLISH, ImmutableMap.of(), ImmutableMap.of(),