From 233d34ca3e3702d436ded9653a8cd0bf9b80bbf8 Mon Sep 17 00:00:00 2001 From: David Phillips Date: Sun, 23 Dec 2018 16:53:48 -0800 Subject: [PATCH 1/5] 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 8e73bcf799a..77adc89f704 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 df603a84a9e..12f8b0bc114 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 3bc11150947..bd5df05a1e8 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 a06fd00c779..9701775bf5e 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 6bd15d3d1c3..3ce9689bc32 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 988882264f1..361faa8a5d1 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 df8f5510c3a..c9cb73a57f4 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 cb97f9a50eb..ea531e7f9b5 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 2b606ce8a90..5abda15e9ed 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(), From 38066427ba28d359bcd3dcd365181c4e1b05e913 Mon Sep 17 00:00:00 2001 From: David Phillips Date: Sun, 23 Dec 2018 17:50:37 -0800 Subject: [PATCH 2/5] Replace PrestoWarning with new client Warning --- .../cli/AbstractWarningsPrinter.java | 8 +- .../src/main/java/io/prestosql/cli/Query.java | 4 +- .../io/prestosql/cli/WarningsPrinter.java | 4 +- .../io/prestosql/client/QueryResults.java | 9 +- .../io/prestosql/client/QueryStatusInfo.java | 4 +- .../java/io/prestosql/client/Warning.java | 128 ++++++++++++++++++ .../io/prestosql/jdbc/PrestoSqlWarning.java | 9 +- .../io/prestosql/jdbc/WarningsManager.java | 11 +- .../io/prestosql/jdbc/TestJdbcWarnings.java | 24 +++- .../io/prestosql/server/protocol/Query.java | 12 +- 10 files changed, 177 insertions(+), 36 deletions(-) create mode 100644 presto-client/src/main/java/io/prestosql/client/Warning.java diff --git a/presto-cli/src/main/java/io/prestosql/cli/AbstractWarningsPrinter.java b/presto-cli/src/main/java/io/prestosql/cli/AbstractWarningsPrinter.java index c5940e2e8c9..f569efced96 100644 --- a/presto-cli/src/main/java/io/prestosql/cli/AbstractWarningsPrinter.java +++ b/presto-cli/src/main/java/io/prestosql/cli/AbstractWarningsPrinter.java @@ -13,7 +13,7 @@ */ package io.prestosql.cli; -import io.prestosql.spi.PrestoWarning; +import io.prestosql.client.Warning; import java.util.List; import java.util.OptionalInt; @@ -38,7 +38,7 @@ abstract class AbstractWarningsPrinter this.maxWarnings = requireNonNull(maxWarnings, "maxWarnings is null"); } - private String getWarningMessage(PrestoWarning warning) + private String getWarningMessage(Warning warning) { // If this is a real terminal color the warnings yellow if (REAL_TERMINAL) { @@ -47,7 +47,7 @@ private String getWarningMessage(PrestoWarning warning) return format("WARNING: %s", warning.getMessage()); } - private List getNewWarnings(List warnings) + private List getNewWarnings(List warnings) { int end = warnings.size(); if (maxWarnings.isPresent()) { @@ -94,7 +94,7 @@ private void printWithTrailingSeparator(List warnings) } @Override - public void print(List warnings, boolean withInitialSeparator, boolean withTrailingSeparator) + public void print(List warnings, boolean withInitialSeparator, boolean withTrailingSeparator) { requireNonNull(warnings, "warnings is null"); List newWarnings = getNewWarnings(warnings); diff --git a/presto-cli/src/main/java/io/prestosql/cli/Query.java b/presto-cli/src/main/java/io/prestosql/cli/Query.java index 1ce090eb66c..096dba191a5 100644 --- a/presto-cli/src/main/java/io/prestosql/cli/Query.java +++ b/presto-cli/src/main/java/io/prestosql/cli/Query.java @@ -23,7 +23,7 @@ import io.prestosql.client.QueryError; import io.prestosql.client.QueryStatusInfo; import io.prestosql.client.StatementClient; -import io.prestosql.spi.PrestoWarning; +import io.prestosql.client.Warning; import org.fusesource.jansi.Ansi; import sun.misc.Signal; import sun.misc.SignalHandler; @@ -194,7 +194,7 @@ private void processInitialStatusUpdates(WarningsPrinter warningsPrinter) warningsPrinter.print(client.currentStatusInfo().getWarnings(), true, false); client.advance(); } - List warnings; + List warnings; if (client.isRunning()) { warnings = client.currentStatusInfo().getWarnings(); } diff --git a/presto-cli/src/main/java/io/prestosql/cli/WarningsPrinter.java b/presto-cli/src/main/java/io/prestosql/cli/WarningsPrinter.java index e22a8e9ab5f..9404b1279f4 100644 --- a/presto-cli/src/main/java/io/prestosql/cli/WarningsPrinter.java +++ b/presto-cli/src/main/java/io/prestosql/cli/WarningsPrinter.java @@ -13,11 +13,11 @@ */ package io.prestosql.cli; -import io.prestosql.spi.PrestoWarning; +import io.prestosql.client.Warning; import java.util.List; public interface WarningsPrinter { - void print(List warnings, boolean withInitialSeparator, boolean withTrailingSeparator); + void print(List warnings, boolean withInitialSeparator, boolean withTrailingSeparator); } diff --git a/presto-client/src/main/java/io/prestosql/client/QueryResults.java b/presto-client/src/main/java/io/prestosql/client/QueryResults.java index d7acf8759cd..4c1e798542a 100644 --- a/presto-client/src/main/java/io/prestosql/client/QueryResults.java +++ b/presto-client/src/main/java/io/prestosql/client/QueryResults.java @@ -16,7 +16,6 @@ import com.fasterxml.jackson.annotation.JsonCreator; import com.fasterxml.jackson.annotation.JsonProperty; import com.google.common.collect.ImmutableList; -import io.prestosql.spi.PrestoWarning; import javax.annotation.Nullable; import javax.annotation.concurrent.Immutable; @@ -43,7 +42,7 @@ public class QueryResults private final Iterable> data; private final StatementStats stats; private final QueryError error; - private final List warnings; + private final List warnings; private final String updateType; private final Long updateCount; @@ -57,7 +56,7 @@ public QueryResults( @JsonProperty("data") List> data, @JsonProperty("stats") StatementStats stats, @JsonProperty("error") QueryError error, - @JsonProperty("warnings") List warnings, + @JsonProperty("warnings") List warnings, @JsonProperty("updateType") String updateType, @JsonProperty("updateCount") Long updateCount) { @@ -84,7 +83,7 @@ public QueryResults( Iterable> data, StatementStats stats, QueryError error, - List warnings, + List warnings, String updateType, Long updateCount) { @@ -165,7 +164,7 @@ public QueryError getError() @JsonProperty @Override - public List getWarnings() + public List getWarnings() { return warnings; } diff --git a/presto-client/src/main/java/io/prestosql/client/QueryStatusInfo.java b/presto-client/src/main/java/io/prestosql/client/QueryStatusInfo.java index 71ee921b789..d3243e8b4d7 100644 --- a/presto-client/src/main/java/io/prestosql/client/QueryStatusInfo.java +++ b/presto-client/src/main/java/io/prestosql/client/QueryStatusInfo.java @@ -13,8 +13,6 @@ */ package io.prestosql.client; -import io.prestosql.spi.PrestoWarning; - import java.net.URI; import java.util.List; @@ -34,7 +32,7 @@ public interface QueryStatusInfo QueryError getError(); - List getWarnings(); + List getWarnings(); String getUpdateType(); diff --git a/presto-client/src/main/java/io/prestosql/client/Warning.java b/presto-client/src/main/java/io/prestosql/client/Warning.java new file mode 100644 index 00000000000..95fab4bd801 --- /dev/null +++ b/presto-client/src/main/java/io/prestosql/client/Warning.java @@ -0,0 +1,128 @@ +/* + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package io.prestosql.client; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonProperty; + +import java.util.Objects; + +import static java.lang.String.format; +import static java.util.Objects.requireNonNull; + +public final class Warning +{ + private final Code warningCode; + private final String message; + + @JsonCreator + public Warning( + @JsonProperty("warningCode") Code warningCode, + @JsonProperty("message") String message) + { + this.warningCode = requireNonNull(warningCode, "warningCode is null"); + this.message = requireNonNull(message, "message is null"); + } + + @JsonProperty + public Code getWarningCode() + { + return warningCode; + } + + @JsonProperty + public String getMessage() + { + return message; + } + + @Override + public boolean equals(Object obj) + { + if (this == obj) { + return true; + } + if ((obj == null) || (getClass() != obj.getClass())) { + return false; + } + Warning that = (Warning) obj; + return Objects.equals(warningCode, that.warningCode) && + Objects.equals(message, that.message); + } + + @Override + public int hashCode() + { + return Objects.hash(warningCode, message); + } + + @Override + public String toString() + { + return format("%s, %s", warningCode, message); + } + + public static final class Code + { + private final int code; + private final String name; + + @JsonCreator + public Code( + @JsonProperty("code") int code, + @JsonProperty("name") String name) + { + this.code = code; + this.name = requireNonNull(name, "name is null"); + } + + @JsonProperty + public int getCode() + { + return code; + } + + @JsonProperty + public String getName() + { + return name; + } + + @Override + public boolean equals(Object obj) + { + if (this == obj) { + return true; + } + if ((obj == null) || (getClass() != obj.getClass())) { + return false; + } + Code other = (Code) obj; + return (code == other.code) && + Objects.equals(name, other.name); + } + + @Override + public int hashCode() + { + return Objects.hash(code, name); + } + + @Override + public String toString() + { + return name + ":" + code; + } + } +} diff --git a/presto-jdbc/src/main/java/io/prestosql/jdbc/PrestoSqlWarning.java b/presto-jdbc/src/main/java/io/prestosql/jdbc/PrestoSqlWarning.java index bccd84a1620..c23d84c5efd 100644 --- a/presto-jdbc/src/main/java/io/prestosql/jdbc/PrestoSqlWarning.java +++ b/presto-jdbc/src/main/java/io/prestosql/jdbc/PrestoSqlWarning.java @@ -13,19 +13,14 @@ */ package io.prestosql.jdbc; -import io.prestosql.spi.PrestoWarning; +import io.prestosql.client.Warning; import java.sql.SQLWarning; public class PrestoSqlWarning extends SQLWarning { - public PrestoSqlWarning() - { - super(); - } - - public PrestoSqlWarning(PrestoWarning warning) + public PrestoSqlWarning(Warning warning) { //TODO: enforce that sqlState is 01[5,6,7,8,9,I-Z][0-9A-Z]{3} // From the SQL Standard ISO_IEC_9075-2E_2016 24.1 SQLState: warning codes have class 01 diff --git a/presto-jdbc/src/main/java/io/prestosql/jdbc/WarningsManager.java b/presto-jdbc/src/main/java/io/prestosql/jdbc/WarningsManager.java index 04ff5c40f6f..38e9fd02ae1 100644 --- a/presto-jdbc/src/main/java/io/prestosql/jdbc/WarningsManager.java +++ b/presto-jdbc/src/main/java/io/prestosql/jdbc/WarningsManager.java @@ -13,8 +13,7 @@ */ package io.prestosql.jdbc; -import io.prestosql.spi.PrestoWarning; -import io.prestosql.spi.WarningCode; +import io.prestosql.client.Warning; import javax.annotation.concurrent.GuardedBy; import javax.annotation.concurrent.ThreadSafe; @@ -30,7 +29,7 @@ public class WarningsManager { @GuardedBy("this") - private Set warningsSeen = new HashSet<>(); + private final Set warningsSeen = new HashSet<>(); @GuardedBy("this") private SQLWarning firstWarning; @@ -39,7 +38,7 @@ public class WarningsManager @GuardedBy("this") private SQLWarning lastWarning; - private synchronized void addWarning(PrestoWarning warning) + private synchronized void addWarning(Warning warning) { requireNonNull(warning, "warning is null"); if (lastWarning == null) { @@ -56,9 +55,9 @@ private synchronized void addWarning(PrestoWarning warning) } } - public synchronized void addWarnings(List warnings) + public synchronized void addWarnings(List warnings) { - for (PrestoWarning warning : warnings) { + for (Warning warning : warnings) { if (warningsSeen.add(warning.getWarningCode())) { addWarning(warning); } diff --git a/presto-jdbc/src/test/java/io/prestosql/jdbc/TestJdbcWarnings.java b/presto-jdbc/src/test/java/io/prestosql/jdbc/TestJdbcWarnings.java index b4bd3435a4c..9a56f2372e5 100644 --- a/presto-jdbc/src/test/java/io/prestosql/jdbc/TestJdbcWarnings.java +++ b/presto-jdbc/src/test/java/io/prestosql/jdbc/TestJdbcWarnings.java @@ -17,6 +17,7 @@ import com.google.common.collect.ImmutableMap; import com.google.common.collect.Iterators; import com.google.common.util.concurrent.AbstractFuture; +import io.prestosql.client.Warning; import io.prestosql.execution.QueryInfo; import io.prestosql.execution.warnings.WarningCollectorConfig; import io.prestosql.plugin.blackhole.BlackHolePlugin; @@ -211,7 +212,7 @@ public void testExecuteQueryWarnings() TestingWarningCollector warningCollector = new TestingWarningCollector(new WarningCollectorConfig(), warningCollectorConfig); List expectedWarnings = warningCollector.getWarnings(); for (PrestoWarning prestoWarning : expectedWarnings) { - assertTrue(currentWarnings.contains(new WarningEntry(new PrestoSqlWarning(prestoWarning)))); + assertTrue(currentWarnings.contains(new WarningEntry(toPrestoSqlWarning(prestoWarning)))); } } } @@ -226,9 +227,9 @@ public void testSqlWarning() List warnings = builder.build(); SQLWarning warning = fromPrestoWarnings(warnings); assertEquals(Iterators.size(warning.iterator()), warnings.size()); - assertWarningsEqual(warning, new PrestoSqlWarning(warnings.get(0))); - assertWarningsEqual(warning.getNextWarning(), new PrestoSqlWarning(warnings.get(1))); - assertWarningsEqual(warning.getNextWarning().getNextWarning(), new PrestoSqlWarning(warnings.get(2))); + assertWarningsEqual(warning, toPrestoSqlWarning(warnings.get(0))); + assertWarningsEqual(warning.getNextWarning(), toPrestoSqlWarning(warnings.get(1))); + assertWarningsEqual(warning.getNextWarning().getNextWarning(), toPrestoSqlWarning(warnings.get(2))); } private static SQLWarning fromPrestoWarnings(List warnings) @@ -236,15 +237,26 @@ private static SQLWarning fromPrestoWarnings(List warnings) requireNonNull(warnings, "warnings is null"); assertFalse(warnings.isEmpty()); Iterator iterator = warnings.iterator(); - PrestoSqlWarning first = new PrestoSqlWarning(iterator.next()); + PrestoSqlWarning first = toPrestoSqlWarning(iterator.next()); SQLWarning current = first; while (iterator.hasNext()) { - current.setNextWarning(new PrestoSqlWarning(iterator.next())); + current.setNextWarning(toPrestoSqlWarning(iterator.next())); current = current.getNextWarning(); } return first; } + private static PrestoSqlWarning toPrestoSqlWarning(PrestoWarning warning) + { + return new PrestoSqlWarning(toClientWarning(warning)); + } + + private static Warning toClientWarning(PrestoWarning warning) + { + WarningCode code = warning.getWarningCode(); + return new Warning(new Warning.Code(code.getCode(), code.getName()), warning.getMessage()); + } + private static void assertWarningsEqual(SQLWarning actual, SQLWarning expected) { assertEquals(actual.getMessage(), expected.getMessage()); diff --git a/presto-main/src/main/java/io/prestosql/server/protocol/Query.java b/presto-main/src/main/java/io/prestosql/server/protocol/Query.java index 210d6155110..1e79db9560d 100644 --- a/presto-main/src/main/java/io/prestosql/server/protocol/Query.java +++ b/presto-main/src/main/java/io/prestosql/server/protocol/Query.java @@ -32,6 +32,7 @@ import io.prestosql.client.QueryResults; import io.prestosql.client.StageStats; import io.prestosql.client.StatementStats; +import io.prestosql.client.Warning; import io.prestosql.execution.QueryExecution; import io.prestosql.execution.QueryInfo; import io.prestosql.execution.QueryManager; @@ -47,7 +48,9 @@ import io.prestosql.server.SessionContext; import io.prestosql.spi.ErrorCode; import io.prestosql.spi.Page; +import io.prestosql.spi.PrestoWarning; import io.prestosql.spi.QueryId; +import io.prestosql.spi.WarningCode; import io.prestosql.spi.block.BlockEncodingSerde; import io.prestosql.spi.type.BooleanType; import io.prestosql.spi.type.StandardTypes; @@ -83,6 +86,7 @@ import static io.prestosql.execution.QueryState.FAILED; import static io.prestosql.spi.StandardErrorCode.GENERIC_INTERNAL_ERROR; import static io.prestosql.util.Failures.toFailure; +import static io.prestosql.util.MoreLists.mappedCopy; import static java.lang.String.format; import static java.util.Objects.requireNonNull; @@ -492,7 +496,7 @@ public synchronized QueryResults getNextResult(OptionalLong token, UriInfo uriIn data, toStatementStats(queryInfo), toQueryError(queryInfo), - queryInfo.getWarnings(), + mappedCopy(queryInfo.getWarnings(), Query::toClientWarning), queryInfo.getUpdateType(), updateCount); @@ -706,6 +710,12 @@ private static QueryError toQueryError(QueryInfo queryInfo) failure); } + private static Warning toClientWarning(PrestoWarning warning) + { + WarningCode code = warning.getWarningCode(); + return new Warning(new Warning.Code(code.getCode(), code.getName()), warning.getMessage()); + } + private static class QuerySubmissionFuture extends AbstractFuture { From 83f654dfe17ea98e4ec4d6a45710bc5eb608424b Mon Sep 17 00:00:00 2001 From: David Phillips Date: Mon, 24 Dec 2018 01:01:26 -0800 Subject: [PATCH 3/5] Convert JDBC driver to ClientTypeSignature --- .../prestosql/client/ClientTypeSignature.java | 11 +++++++ .../io/prestosql/client/FixJsonDataUtils.java | 29 ++++++++---------- .../java/io/prestosql/jdbc/ColumnInfo.java | 30 +++++++++---------- .../io/prestosql/jdbc/PrestoResultSet.java | 7 ++--- 4 files changed, 42 insertions(+), 35 deletions(-) diff --git a/presto-client/src/main/java/io/prestosql/client/ClientTypeSignature.java b/presto-client/src/main/java/io/prestosql/client/ClientTypeSignature.java index b78d092de38..177b730cb91 100644 --- a/presto-client/src/main/java/io/prestosql/client/ClientTypeSignature.java +++ b/presto-client/src/main/java/io/prestosql/client/ClientTypeSignature.java @@ -35,6 +35,8 @@ import java.util.stream.Collectors; import static com.google.common.base.Preconditions.checkArgument; +import static com.google.common.base.Preconditions.checkState; +import static com.google.common.collect.ImmutableList.toImmutableList; import static java.lang.String.format; import static java.util.Collections.unmodifiableList; import static java.util.Objects.requireNonNull; @@ -132,6 +134,15 @@ public List getArguments() return arguments; } + public List getArgumentsAsTypeSignatures() + { + return arguments.stream() + .peek(parameter -> checkState(parameter.getKind() == ParameterKind.TYPE, + "Expected all parameters to be TypeSignatures but [%s] was found", parameter)) + .map(ClientTypeSignatureParameter::getTypeSignature) + .collect(toImmutableList()); + } + /** * This field is deprecated and clients should switch to {@link #getArguments()} */ diff --git a/presto-client/src/main/java/io/prestosql/client/FixJsonDataUtils.java b/presto-client/src/main/java/io/prestosql/client/FixJsonDataUtils.java index ebcf01e70cb..68780701644 100644 --- a/presto-client/src/main/java/io/prestosql/client/FixJsonDataUtils.java +++ b/presto-client/src/main/java/io/prestosql/client/FixJsonDataUtils.java @@ -16,8 +16,6 @@ import com.google.common.collect.ImmutableList; import io.prestosql.spi.type.NamedTypeSignature; import io.prestosql.spi.type.ParameterKind; -import io.prestosql.spi.type.TypeSignature; -import io.prestosql.spi.type.TypeSignatureParameter; import java.util.ArrayList; import java.util.Base64; @@ -52,7 +50,6 @@ import static io.prestosql.spi.type.StandardTypes.TIME_WITH_TIME_ZONE; import static io.prestosql.spi.type.StandardTypes.TINYINT; import static io.prestosql.spi.type.StandardTypes.VARCHAR; -import static io.prestosql.spi.type.TypeSignature.parseTypeSignature; import static java.util.Collections.unmodifiableList; import static java.util.Objects.requireNonNull; import static java.util.stream.Collectors.toList; @@ -67,8 +64,8 @@ public static Iterable> fixData(List columns, Iterable signatures = columns.stream() - .map(column -> parseTypeSignature(column.getType())) + List signatures = columns.stream() + .map(Column::getTypeSignature) .collect(toList()); ImmutableList.Builder> rows = ImmutableList.builder(); for (List row : data) { @@ -85,45 +82,45 @@ public static Iterable> fixData(List columns, Iterable fixedValue = new ArrayList<>(); for (Object object : List.class.cast(value)) { - fixedValue.add(fixValue(signature.getTypeParametersAsTypeSignatures().get(0), object)); + fixedValue.add(fixValue(signature.getArgumentsAsTypeSignatures().get(0), object)); } return fixedValue; } - if (signature.getBase().equals(MAP)) { - TypeSignature keySignature = signature.getTypeParametersAsTypeSignatures().get(0); - TypeSignature valueSignature = signature.getTypeParametersAsTypeSignatures().get(1); + if (signature.getRawType().equals(MAP)) { + ClientTypeSignature keySignature = signature.getArgumentsAsTypeSignatures().get(0); + ClientTypeSignature valueSignature = signature.getArgumentsAsTypeSignatures().get(1); Map fixedValue = new HashMap<>(); for (Map.Entry entry : (Set>) Map.class.cast(value).entrySet()) { fixedValue.put(fixValue(keySignature, entry.getKey()), fixValue(valueSignature, entry.getValue())); } return fixedValue; } - if (signature.getBase().equals(ROW)) { + if (signature.getRawType().equals(ROW)) { Map fixedValue = new LinkedHashMap<>(); List listValue = List.class.cast(value); - checkArgument(listValue.size() == signature.getParameters().size(), "Mismatched data values and row type"); + checkArgument(listValue.size() == signature.getArguments().size(), "Mismatched data values and row type"); for (int i = 0; i < listValue.size(); i++) { - TypeSignatureParameter parameter = signature.getParameters().get(i); + ClientTypeSignatureParameter parameter = signature.getArguments().get(i); checkArgument( parameter.getKind() == ParameterKind.NAMED_TYPE, "Unexpected parameter [%s] for row type", parameter); NamedTypeSignature namedTypeSignature = parameter.getNamedTypeSignature(); String key = namedTypeSignature.getName().orElse("field" + i); - fixedValue.put(key, fixValue(namedTypeSignature.getTypeSignature(), listValue.get(i))); + fixedValue.put(key, fixValue(new ClientTypeSignature(namedTypeSignature.getTypeSignature()), listValue.get(i))); } return fixedValue; } - switch (signature.getBase()) { + switch (signature.getRawType()) { case BIGINT: if (value instanceof String) { return Long.parseLong((String) value); diff --git a/presto-jdbc/src/main/java/io/prestosql/jdbc/ColumnInfo.java b/presto-jdbc/src/main/java/io/prestosql/jdbc/ColumnInfo.java index b3a6a513df5..14699290a02 100644 --- a/presto-jdbc/src/main/java/io/prestosql/jdbc/ColumnInfo.java +++ b/presto-jdbc/src/main/java/io/prestosql/jdbc/ColumnInfo.java @@ -14,8 +14,8 @@ package io.prestosql.jdbc; import com.google.common.collect.ImmutableList; -import io.prestosql.spi.type.TypeSignature; -import io.prestosql.spi.type.TypeSignatureParameter; +import io.prestosql.client.ClientTypeSignature; +import io.prestosql.client.ClientTypeSignatureParameter; import java.sql.Types; import java.util.List; @@ -35,7 +35,7 @@ class ColumnInfo private final int columnType; private final List columnParameterTypes; - private final TypeSignature columnTypeSignature; + private final ClientTypeSignature columnTypeSignature; private final Nullable nullable; private final boolean currency; private final boolean signed; @@ -56,7 +56,7 @@ public enum Nullable public ColumnInfo( int columnType, List columnParameterTypes, - TypeSignature columnTypeSignature, + ClientTypeSignature columnTypeSignature, Nullable nullable, boolean currency, boolean signed, @@ -85,11 +85,11 @@ public ColumnInfo( this.catalogName = requireNonNull(catalogName, "catalogName is null"); } - public static void setTypeInfo(Builder builder, TypeSignature type) + public static void setTypeInfo(Builder builder, ClientTypeSignature type) { builder.setColumnType(getType(type)); ImmutableList.Builder parameterTypes = ImmutableList.builder(); - for (TypeSignatureParameter parameter : type.getParameters()) { + for (ClientTypeSignatureParameter parameter : type.getArguments()) { parameterTypes.add(getType(parameter)); } builder.setColumnParameterTypes(parameterTypes.build()); @@ -182,14 +182,14 @@ public static void setTypeInfo(Builder builder, TypeSignature type) break; case "decimal": builder.setSigned(true); - builder.setColumnDisplaySize(type.getParameters().get(0).getLongLiteral().intValue() + 2); // dot and sign - builder.setPrecision(type.getParameters().get(0).getLongLiteral().intValue()); - builder.setScale(type.getParameters().get(1).getLongLiteral().intValue()); + builder.setColumnDisplaySize(type.getArguments().get(0).getLongLiteral().intValue() + 2); // dot and sign + builder.setPrecision(type.getArguments().get(0).getLongLiteral().intValue()); + builder.setScale(type.getArguments().get(1).getLongLiteral().intValue()); break; } } - private static int getType(TypeSignatureParameter typeParameter) + private static int getType(ClientTypeSignatureParameter typeParameter) { switch (typeParameter.getKind()) { case TYPE: @@ -199,9 +199,9 @@ private static int getType(TypeSignatureParameter typeParameter) } } - private static int getType(TypeSignature type) + private static int getType(ClientTypeSignature type) { - switch (type.getBase()) { + switch (type.getRawType()) { case "array": return Types.ARRAY; case "boolean": @@ -258,7 +258,7 @@ public String getColumnTypeName() return columnTypeSignature.toString(); } - public TypeSignature getColumnTypeSignature() + public ClientTypeSignature getColumnTypeSignature() { return columnTypeSignature; } @@ -322,7 +322,7 @@ static class Builder { private int columnType; private List columnParameterTypes; - private TypeSignature columnTypeSignature; + private ClientTypeSignature columnTypeSignature; private Nullable nullable; private boolean currency; private boolean signed; @@ -346,7 +346,7 @@ public void setColumnParameterTypes(List columnParameterTypes) this.columnParameterTypes = ImmutableList.copyOf(requireNonNull(columnParameterTypes, "columnParameterTypes is null")); } - public Builder setColumnTypeSignature(TypeSignature columnTypeSignature) + public Builder setColumnTypeSignature(ClientTypeSignature columnTypeSignature) { this.columnTypeSignature = columnTypeSignature; return this; diff --git a/presto-jdbc/src/main/java/io/prestosql/jdbc/PrestoResultSet.java b/presto-jdbc/src/main/java/io/prestosql/jdbc/PrestoResultSet.java index d6658ca7fd8..77ea0950ffe 100644 --- a/presto-jdbc/src/main/java/io/prestosql/jdbc/PrestoResultSet.java +++ b/presto-jdbc/src/main/java/io/prestosql/jdbc/PrestoResultSet.java @@ -65,7 +65,6 @@ import static com.google.common.collect.Iterators.concat; import static com.google.common.collect.Iterators.transform; import static io.prestosql.jdbc.ColumnInfo.setTypeInfo; -import static io.prestosql.spi.type.TypeSignature.parseTypeSignature; import static java.lang.String.format; import static java.math.BigDecimal.ROUND_HALF_UP; import static java.util.Locale.ENGLISH; @@ -1125,7 +1124,7 @@ public Array getArray(int columnIndex) } ColumnInfo columnInfo = columnInfo(columnIndex); - String elementTypeName = getOnlyElement(columnInfo.getColumnTypeSignature().getParameters()).toString(); + String elementTypeName = getOnlyElement(columnInfo.getColumnTypeSignature().getArguments()).toString(); int elementType = getOnlyElement(columnInfo.getColumnParameterTypes()); return new PrestoArray(elementTypeName, elementType, (List) value); } @@ -1862,10 +1861,10 @@ private static List getColumnInfo(List columns) .setTableName("") // TODO .setColumnLabel(column.getName()) .setColumnName(column.getName()) // TODO - .setColumnTypeSignature(parseTypeSignature(column.getType().toUpperCase(ENGLISH))) + .setColumnTypeSignature(column.getTypeSignature()) .setNullable(Nullable.UNKNOWN) .setCurrency(false); - setTypeInfo(builder, parseTypeSignature(column.getType())); + setTypeInfo(builder, column.getTypeSignature()); list.add(builder.build()); } return list.build(); From c4496921cf7f9635d7171aff59caf2acbb675fc9 Mon Sep 17 00:00:00 2001 From: David Phillips Date: Tue, 25 Dec 2018 00:43:01 -0800 Subject: [PATCH 4/5] Remove usages of TypeSignature from client --- presto-cli/pom.xml | 12 +-- .../io/prestosql/cli/TestQueryRunner.java | 5 +- .../prestosql/client/ClientTypeSignature.java | 41 ++------- .../client/ClientTypeSignatureParameter.java | 36 ++++---- .../main/java/io/prestosql/client/Column.java | 12 --- .../io/prestosql/client/FixJsonDataUtils.java | 6 +- .../client/NamedClientTypeSignature.java | 86 +++++++++++++++++++ .../io/prestosql/client/ParameterKind.java | 57 ++++++++++++ .../io/prestosql/client/RowFieldName.java | 79 +++++++++++++++++ .../client/TestClientTypeSignature.java | 19 ++-- .../client/TestFixJsonDataUtils.java | 29 ++++++- .../prestosql/client}/TestParameterKind.java | 2 +- .../prestosql/jdbc/TestProgressMonitor.java | 5 +- .../io/prestosql/server/protocol/Query.java | 40 ++++++++- .../spi/type/NamedTypeSignature.java | 10 +-- .../io/prestosql/spi/type/ParameterKind.java | 40 +-------- .../io/prestosql/spi/type/RowFieldName.java | 10 +-- 17 files changed, 334 insertions(+), 155 deletions(-) create mode 100644 presto-client/src/main/java/io/prestosql/client/NamedClientTypeSignature.java create mode 100644 presto-client/src/main/java/io/prestosql/client/ParameterKind.java create mode 100644 presto-client/src/main/java/io/prestosql/client/RowFieldName.java rename {presto-spi/src/test/java/io/prestosql/spi/type => presto-client/src/test/java/io/prestosql/client}/TestParameterKind.java (98%) diff --git a/presto-cli/pom.xml b/presto-cli/pom.xml index cf5c5a583d3..f81de5f9c74 100644 --- a/presto-cli/pom.xml +++ b/presto-cli/pom.xml @@ -17,11 +17,6 @@ - - io.prestosql - presto-spi - - io.prestosql presto-client @@ -93,6 +88,13 @@ okhttp + + + io.prestosql + presto-spi + runtime + + org.testng 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 bd5df05a1e8..471c1cffd63 100644 --- a/presto-cli/src/test/java/io/prestosql/cli/TestQueryRunner.java +++ b/presto-cli/src/test/java/io/prestosql/cli/TestQueryRunner.java @@ -19,10 +19,11 @@ import io.airlift.json.JsonCodec; import io.airlift.units.Duration; import io.prestosql.client.ClientSession; +import io.prestosql.client.ClientTypeSignature; import io.prestosql.client.Column; import io.prestosql.client.QueryResults; import io.prestosql.client.StatementStats; -import io.prestosql.spi.type.BigintType; +import io.prestosql.spi.type.StandardTypes; import okhttp3.mockwebserver.MockResponse; import okhttp3.mockwebserver.MockWebServer; import org.testng.annotations.AfterMethod; @@ -118,7 +119,7 @@ private String createResults() server.url("/query.html?20160128_214710_00012_rk68b").uri(), null, null, - ImmutableList.of(new Column("_col0", BigintType.BIGINT)), + ImmutableList.of(new Column("_col0", StandardTypes.BIGINT, new ClientTypeSignature(StandardTypes.BIGINT))), ImmutableList.of(ImmutableList.of(123)), StatementStats.builder().setState("FINISHED").build(), //new StatementStats("FINISHED", false, true, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, null), diff --git a/presto-client/src/main/java/io/prestosql/client/ClientTypeSignature.java b/presto-client/src/main/java/io/prestosql/client/ClientTypeSignature.java index 177b730cb91..19efa16b2d2 100644 --- a/presto-client/src/main/java/io/prestosql/client/ClientTypeSignature.java +++ b/presto-client/src/main/java/io/prestosql/client/ClientTypeSignature.java @@ -16,13 +16,7 @@ import com.fasterxml.jackson.annotation.JsonCreator; import com.fasterxml.jackson.annotation.JsonProperty; import com.google.common.collect.ImmutableList; -import com.google.common.collect.Lists; -import io.prestosql.spi.type.NamedTypeSignature; -import io.prestosql.spi.type.ParameterKind; -import io.prestosql.spi.type.RowFieldName; import io.prestosql.spi.type.StandardTypes; -import io.prestosql.spi.type.TypeSignature; -import io.prestosql.spi.type.TypeSignatureParameter; import javax.annotation.concurrent.Immutable; @@ -40,7 +34,6 @@ import static java.lang.String.format; import static java.util.Collections.unmodifiableList; import static java.util.Objects.requireNonNull; -import static java.util.stream.Collectors.toList; @Immutable public class ClientTypeSignature @@ -49,11 +42,9 @@ public class ClientTypeSignature private final String rawType; private final List arguments; - public ClientTypeSignature(TypeSignature typeSignature) + public ClientTypeSignature(String rawType) { - this( - typeSignature.getBase(), - Lists.transform(typeSignature.getParameters(), ClientTypeSignatureParameter::new)); + this(rawType, ImmutableList.of()); } public ClientTypeSignature(String rawType, List arguments) @@ -85,9 +76,9 @@ public ClientTypeSignature( for (int i = 0; i < typeArguments.size(); i++) { Object value = literalArguments.get(i); checkArgument(value instanceof String, "Expected literalArgument %d in %s to be a string", i, literalArguments); - convertedArguments.add(new ClientTypeSignatureParameter(TypeSignatureParameter.of(new NamedTypeSignature( + convertedArguments.add(ClientTypeSignatureParameter.ofNamedType(new NamedClientTypeSignature( Optional.of(new RowFieldName((String) value, false)), - toTypeSignature(typeArguments.get(i)))))); + typeArguments.get(i)))); } } else { @@ -100,28 +91,6 @@ public ClientTypeSignature( } } - private static TypeSignature toTypeSignature(ClientTypeSignature signature) - { - List parameters = signature.getArguments().stream() - .map(ClientTypeSignature::legacyClientTypeSignatureParameterToTypeSignatureParameter) - .collect(toList()); - return new TypeSignature(signature.getRawType(), parameters); - } - - private static TypeSignatureParameter legacyClientTypeSignatureParameterToTypeSignatureParameter(ClientTypeSignatureParameter parameter) - { - switch (parameter.getKind()) { - case LONG: - throw new UnsupportedOperationException("Unexpected long type literal returned by legacy server"); - case TYPE: - return TypeSignatureParameter.of(toTypeSignature(parameter.getTypeSignature())); - case NAMED_TYPE: - return TypeSignatureParameter.of(parameter.getNamedTypeSignature()); - default: - throw new UnsupportedOperationException("Unknown parameter kind " + parameter.getKind()); - } - } - @JsonProperty public String getRawType() { @@ -157,7 +126,7 @@ public List getTypeArguments() result.add(argument.getTypeSignature()); break; case NAMED_TYPE: - result.add(new ClientTypeSignature(argument.getNamedTypeSignature().getTypeSignature())); + result.add(argument.getNamedTypeSignature().getTypeSignature()); break; default: return new ArrayList<>(); diff --git a/presto-client/src/main/java/io/prestosql/client/ClientTypeSignatureParameter.java b/presto-client/src/main/java/io/prestosql/client/ClientTypeSignatureParameter.java index 9abb73484b0..776721a432b 100644 --- a/presto-client/src/main/java/io/prestosql/client/ClientTypeSignatureParameter.java +++ b/presto-client/src/main/java/io/prestosql/client/ClientTypeSignatureParameter.java @@ -22,9 +22,6 @@ import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.annotation.JsonDeserialize; import io.airlift.json.ObjectMapperProvider; -import io.prestosql.spi.type.NamedTypeSignature; -import io.prestosql.spi.type.ParameterKind; -import io.prestosql.spi.type.TypeSignatureParameter; import javax.annotation.concurrent.Immutable; @@ -40,22 +37,19 @@ public class ClientTypeSignatureParameter private final ParameterKind kind; private final Object value; - public ClientTypeSignatureParameter(TypeSignatureParameter typeParameterSignature) + public static ClientTypeSignatureParameter ofType(ClientTypeSignature typeSignature) { - this.kind = typeParameterSignature.getKind(); - switch (kind) { - case TYPE: - value = new ClientTypeSignature(typeParameterSignature.getTypeSignature()); - break; - case LONG: - value = typeParameterSignature.getLongLiteral(); - break; - case NAMED_TYPE: - value = typeParameterSignature.getNamedTypeSignature(); - break; - default: - throw new UnsupportedOperationException(format("Unknown kind [%s]", kind)); - } + return new ClientTypeSignatureParameter(ParameterKind.TYPE, typeSignature); + } + + public static ClientTypeSignatureParameter ofNamedType(NamedClientTypeSignature namedTypeSignature) + { + return new ClientTypeSignatureParameter(ParameterKind.NAMED_TYPE, namedTypeSignature); + } + + public static ClientTypeSignatureParameter ofLong(long longLiteral) + { + return new ClientTypeSignatureParameter(ParameterKind.LONG, longLiteral); } @JsonCreator @@ -97,9 +91,9 @@ public Long getLongLiteral() return getValue(ParameterKind.LONG, Long.class); } - public NamedTypeSignature getNamedTypeSignature() + public NamedClientTypeSignature getNamedTypeSignature() { - return getValue(ParameterKind.NAMED_TYPE, NamedTypeSignature.class); + return getValue(ParameterKind.NAMED_TYPE, NamedClientTypeSignature.class); } @Override @@ -148,7 +142,7 @@ public ClientTypeSignatureParameter deserialize(JsonParser jp, DeserializationCo value = MAPPER.readValue(jsonValue, ClientTypeSignature.class); break; case NAMED_TYPE: - value = MAPPER.readValue(jsonValue, NamedTypeSignature.class); + value = MAPPER.readValue(jsonValue, NamedClientTypeSignature.class); break; case LONG: value = MAPPER.readValue(jsonValue, Long.class); diff --git a/presto-client/src/main/java/io/prestosql/client/Column.java b/presto-client/src/main/java/io/prestosql/client/Column.java index dbd7a32b001..90452f07b75 100644 --- a/presto-client/src/main/java/io/prestosql/client/Column.java +++ b/presto-client/src/main/java/io/prestosql/client/Column.java @@ -15,8 +15,6 @@ import com.fasterxml.jackson.annotation.JsonCreator; import com.fasterxml.jackson.annotation.JsonProperty; -import io.prestosql.spi.type.Type; -import io.prestosql.spi.type.TypeSignature; import javax.annotation.concurrent.Immutable; @@ -29,16 +27,6 @@ public class Column private final String type; private final ClientTypeSignature typeSignature; - public Column(String name, Type type) - { - this(name, type.getTypeSignature()); - } - - public Column(String name, TypeSignature signature) - { - this(name, signature.toString(), new ClientTypeSignature(signature)); - } - @JsonCreator public Column( @JsonProperty("name") String name, diff --git a/presto-client/src/main/java/io/prestosql/client/FixJsonDataUtils.java b/presto-client/src/main/java/io/prestosql/client/FixJsonDataUtils.java index 68780701644..dace9a53f2b 100644 --- a/presto-client/src/main/java/io/prestosql/client/FixJsonDataUtils.java +++ b/presto-client/src/main/java/io/prestosql/client/FixJsonDataUtils.java @@ -14,8 +14,6 @@ package io.prestosql.client; import com.google.common.collect.ImmutableList; -import io.prestosql.spi.type.NamedTypeSignature; -import io.prestosql.spi.type.ParameterKind; import java.util.ArrayList; import java.util.Base64; @@ -114,9 +112,9 @@ private static Object fixValue(ClientTypeSignature signature, Object value) parameter.getKind() == ParameterKind.NAMED_TYPE, "Unexpected parameter [%s] for row type", parameter); - NamedTypeSignature namedTypeSignature = parameter.getNamedTypeSignature(); + NamedClientTypeSignature namedTypeSignature = parameter.getNamedTypeSignature(); String key = namedTypeSignature.getName().orElse("field" + i); - fixedValue.put(key, fixValue(new ClientTypeSignature(namedTypeSignature.getTypeSignature()), listValue.get(i))); + fixedValue.put(key, fixValue(namedTypeSignature.getTypeSignature(), listValue.get(i))); } return fixedValue; } diff --git a/presto-client/src/main/java/io/prestosql/client/NamedClientTypeSignature.java b/presto-client/src/main/java/io/prestosql/client/NamedClientTypeSignature.java new file mode 100644 index 00000000000..c857cd5a6fb --- /dev/null +++ b/presto-client/src/main/java/io/prestosql/client/NamedClientTypeSignature.java @@ -0,0 +1,86 @@ +/* + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package io.prestosql.client; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonProperty; + +import java.util.Objects; +import java.util.Optional; + +import static java.lang.String.format; +import static java.util.Objects.requireNonNull; + +public class NamedClientTypeSignature +{ + private final Optional fieldName; + private final ClientTypeSignature typeSignature; + + @JsonCreator + public NamedClientTypeSignature( + @JsonProperty("fieldName") Optional fieldName, + @JsonProperty("typeSignature") ClientTypeSignature typeSignature) + { + this.fieldName = requireNonNull(fieldName, "fieldName is null"); + this.typeSignature = requireNonNull(typeSignature, "typeSignature is null"); + } + + @JsonProperty + public Optional getFieldName() + { + return fieldName; + } + + @JsonProperty + public ClientTypeSignature getTypeSignature() + { + return typeSignature; + } + + public Optional getName() + { + return getFieldName().map(RowFieldName::getName); + } + + @Override + public boolean equals(Object o) + { + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } + + NamedClientTypeSignature other = (NamedClientTypeSignature) o; + + return Objects.equals(this.fieldName, other.fieldName) && + Objects.equals(this.typeSignature, other.typeSignature); + } + + @Override + public String toString() + { + if (fieldName.isPresent()) { + return format("%s %s", fieldName.get(), typeSignature); + } + return typeSignature.toString(); + } + + @Override + public int hashCode() + { + return Objects.hash(fieldName, typeSignature); + } +} diff --git a/presto-client/src/main/java/io/prestosql/client/ParameterKind.java b/presto-client/src/main/java/io/prestosql/client/ParameterKind.java new file mode 100644 index 00000000000..70ac72637bc --- /dev/null +++ b/presto-client/src/main/java/io/prestosql/client/ParameterKind.java @@ -0,0 +1,57 @@ +/* + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package io.prestosql.client; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonValue; + +import java.util.Optional; + +public enum ParameterKind +{ + TYPE(Optional.of("TYPE_SIGNATURE")), + NAMED_TYPE(Optional.of("NAMED_TYPE_SIGNATURE")), + LONG(Optional.of("LONG_LITERAL")), + VARIABLE(Optional.empty()); + + // TODO: drop special serialization code as soon as all clients + // migrate to version which can deserialize new format. + + private final Optional oldName; + + ParameterKind(Optional oldName) + { + this.oldName = oldName; + } + + @JsonValue + public String jsonName() + { + return oldName.orElse(name()); + } + + @JsonCreator + public static ParameterKind fromJsonValue(String value) + { + for (ParameterKind kind : values()) { + if (kind.oldName.isPresent() && kind.oldName.get().equals(value)) { + return kind; + } + if (kind.name().equals(value)) { + return kind; + } + } + throw new IllegalArgumentException("Invalid serialized ParameterKind value: " + value); + } +} diff --git a/presto-client/src/main/java/io/prestosql/client/RowFieldName.java b/presto-client/src/main/java/io/prestosql/client/RowFieldName.java new file mode 100644 index 00000000000..a0feda34581 --- /dev/null +++ b/presto-client/src/main/java/io/prestosql/client/RowFieldName.java @@ -0,0 +1,79 @@ +/* + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package io.prestosql.client; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonProperty; + +import java.util.Objects; + +import static java.util.Objects.requireNonNull; + +public class RowFieldName +{ + private final String name; + private final boolean delimited; + + @JsonCreator + public RowFieldName( + @JsonProperty("name") String name, + @JsonProperty("delimited") boolean delimited) + { + this.name = requireNonNull(name, "name is null"); + this.delimited = delimited; + } + + @JsonProperty + public String getName() + { + return name; + } + + @JsonProperty + public boolean isDelimited() + { + return delimited; + } + + @Override + public boolean equals(Object o) + { + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } + + RowFieldName other = (RowFieldName) o; + + return Objects.equals(this.name, other.name) && + Objects.equals(this.delimited, other.delimited); + } + + @Override + public String toString() + { + if (!isDelimited()) { + return name; + } + return '"' + name.replace("\"", "\"\"") + '"'; + } + + @Override + public int hashCode() + { + return Objects.hash(name, delimited); + } +} diff --git a/presto-client/src/test/java/io/prestosql/client/TestClientTypeSignature.java b/presto-client/src/test/java/io/prestosql/client/TestClientTypeSignature.java index 41a19526cd7..eb5258e97e6 100644 --- a/presto-client/src/test/java/io/prestosql/client/TestClientTypeSignature.java +++ b/presto-client/src/test/java/io/prestosql/client/TestClientTypeSignature.java @@ -17,16 +17,11 @@ import io.airlift.json.JsonCodec; import io.airlift.json.JsonCodecFactory; import io.airlift.json.ObjectMapperProvider; -import io.prestosql.spi.type.NamedTypeSignature; -import io.prestosql.spi.type.RowFieldName; import io.prestosql.spi.type.StandardTypes; -import io.prestosql.spi.type.TypeSignature; -import io.prestosql.spi.type.TypeSignatureParameter; import org.testng.annotations.Test; import java.util.Optional; -import static io.prestosql.spi.type.BigintType.BIGINT; import static org.testng.Assert.assertEquals; public class TestClientTypeSignature @@ -42,25 +37,25 @@ public class TestClientTypeSignature @Test public void testJsonRoundTrip() { - TypeSignature bigint = BIGINT.getTypeSignature(); - assertJsonRoundTrip(new ClientTypeSignature(bigint)); + ClientTypeSignature bigint = new ClientTypeSignature(StandardTypes.BIGINT); + assertJsonRoundTrip(bigint); assertJsonRoundTrip(new ClientTypeSignature( "array", - ImmutableList.of(new ClientTypeSignatureParameter(TypeSignatureParameter.of(bigint))))); + ImmutableList.of(ClientTypeSignatureParameter.ofType(bigint)))); assertJsonRoundTrip(new ClientTypeSignature( "foo", - ImmutableList.of(new ClientTypeSignatureParameter(TypeSignatureParameter.of(42))))); + ImmutableList.of(ClientTypeSignatureParameter.ofLong(42)))); assertJsonRoundTrip(new ClientTypeSignature( "row", ImmutableList.of( - new ClientTypeSignatureParameter(TypeSignatureParameter.of(new NamedTypeSignature(Optional.of(new RowFieldName("foo", false)), bigint))), - new ClientTypeSignatureParameter(TypeSignatureParameter.of(new NamedTypeSignature(Optional.of(new RowFieldName("bar", false)), bigint)))))); + ClientTypeSignatureParameter.ofNamedType(new NamedClientTypeSignature(Optional.of(new RowFieldName("foo", false)), bigint)), + ClientTypeSignatureParameter.ofNamedType(new NamedClientTypeSignature(Optional.of(new RowFieldName("bar", false)), bigint))))); } @Test public void testBackwardsCompatible() { - ClientTypeSignature signature = new ClientTypeSignature(StandardTypes.ARRAY, ImmutableList.of(new ClientTypeSignatureParameter(TypeSignatureParameter.of(BIGINT.getTypeSignature())))); + ClientTypeSignature signature = new ClientTypeSignature(StandardTypes.ARRAY, ImmutableList.of(ClientTypeSignatureParameter.ofType(new ClientTypeSignature(StandardTypes.BIGINT)))); ClientTypeSignature legacy = CLIENT_TYPE_SIGNATURE_CODEC.fromJson("{\"rawType\":\"array\",\"literalArguments\":[],\"typeArguments\":[{\"rawType\":\"bigint\",\"literalArguments\":[],\"typeArguments\":[]}]}"); assertEquals(legacy, signature); } diff --git a/presto-client/src/test/java/io/prestosql/client/TestFixJsonDataUtils.java b/presto-client/src/test/java/io/prestosql/client/TestFixJsonDataUtils.java index 6fae67cc916..dd4b5c50a82 100644 --- a/presto-client/src/test/java/io/prestosql/client/TestFixJsonDataUtils.java +++ b/presto-client/src/test/java/io/prestosql/client/TestFixJsonDataUtils.java @@ -15,11 +15,14 @@ import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableMap; +import io.prestosql.spi.type.TypeSignature; +import io.prestosql.spi.type.TypeSignatureParameter; import org.testng.annotations.Test; import java.util.Base64; import java.util.List; +import static com.google.common.collect.ImmutableList.toImmutableList; import static com.google.common.collect.Lists.newArrayList; import static io.prestosql.client.FixJsonDataUtils.fixData; import static io.prestosql.spi.type.TypeSignature.parseTypeSignature; @@ -59,11 +62,35 @@ public void testFixData() private void assertQueryResult(String type, Object data, Object expected) { + TypeSignature signature = parseTypeSignature(type); List> rows = newArrayList(fixData( - ImmutableList.of(new Column("test", parseTypeSignature(type))), + ImmutableList.of(new Column("test", signature.toString(), toClientTypeSignature(signature))), ImmutableList.of(ImmutableList.of(data)))); assertEquals(rows.size(), 1); assertEquals(rows.get(0).size(), 1); assertEquals(rows.get(0).get(0), expected); } + + private static ClientTypeSignature toClientTypeSignature(TypeSignature signature) + { + return new ClientTypeSignature(signature.getBase(), signature.getParameters().stream() + .map(TestFixJsonDataUtils::toClientTypeSignatureParameter) + .collect(toImmutableList())); + } + + private static ClientTypeSignatureParameter toClientTypeSignatureParameter(TypeSignatureParameter parameter) + { + switch (parameter.getKind()) { + case TYPE: + return ClientTypeSignatureParameter.ofType(toClientTypeSignature(parameter.getTypeSignature())); + case NAMED_TYPE: + return ClientTypeSignatureParameter.ofNamedType(new NamedClientTypeSignature( + parameter.getNamedTypeSignature().getFieldName().map(value -> + new RowFieldName(value.getName(), value.isDelimited())), + toClientTypeSignature(parameter.getNamedTypeSignature().getTypeSignature()))); + case LONG: + return ClientTypeSignatureParameter.ofLong(parameter.getLongLiteral()); + } + throw new IllegalArgumentException("Unsupported kind: " + parameter.getKind()); + } } diff --git a/presto-spi/src/test/java/io/prestosql/spi/type/TestParameterKind.java b/presto-client/src/test/java/io/prestosql/client/TestParameterKind.java similarity index 98% rename from presto-spi/src/test/java/io/prestosql/spi/type/TestParameterKind.java rename to presto-client/src/test/java/io/prestosql/client/TestParameterKind.java index 745bc1fc37c..2e09af09a56 100644 --- a/presto-spi/src/test/java/io/prestosql/spi/type/TestParameterKind.java +++ b/presto-client/src/test/java/io/prestosql/client/TestParameterKind.java @@ -11,7 +11,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package io.prestosql.spi.type; +package io.prestosql.client; import io.airlift.json.JsonCodec; import io.airlift.json.JsonCodecFactory; diff --git a/presto-jdbc/src/test/java/io/prestosql/jdbc/TestProgressMonitor.java b/presto-jdbc/src/test/java/io/prestosql/jdbc/TestProgressMonitor.java index 35d1506917e..d9597f7ae17 100644 --- a/presto-jdbc/src/test/java/io/prestosql/jdbc/TestProgressMonitor.java +++ b/presto-jdbc/src/test/java/io/prestosql/jdbc/TestProgressMonitor.java @@ -15,10 +15,11 @@ import com.google.common.collect.ImmutableList; import io.airlift.json.JsonCodec; +import io.prestosql.client.ClientTypeSignature; import io.prestosql.client.Column; import io.prestosql.client.QueryResults; import io.prestosql.client.StatementStats; -import io.prestosql.spi.type.BigintType; +import io.prestosql.spi.type.StandardTypes; import okhttp3.mockwebserver.MockResponse; import okhttp3.mockwebserver.MockWebServer; import org.testng.annotations.AfterMethod; @@ -68,7 +69,7 @@ public void teardown() private List createResults() { - List columns = ImmutableList.of(new Column("_col0", BigintType.BIGINT)); + List columns = ImmutableList.of(new Column("_col0", StandardTypes.BIGINT, new ClientTypeSignature(StandardTypes.BIGINT))); return ImmutableList.builder() .add(newQueryResults(null, 1, null, null, "QUEUED")) .add(newQueryResults(1, 2, columns, null, "RUNNING")) diff --git a/presto-main/src/main/java/io/prestosql/server/protocol/Query.java b/presto-main/src/main/java/io/prestosql/server/protocol/Query.java index 1e79db9560d..8d9f30547df 100644 --- a/presto-main/src/main/java/io/prestosql/server/protocol/Query.java +++ b/presto-main/src/main/java/io/prestosql/server/protocol/Query.java @@ -26,10 +26,14 @@ import io.airlift.units.DataSize; import io.airlift.units.Duration; import io.prestosql.Session; +import io.prestosql.client.ClientTypeSignature; +import io.prestosql.client.ClientTypeSignatureParameter; import io.prestosql.client.Column; import io.prestosql.client.FailureInfo; +import io.prestosql.client.NamedClientTypeSignature; import io.prestosql.client.QueryError; import io.prestosql.client.QueryResults; +import io.prestosql.client.RowFieldName; import io.prestosql.client.StageStats; import io.prestosql.client.StatementStats; import io.prestosql.client.Warning; @@ -55,6 +59,8 @@ import io.prestosql.spi.type.BooleanType; import io.prestosql.spi.type.StandardTypes; import io.prestosql.spi.type.Type; +import io.prestosql.spi.type.TypeSignature; +import io.prestosql.spi.type.TypeSignatureParameter; import io.prestosql.transaction.TransactionId; import javax.annotation.concurrent.GuardedBy; @@ -78,6 +84,7 @@ import static com.google.common.base.MoreObjects.firstNonNull; import static com.google.common.base.Preconditions.checkArgument; +import static com.google.common.collect.ImmutableList.toImmutableList; import static com.google.common.util.concurrent.Futures.immediateFuture; import static com.google.common.util.concurrent.MoreExecutors.directExecutor; import static io.airlift.concurrent.MoreFutures.addSuccessCallback; @@ -455,7 +462,7 @@ public synchronized QueryResults getNextResult(OptionalLong token, UriInfo uriIn // for queries with no output, return a fake result for clients that require it if ((queryInfo.getState() == QueryState.FINISHED) && !queryInfo.getOutputStage().isPresent()) { - columns = ImmutableList.of(new Column("result", BooleanType.BOOLEAN)); + columns = ImmutableList.of(createColumn("result", BooleanType.BOOLEAN)); data = ImmutableSet.of(ImmutableList.of(true)); } @@ -537,7 +544,7 @@ private synchronized void setQueryOutputInfo(QueryExecution.QueryOutputInfo outp ImmutableList.Builder list = ImmutableList.builder(); for (int i = 0; i < columnNames.size(); i++) { - list.add(new Column(columnNames.get(i), columnTypes.get(i))); + list.add(createColumn(columnNames.get(i), columnTypes.get(i))); } columns = list.build(); types = outputInfo.getColumnTypes(); @@ -570,6 +577,35 @@ private synchronized URI createNextResultsUri(String scheme, UriInfo uriInfo) .build(); } + private static Column createColumn(String name, Type type) + { + TypeSignature signature = type.getTypeSignature(); + return new Column(name, signature.toString(), toClientTypeSignature(signature)); + } + + private static ClientTypeSignature toClientTypeSignature(TypeSignature signature) + { + return new ClientTypeSignature(signature.getBase(), signature.getParameters().stream() + .map(Query::toClientTypeSignatureParameter) + .collect(toImmutableList())); + } + + private static ClientTypeSignatureParameter toClientTypeSignatureParameter(TypeSignatureParameter parameter) + { + switch (parameter.getKind()) { + case TYPE: + return ClientTypeSignatureParameter.ofType(toClientTypeSignature(parameter.getTypeSignature())); + case NAMED_TYPE: + return ClientTypeSignatureParameter.ofNamedType(new NamedClientTypeSignature( + parameter.getNamedTypeSignature().getFieldName().map(value -> + new RowFieldName(value.getName(), value.isDelimited())), + toClientTypeSignature(parameter.getNamedTypeSignature().getTypeSignature()))); + case LONG: + return ClientTypeSignatureParameter.ofLong(parameter.getLongLiteral()); + } + throw new IllegalArgumentException("Unsupported kind: " + parameter.getKind()); + } + private static StatementStats toStatementStats(QueryInfo queryInfo) { QueryStats queryStats = queryInfo.getQueryStats(); diff --git a/presto-spi/src/main/java/io/prestosql/spi/type/NamedTypeSignature.java b/presto-spi/src/main/java/io/prestosql/spi/type/NamedTypeSignature.java index 1b5afd68a1b..c04a9cb99fe 100644 --- a/presto-spi/src/main/java/io/prestosql/spi/type/NamedTypeSignature.java +++ b/presto-spi/src/main/java/io/prestosql/spi/type/NamedTypeSignature.java @@ -13,9 +13,6 @@ */ package io.prestosql.spi.type; -import com.fasterxml.jackson.annotation.JsonCreator; -import com.fasterxml.jackson.annotation.JsonProperty; - import java.util.Objects; import java.util.Optional; @@ -27,22 +24,17 @@ public class NamedTypeSignature private final Optional fieldName; private final TypeSignature typeSignature; - @JsonCreator - public NamedTypeSignature( - @JsonProperty("fieldName") Optional fieldName, - @JsonProperty("typeSignature") TypeSignature typeSignature) + public NamedTypeSignature(Optional fieldName, TypeSignature typeSignature) { this.fieldName = requireNonNull(fieldName, "fieldName is null"); this.typeSignature = requireNonNull(typeSignature, "typeSignature is null"); } - @JsonProperty public Optional getFieldName() { return fieldName; } - @JsonProperty public TypeSignature getTypeSignature() { return typeSignature; diff --git a/presto-spi/src/main/java/io/prestosql/spi/type/ParameterKind.java b/presto-spi/src/main/java/io/prestosql/spi/type/ParameterKind.java index f28d4500fe6..cdd91eecde3 100644 --- a/presto-spi/src/main/java/io/prestosql/spi/type/ParameterKind.java +++ b/presto-spi/src/main/java/io/prestosql/spi/type/ParameterKind.java @@ -13,45 +13,7 @@ */ package io.prestosql.spi.type; -import com.fasterxml.jackson.annotation.JsonCreator; -import com.fasterxml.jackson.annotation.JsonValue; - -import java.util.Optional; - public enum ParameterKind { - TYPE(Optional.of("TYPE_SIGNATURE")), - NAMED_TYPE(Optional.of("NAMED_TYPE_SIGNATURE")), - LONG(Optional.of("LONG_LITERAL")), - VARIABLE(Optional.empty()); - - // TODO: drop special serialization code as soon as all clients - // migrate to version which can deserialize new format. - - private final Optional oldName; - - ParameterKind(Optional oldName) - { - this.oldName = oldName; - } - - @JsonValue - public String jsonName() - { - return oldName.orElse(name()); - } - - @JsonCreator - public static ParameterKind fromJsonValue(String value) - { - for (ParameterKind kind : values()) { - if (kind.oldName.isPresent() && kind.oldName.get().equals(value)) { - return kind; - } - if (kind.name().equals(value)) { - return kind; - } - } - throw new IllegalArgumentException("Invalid serialized ParameterKind value: " + value); - } + TYPE, NAMED_TYPE, LONG, VARIABLE } diff --git a/presto-spi/src/main/java/io/prestosql/spi/type/RowFieldName.java b/presto-spi/src/main/java/io/prestosql/spi/type/RowFieldName.java index 48dafcf4f4b..51aab02c175 100644 --- a/presto-spi/src/main/java/io/prestosql/spi/type/RowFieldName.java +++ b/presto-spi/src/main/java/io/prestosql/spi/type/RowFieldName.java @@ -13,9 +13,6 @@ */ package io.prestosql.spi.type; -import com.fasterxml.jackson.annotation.JsonCreator; -import com.fasterxml.jackson.annotation.JsonProperty; - import java.util.Objects; import static java.util.Objects.requireNonNull; @@ -25,22 +22,17 @@ public class RowFieldName private final String name; private final boolean delimited; - @JsonCreator - public RowFieldName( - @JsonProperty("name") String name, - @JsonProperty("delimited") boolean delimited) + public RowFieldName(String name, boolean delimited) { this.name = requireNonNull(name, "name is null"); this.delimited = delimited; } - @JsonProperty public String getName() { return name; } - @JsonProperty public boolean isDelimited() { return delimited; From 907b3ebb1ed1f14eba5df8cb9efdb08758c73fa3 Mon Sep 17 00:00:00 2001 From: David Phillips Date: Thu, 27 Dec 2018 17:02:31 -0800 Subject: [PATCH 5/5] Remove SPI as dependency for JDBC driver --- presto-cli/pom.xml | 7 --- .../io/prestosql/cli/TestQueryRunner.java | 4 +- presto-client/pom.xml | 11 +++-- .../prestosql/client/ClientStandardTypes.java | 48 +++++++++++++++++++ .../prestosql/client/ClientTypeSignature.java | 6 +-- .../io/prestosql/client/FixJsonDataUtils.java | 48 +++++++++---------- 6 files changed, 83 insertions(+), 41 deletions(-) create mode 100644 presto-client/src/main/java/io/prestosql/client/ClientStandardTypes.java diff --git a/presto-cli/pom.xml b/presto-cli/pom.xml index f81de5f9c74..80e99a337bc 100644 --- a/presto-cli/pom.xml +++ b/presto-cli/pom.xml @@ -88,13 +88,6 @@ okhttp - - - io.prestosql - presto-spi - runtime - - org.testng 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 471c1cffd63..d81ff9ac11b 100644 --- a/presto-cli/src/test/java/io/prestosql/cli/TestQueryRunner.java +++ b/presto-cli/src/test/java/io/prestosql/cli/TestQueryRunner.java @@ -23,7 +23,6 @@ import io.prestosql.client.Column; import io.prestosql.client.QueryResults; import io.prestosql.client.StatementStats; -import io.prestosql.spi.type.StandardTypes; import okhttp3.mockwebserver.MockResponse; import okhttp3.mockwebserver.MockWebServer; import org.testng.annotations.AfterMethod; @@ -43,6 +42,7 @@ import static com.google.common.net.HttpHeaders.SET_COOKIE; import static io.airlift.json.JsonCodec.jsonCodec; import static io.prestosql.cli.ClientOptions.OutputFormat.CSV; +import static io.prestosql.client.ClientStandardTypes.BIGINT; import static java.util.concurrent.TimeUnit.MINUTES; import static org.testng.Assert.assertEquals; @@ -119,7 +119,7 @@ private String createResults() server.url("/query.html?20160128_214710_00012_rk68b").uri(), null, null, - ImmutableList.of(new Column("_col0", StandardTypes.BIGINT, new ClientTypeSignature(StandardTypes.BIGINT))), + ImmutableList.of(new Column("_col0", BIGINT, new ClientTypeSignature(BIGINT))), ImmutableList.of(ImmutableList.of(123)), StatementStats.builder().setState("FINISHED").build(), //new StatementStats("FINISHED", false, true, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, null), diff --git a/presto-client/pom.xml b/presto-client/pom.xml index 30bf1ba8836..5b1c1a02631 100644 --- a/presto-client/pom.xml +++ b/presto-client/pom.xml @@ -16,11 +16,6 @@ - - io.prestosql - presto-spi - - com.google.code.findbugs jsr305 @@ -73,6 +68,12 @@ + + io.prestosql + presto-spi + test + + org.testng testng diff --git a/presto-client/src/main/java/io/prestosql/client/ClientStandardTypes.java b/presto-client/src/main/java/io/prestosql/client/ClientStandardTypes.java new file mode 100644 index 00000000000..12e13425d15 --- /dev/null +++ b/presto-client/src/main/java/io/prestosql/client/ClientStandardTypes.java @@ -0,0 +1,48 @@ +/* + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package io.prestosql.client; + +public final class ClientStandardTypes +{ + public static final String BIGINT = "bigint"; + public static final String INTEGER = "integer"; + public static final String SMALLINT = "smallint"; + public static final String TINYINT = "tinyint"; + public static final String BOOLEAN = "boolean"; + public static final String DATE = "date"; + public static final String DECIMAL = "decimal"; + public static final String REAL = "real"; + public static final String DOUBLE = "double"; + public static final String HYPER_LOG_LOG = "HyperLogLog"; + public static final String QDIGEST = "qdigest"; + public static final String P4_HYPER_LOG_LOG = "P4HyperLogLog"; + public static final String INTERVAL_DAY_TO_SECOND = "interval day to second"; + public static final String INTERVAL_YEAR_TO_MONTH = "interval year to month"; + public static final String TIMESTAMP = "timestamp"; + public static final String TIMESTAMP_WITH_TIME_ZONE = "timestamp with time zone"; + public static final String TIME = "time"; + public static final String TIME_WITH_TIME_ZONE = "time with time zone"; + public static final String VARBINARY = "varbinary"; + public static final String VARCHAR = "varchar"; + public static final String CHAR = "char"; + public static final String ROW = "row"; + public static final String ARRAY = "array"; + public static final String MAP = "map"; + public static final String JSON = "json"; + public static final String IPADDRESS = "ipaddress"; + public static final String GEOMETRY = "Geometry"; + public static final String BING_TILE = "BingTile"; + + private ClientStandardTypes() {} +} diff --git a/presto-client/src/main/java/io/prestosql/client/ClientTypeSignature.java b/presto-client/src/main/java/io/prestosql/client/ClientTypeSignature.java index 19efa16b2d2..1a7321e4b05 100644 --- a/presto-client/src/main/java/io/prestosql/client/ClientTypeSignature.java +++ b/presto-client/src/main/java/io/prestosql/client/ClientTypeSignature.java @@ -16,7 +16,6 @@ import com.fasterxml.jackson.annotation.JsonCreator; import com.fasterxml.jackson.annotation.JsonProperty; import com.google.common.collect.ImmutableList; -import io.prestosql.spi.type.StandardTypes; import javax.annotation.concurrent.Immutable; @@ -31,6 +30,7 @@ import static com.google.common.base.Preconditions.checkArgument; import static com.google.common.base.Preconditions.checkState; import static com.google.common.collect.ImmutableList.toImmutableList; +import static io.prestosql.client.ClientStandardTypes.ROW; import static java.lang.String.format; import static java.util.Collections.unmodifiableList; import static java.util.Objects.requireNonNull; @@ -71,7 +71,7 @@ public ClientTypeSignature( requireNonNull(literalArguments, "literalArguments is null"); ImmutableList.Builder convertedArguments = ImmutableList.builder(); // Talking to a legacy server (< 0.133) - if (rawType.equals(StandardTypes.ROW)) { + if (rawType.equals(ROW)) { checkArgument(typeArguments.size() == literalArguments.size()); for (int i = 0; i < typeArguments.size(); i++) { Object value = literalArguments.get(i); @@ -158,7 +158,7 @@ public List getLiteralArguments() @Override public String toString() { - if (rawType.equals(StandardTypes.ROW)) { + if (rawType.equals(ROW)) { return rowToString(); } else { diff --git a/presto-client/src/main/java/io/prestosql/client/FixJsonDataUtils.java b/presto-client/src/main/java/io/prestosql/client/FixJsonDataUtils.java index dace9a53f2b..cda26625247 100644 --- a/presto-client/src/main/java/io/prestosql/client/FixJsonDataUtils.java +++ b/presto-client/src/main/java/io/prestosql/client/FixJsonDataUtils.java @@ -24,30 +24,30 @@ import java.util.Set; import static com.google.common.base.Preconditions.checkArgument; -import static io.prestosql.spi.type.StandardTypes.ARRAY; -import static io.prestosql.spi.type.StandardTypes.BIGINT; -import static io.prestosql.spi.type.StandardTypes.BING_TILE; -import static io.prestosql.spi.type.StandardTypes.BOOLEAN; -import static io.prestosql.spi.type.StandardTypes.CHAR; -import static io.prestosql.spi.type.StandardTypes.DATE; -import static io.prestosql.spi.type.StandardTypes.DECIMAL; -import static io.prestosql.spi.type.StandardTypes.DOUBLE; -import static io.prestosql.spi.type.StandardTypes.GEOMETRY; -import static io.prestosql.spi.type.StandardTypes.INTEGER; -import static io.prestosql.spi.type.StandardTypes.INTERVAL_DAY_TO_SECOND; -import static io.prestosql.spi.type.StandardTypes.INTERVAL_YEAR_TO_MONTH; -import static io.prestosql.spi.type.StandardTypes.IPADDRESS; -import static io.prestosql.spi.type.StandardTypes.JSON; -import static io.prestosql.spi.type.StandardTypes.MAP; -import static io.prestosql.spi.type.StandardTypes.REAL; -import static io.prestosql.spi.type.StandardTypes.ROW; -import static io.prestosql.spi.type.StandardTypes.SMALLINT; -import static io.prestosql.spi.type.StandardTypes.TIME; -import static io.prestosql.spi.type.StandardTypes.TIMESTAMP; -import static io.prestosql.spi.type.StandardTypes.TIMESTAMP_WITH_TIME_ZONE; -import static io.prestosql.spi.type.StandardTypes.TIME_WITH_TIME_ZONE; -import static io.prestosql.spi.type.StandardTypes.TINYINT; -import static io.prestosql.spi.type.StandardTypes.VARCHAR; +import static io.prestosql.client.ClientStandardTypes.ARRAY; +import static io.prestosql.client.ClientStandardTypes.BIGINT; +import static io.prestosql.client.ClientStandardTypes.BING_TILE; +import static io.prestosql.client.ClientStandardTypes.BOOLEAN; +import static io.prestosql.client.ClientStandardTypes.CHAR; +import static io.prestosql.client.ClientStandardTypes.DATE; +import static io.prestosql.client.ClientStandardTypes.DECIMAL; +import static io.prestosql.client.ClientStandardTypes.DOUBLE; +import static io.prestosql.client.ClientStandardTypes.GEOMETRY; +import static io.prestosql.client.ClientStandardTypes.INTEGER; +import static io.prestosql.client.ClientStandardTypes.INTERVAL_DAY_TO_SECOND; +import static io.prestosql.client.ClientStandardTypes.INTERVAL_YEAR_TO_MONTH; +import static io.prestosql.client.ClientStandardTypes.IPADDRESS; +import static io.prestosql.client.ClientStandardTypes.JSON; +import static io.prestosql.client.ClientStandardTypes.MAP; +import static io.prestosql.client.ClientStandardTypes.REAL; +import static io.prestosql.client.ClientStandardTypes.ROW; +import static io.prestosql.client.ClientStandardTypes.SMALLINT; +import static io.prestosql.client.ClientStandardTypes.TIME; +import static io.prestosql.client.ClientStandardTypes.TIMESTAMP; +import static io.prestosql.client.ClientStandardTypes.TIMESTAMP_WITH_TIME_ZONE; +import static io.prestosql.client.ClientStandardTypes.TIME_WITH_TIME_ZONE; +import static io.prestosql.client.ClientStandardTypes.TINYINT; +import static io.prestosql.client.ClientStandardTypes.VARCHAR; import static java.util.Collections.unmodifiableList; import static java.util.Objects.requireNonNull; import static java.util.stream.Collectors.toList;