diff --git a/hetu-oracle/pom.xml b/hetu-oracle/pom.xml index 3e8501975..245e6fd08 100644 --- a/hetu-oracle/pom.xml +++ b/hetu-oracle/pom.xml @@ -175,7 +175,6 @@ io.hetu.core presto-parser - test diff --git a/presto-base-jdbc/pom.xml b/presto-base-jdbc/pom.xml index badd9391c..8645674a3 100644 --- a/presto-base-jdbc/pom.xml +++ b/presto-base-jdbc/pom.xml @@ -190,7 +190,6 @@ io.hetu.core presto-parser - test diff --git a/presto-base-jdbc/src/main/java/io/prestosql/sql/builder/BaseSqlQueryWriter.java b/presto-base-jdbc/src/main/java/io/prestosql/sql/builder/BaseSqlQueryWriter.java index 09a9c5d62..1407f335c 100644 --- a/presto-base-jdbc/src/main/java/io/prestosql/sql/builder/BaseSqlQueryWriter.java +++ b/presto-base-jdbc/src/main/java/io/prestosql/sql/builder/BaseSqlQueryWriter.java @@ -14,7 +14,6 @@ */ package io.prestosql.sql.builder; -import com.google.common.base.CharMatcher; import com.google.common.base.Joiner; import com.google.common.collect.ImmutableList; import io.prestosql.spi.block.SortOrder; @@ -25,6 +24,7 @@ import io.prestosql.spi.sql.expression.QualifiedName; import io.prestosql.spi.sql.expression.Selection; import io.prestosql.spi.sql.expression.Time; import io.prestosql.spi.sql.expression.Types; +import io.prestosql.sql.ExpressionFormatter; import java.text.DecimalFormat; import java.text.DecimalFormatSymbols; @@ -34,11 +34,9 @@ import java.util.List; import java.util.Locale; import java.util.Map; import java.util.Optional; -import java.util.PrimitiveIterator; import java.util.StringJoiner; import static com.google.common.base.Preconditions.checkArgument; -import static java.lang.String.format; import static java.util.Objects.requireNonNull; import static java.util.stream.Collectors.joining; @@ -568,35 +566,7 @@ public class BaseSqlQueryWriter @SuppressWarnings("Duplicates") public String formatStringLiteral(String literal) { - literal = literal.replace("'", "''"); - if (CharMatcher.inRange((char) 0x20, (char) 0x7E).matchesAllOf(literal)) { - return "'" + literal + "'"; - } - - StringBuilder builder = new StringBuilder(); - builder.append("U&'"); - PrimitiveIterator.OfInt iterator = literal.codePoints().iterator(); - while (iterator.hasNext()) { - int codePoint = iterator.nextInt(); - checkArgument(codePoint >= 0, "Invalid UTF-8 encoding in characters: %s", literal); - if (isAsciiPrintable(codePoint)) { - char ch = (char) codePoint; - if (ch == '\\') { - builder.append(ch); - } - builder.append(ch); - } - else if (codePoint <= 0xFFFF) { - builder.append('\\'); - builder.append(format("%04X", codePoint)); - } - else { - builder.append("\\+"); - builder.append(format("%06X", codePoint)); - } - } - builder.append("'"); - return builder.toString(); + return ExpressionFormatter.formatStringLiteral(literal); } @Override diff --git a/presto-main/src/main/java/io/prestosql/datacenter/SingleHTTPSubscriber.java b/presto-main/src/main/java/io/prestosql/datacenter/SingleHTTPSubscriber.java index f5de037af..f8ec58923 100644 --- a/presto-main/src/main/java/io/prestosql/datacenter/SingleHTTPSubscriber.java +++ b/presto-main/src/main/java/io/prestosql/datacenter/SingleHTTPSubscriber.java @@ -19,22 +19,8 @@ import io.prestosql.server.protocol.PageSubscriber; import io.prestosql.server.protocol.Query; import javax.ws.rs.container.AsyncResponse; -import javax.ws.rs.core.Response; -import java.io.UnsupportedEncodingException; -import java.net.URLEncoder; -import java.util.Map; - -import static io.prestosql.client.PrestoHeaders.PRESTO_ADDED_PREPARE; -import static io.prestosql.client.PrestoHeaders.PRESTO_CLEAR_SESSION; -import static io.prestosql.client.PrestoHeaders.PRESTO_CLEAR_TRANSACTION_ID; -import static io.prestosql.client.PrestoHeaders.PRESTO_DEALLOCATED_PREPARE; -import static io.prestosql.client.PrestoHeaders.PRESTO_SET_CATALOG; -import static io.prestosql.client.PrestoHeaders.PRESTO_SET_PATH; -import static io.prestosql.client.PrestoHeaders.PRESTO_SET_ROLE; -import static io.prestosql.client.PrestoHeaders.PRESTO_SET_SCHEMA; -import static io.prestosql.client.PrestoHeaders.PRESTO_SET_SESSION; -import static io.prestosql.client.PrestoHeaders.PRESTO_STARTED_TRANSACTION_ID; +import static io.prestosql.server.protocol.ExecutingStatementResource.toResponse; import static java.util.Objects.requireNonNull; public class SingleHTTPSubscriber @@ -73,60 +59,4 @@ public class SingleHTTPSubscriber { this.asyncResponse.resume(toResponse(query, results)); } - - private static Response toResponse(Query query, DataCenterQueryResults queryResults) - { - Response.ResponseBuilder response = Response.ok(queryResults); - - if (query != null) { - query.getSetCatalog().ifPresent(catalog -> response.header(PRESTO_SET_CATALOG, catalog)); - query.getSetSchema().ifPresent(schema -> response.header(PRESTO_SET_SCHEMA, schema)); - query.getSetPath().ifPresent(path -> response.header(PRESTO_SET_PATH, path)); - - // add set session properties - query.getSetSessionProperties() - .forEach((key, value) -> response.header(PRESTO_SET_SESSION, key + '=' + urlEncode(value))); - - // add clear session properties - query.getResetSessionProperties() - .forEach(name -> response.header(PRESTO_CLEAR_SESSION, name)); - - // add set roles - query.getSetRoles() - .forEach((key, value) -> response.header(PRESTO_SET_ROLE, key + '=' + urlEncode(value.toString()))); - - // add added prepare statements - for (Map.Entry entry : query.getAddedPreparedStatements().entrySet()) { - String encodedKey = urlEncode(entry.getKey()); - String encodedValue = urlEncode(entry.getValue()); - response.header(PRESTO_ADDED_PREPARE, encodedKey + '=' + encodedValue); - } - - // add deallocated prepare statements - for (String name : query.getDeallocatedPreparedStatements()) { - response.header(PRESTO_DEALLOCATED_PREPARE, urlEncode(name)); - } - - // add new transaction ID - query.getStartedTransactionId() - .ifPresent(transactionId -> response.header(PRESTO_STARTED_TRANSACTION_ID, transactionId)); - - // add clear transaction ID directive - if (query.isClearTransactionId()) { - response.header(PRESTO_CLEAR_TRANSACTION_ID, true); - } - } - - return response.build(); - } - - private static String urlEncode(String value) - { - try { - return URLEncoder.encode(value, "UTF-8"); - } - catch (UnsupportedEncodingException e) { - throw new AssertionError(e); - } - } } diff --git a/presto-main/src/main/java/io/prestosql/query/HetuLogicalPlanner.java b/presto-main/src/main/java/io/prestosql/query/HetuLogicalPlanner.java index 2aa55dc04..3fb0882a9 100644 --- a/presto-main/src/main/java/io/prestosql/query/HetuLogicalPlanner.java +++ b/presto-main/src/main/java/io/prestosql/query/HetuLogicalPlanner.java @@ -1,4 +1,5 @@ /* + * Copyright (C) 2018-2020. Huawei Technologies Co., Ltd. All rights reserved. * 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 diff --git a/presto-main/src/main/java/io/prestosql/server/protocol/ExecutingStatementResource.java b/presto-main/src/main/java/io/prestosql/server/protocol/ExecutingStatementResource.java index 4f22fb7bb..3e525d95d 100644 --- a/presto-main/src/main/java/io/prestosql/server/protocol/ExecutingStatementResource.java +++ b/presto-main/src/main/java/io/prestosql/server/protocol/ExecutingStatementResource.java @@ -22,6 +22,7 @@ import io.airlift.units.DataSize; import io.airlift.units.Duration; import io.prestosql.Session; import io.prestosql.client.QueryResults; +import io.prestosql.client.QueryStatusInfo; import io.prestosql.execution.QueryManager; import io.prestosql.memory.context.SimpleLocalMemoryContext; import io.prestosql.operator.ExchangeClient; @@ -223,45 +224,47 @@ public class ExecutingStatementResource bindAsyncResponse(asyncResponse, response, responseExecutor); } - private static Response toResponse(Query query, QueryResults queryResults) + public static Response toResponse(Query query, QueryStatusInfo queryResults) { ResponseBuilder response = Response.ok(queryResults); - query.getSetCatalog().ifPresent(catalog -> response.header(PRESTO_SET_CATALOG, catalog)); - query.getSetSchema().ifPresent(schema -> response.header(PRESTO_SET_SCHEMA, schema)); - query.getSetPath().ifPresent(path -> response.header(PRESTO_SET_PATH, path)); + if (query != null) { + query.getSetCatalog().ifPresent(catalog -> response.header(PRESTO_SET_CATALOG, catalog)); + query.getSetSchema().ifPresent(schema -> response.header(PRESTO_SET_SCHEMA, schema)); + query.getSetPath().ifPresent(path -> response.header(PRESTO_SET_PATH, path)); - // add set session properties - query.getSetSessionProperties() - .forEach((key, value) -> response.header(PRESTO_SET_SESSION, key + '=' + urlEncode(value))); + // add set session properties + query.getSetSessionProperties() + .forEach((key, value) -> response.header(PRESTO_SET_SESSION, key + '=' + urlEncode(value))); - // add clear session properties - query.getResetSessionProperties() - .forEach(name -> response.header(PRESTO_CLEAR_SESSION, name)); + // add clear session properties + query.getResetSessionProperties() + .forEach(name -> response.header(PRESTO_CLEAR_SESSION, name)); - // add set roles - query.getSetRoles() - .forEach((key, value) -> response.header(PRESTO_SET_ROLE, key + '=' + urlEncode(value.toString()))); + // add set roles + query.getSetRoles() + .forEach((key, value) -> response.header(PRESTO_SET_ROLE, key + '=' + urlEncode(value.toString()))); - // add added prepare statements - for (Entry entry : query.getAddedPreparedStatements().entrySet()) { - String encodedKey = urlEncode(entry.getKey()); - String encodedValue = urlEncode(entry.getValue()); - response.header(PRESTO_ADDED_PREPARE, encodedKey + '=' + encodedValue); - } + // add added prepare statements + for (Entry entry : query.getAddedPreparedStatements().entrySet()) { + String encodedKey = urlEncode(entry.getKey()); + String encodedValue = urlEncode(entry.getValue()); + response.header(PRESTO_ADDED_PREPARE, encodedKey + '=' + encodedValue); + } - // add deallocated prepare statements - for (String name : query.getDeallocatedPreparedStatements()) { - response.header(PRESTO_DEALLOCATED_PREPARE, urlEncode(name)); - } + // add deallocated prepare statements + for (String name : query.getDeallocatedPreparedStatements()) { + response.header(PRESTO_DEALLOCATED_PREPARE, urlEncode(name)); + } - // add new transaction ID - query.getStartedTransactionId() - .ifPresent(transactionId -> response.header(PRESTO_STARTED_TRANSACTION_ID, transactionId)); + // add new transaction ID + query.getStartedTransactionId() + .ifPresent(transactionId -> response.header(PRESTO_STARTED_TRANSACTION_ID, transactionId)); - // add clear transaction ID directive - if (query.isClearTransactionId()) { - response.header(PRESTO_CLEAR_TRANSACTION_ID, true); + // add clear transaction ID directive + if (query.isClearTransactionId()) { + response.header(PRESTO_CLEAR_TRANSACTION_ID, true); + } } return response.build(); diff --git a/presto-parser/src/main/java/io/prestosql/sql/ExpressionFormatter.java b/presto-parser/src/main/java/io/prestosql/sql/ExpressionFormatter.java index fc48879ae..2436e5c1a 100644 --- a/presto-parser/src/main/java/io/prestosql/sql/ExpressionFormatter.java +++ b/presto-parser/src/main/java/io/prestosql/sql/ExpressionFormatter.java @@ -701,7 +701,7 @@ public final class ExpressionFormatter } } - static String formatStringLiteral(String s) + public static String formatStringLiteral(String s) { s = s.replace("'", "''"); if (CharMatcher.inRange((char) 0x20, (char) 0x7E).matchesAllOf(s)) { diff --git a/presto-parser/src/main/java/io/prestosql/sql/tree/DropCache.java b/presto-parser/src/main/java/io/prestosql/sql/tree/DropCache.java index 0069f6623..3315a4714 100644 --- a/presto-parser/src/main/java/io/prestosql/sql/tree/DropCache.java +++ b/presto-parser/src/main/java/io/prestosql/sql/tree/DropCache.java @@ -1,5 +1,4 @@ /* - * Copyright (C) 2018-2020. Huawei Technologies Co., Ltd. All rights reserved. * 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 diff --git a/presto-spi/src/main/java/io/prestosql/spi/SuppressFBWarnings.java b/presto-spi/src/main/java/io/prestosql/spi/SuppressFBWarnings.java index fea94c4a5..b8ee3b32d 100644 --- a/presto-spi/src/main/java/io/prestosql/spi/SuppressFBWarnings.java +++ b/presto-spi/src/main/java/io/prestosql/spi/SuppressFBWarnings.java @@ -20,14 +20,5 @@ import java.lang.annotation.RetentionPolicy; @Retention(RetentionPolicy.CLASS) public @interface SuppressFBWarnings { - /** - * The set of FindBugs warnings that are to be suppressed in - * annotated element. The value can be a bug category, kind or pattern. - */ String[] value() default {}; - - /** - * Optional documentation of the reason why the warning is suppressed - */ - String justification() default ""; } diff --git a/presto-spi/src/main/java/io/prestosql/spi/statestore/listener/MapListener.java b/presto-spi/src/main/java/io/prestosql/spi/statestore/listener/MapListener.java index 177d074cf..0bbd7f6ba 100644 --- a/presto-spi/src/main/java/io/prestosql/spi/statestore/listener/MapListener.java +++ b/presto-spi/src/main/java/io/prestosql/spi/statestore/listener/MapListener.java @@ -13,19 +13,6 @@ * limitations under the License. */ -/* - * 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.spi.statestore.listener; /**