Skip to content

Commit

Permalink
Convert JDBC driver from TimeZoneKey to ZoneId
Browse files Browse the repository at this point in the history
  • Loading branch information
electrum committed Jan 27, 2019
1 parent 23e709f commit d5dfb31
Show file tree
Hide file tree
Showing 9 changed files with 27 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -97,7 +97,7 @@ public ClientSession getClientSession()
catalog,
schema,
null,
TimeZone.getDefault().getID(),
ZoneId.systemDefault(),
Locale.getDefault(),
ImmutableMap.of(),
toProperties(this.sessionProperties),
Expand Down
4 changes: 2 additions & 2 deletions presto-cli/src/main/java/io/prestosql/cli/ClientOptions.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,14 @@

import java.net.URI;
import java.net.URISyntaxException;
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.Set;
import java.util.TimeZone;

import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.base.Strings.nullToEmpty;
Expand Down Expand Up @@ -160,7 +160,7 @@ public ClientSession toClientSession()
catalog,
schema,
null,
TimeZone.getDefault().getID(),
ZoneId.systemDefault(),
Locale.getDefault(),
toResourceEstimates(resourceEstimates),
toProperties(sessionProperties),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -92,7 +93,7 @@ public void testCookie()
"catalog",
"schema",
"path",
"America/Los_Angeles",
ZoneId.of("America/Los_Angeles"),
Locale.ENGLISH,
ImmutableMap.of(),
ImmutableMap.of(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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<String, String> resourceEstimates;
private final Map<String, String> properties;
Expand Down Expand Up @@ -72,7 +72,7 @@ public ClientSession(
String catalog,
String schema,
String path,
String timeZoneId,
ZoneId timeZone,
Locale locale,
Map<String, String> resourceEstimates,
Map<String, String> properties,
Expand All @@ -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 comment has been minimized.

Copy link
@redatom

redatom May 14, 2019

This change makes error: "The datetime zone id 'GMT+08:00' is not recognised".

this.transactionId = transactionId;
this.resourceEstimates = ImmutableMap.copyOf(requireNonNull(resourceEstimates, "resourceEstimates is null"));
this.properties = ImmutableMap.copyOf(requireNonNull(properties, "properties is null"));
Expand Down Expand Up @@ -163,7 +163,7 @@ public String getPath()
return path;
}

public TimeZoneKey getTimeZone()
public ZoneId getTimeZone()
{
return timeZone;
}
Expand Down Expand Up @@ -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<String, String> resourceEstimates;
private Map<String, String> properties;
Expand Down Expand Up @@ -317,7 +317,7 @@ public ClientSession build()
catalog,
schema,
path,
timeZone.getId(),
timeZone,
locale,
resourceEstimates,
properties,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -27,7 +26,7 @@ public interface StatementClient
{
String getQuery();

TimeZoneKey getTimeZone();
ZoneId getTimeZone();

boolean isRunning();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -104,7 +104,7 @@ class StatementClientV1
private final Set<String> deallocatedPreparedStatements = Sets.newConcurrentHashSet();
private final AtomicReference<String> 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;
Expand Down Expand Up @@ -201,7 +201,7 @@ public String getQuery()
}

@Override
public TimeZoneKey getTimeZone()
public ZoneId getTimeZone()
{
return timeZone;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -74,7 +74,7 @@ public class PrestoConnection
private final AtomicReference<String> catalog = new AtomicReference<>();
private final AtomicReference<String> schema = new AtomicReference<>();
private final AtomicReference<String> path = new AtomicReference<>();
private final AtomicReference<String> timeZoneId = new AtomicReference<>();
private final AtomicReference<ZoneId> timeZoneId = new AtomicReference<>();
private final AtomicReference<Locale> locale = new AtomicReference<>();
private final AtomicReference<Integer> networkTimeoutMillis = new AtomicReference<>(Ints.saturatedCast(MINUTES.toMillis(2)));
private final AtomicReference<ServerInfo> serverInfo = new AtomicReference<>();
Expand Down Expand Up @@ -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());
}

Expand Down Expand Up @@ -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()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import okhttp3.OkHttpClient;
import org.testng.annotations.Test;

import java.time.ZoneId;
import java.util.Locale;
import java.util.Optional;

Expand Down Expand Up @@ -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(),
Expand Down

0 comments on commit d5dfb31

Please sign in to comment.