fix fossbot scan issues

This commit is contained in:
giteezhangjingfang 2020-07-13 17:14:00 +08:00
parent bf5b371fbc
commit da28e42453
10 changed files with 37 additions and 158 deletions

View File

@ -175,7 +175,6 @@
<dependency>
<groupId>io.hetu.core</groupId>
<artifactId>presto-parser</artifactId>
<scope>test</scope>
</dependency>
<dependency>

View File

@ -190,7 +190,6 @@
<dependency>
<groupId>io.hetu.core</groupId>
<artifactId>presto-parser</artifactId>
<scope>test</scope>
</dependency>
<dependency>

View File

@ -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

View File

@ -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<String, String> 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);
}
}
}

View File

@ -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

View File

@ -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<String, String> 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<String, String> 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();

View File

@ -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)) {

View File

@ -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

View File

@ -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 "";
}

View File

@ -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;
/**