You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@kylin.apache.org by GitBox <gi...@apache.org> on 2018/12/08 09:31:18 UTC
[GitHub] shaofengshi closed pull request #375: Issue 3597 fix sonar issues
shaofengshi closed pull request #375: Issue 3597 fix sonar issues
URL: https://github.com/apache/kylin/pull/375
This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:
As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):
diff --git a/cache/src/main/java/org/apache/kylin/cache/memcached/MemcachedCache.java b/cache/src/main/java/org/apache/kylin/cache/memcached/MemcachedCache.java
index a2e69a725a..43bdc8d108 100644
--- a/cache/src/main/java/org/apache/kylin/cache/memcached/MemcachedCache.java
+++ b/cache/src/main/java/org/apache/kylin/cache/memcached/MemcachedCache.java
@@ -73,6 +73,9 @@
- 2; // length of separators
private static final Logger logger = LoggerFactory.getLogger(MemcachedCache.class);
private static final int DEFAULT_TTL = 7 * 24 * 3600;
+
+ private static final String UNABLE_TO_QUEUE_CACHE_OPERATION = "Unable to queue cache operation.";
+
protected final MemcachedCacheConfig config;
protected final MemcachedClientIF client;
protected final String memcachedPrefix;
@@ -264,11 +267,11 @@ protected void putBinary(String keyS, byte[] valueB, int expiration) {
} catch (IllegalStateException e) {
// operation did not get queued in time (queue is full)
errorCount.incrementAndGet();
- logger.error("Unable to queue cache operation.", e);
+ logger.error(UNABLE_TO_QUEUE_CACHE_OPERATION, e);
return null;
} catch (Throwable t) {
errorCount.incrementAndGet();
- logger.error("Unable to queue cache operation.", t);
+ logger.error(UNABLE_TO_QUEUE_CACHE_OPERATION, t);
return null;
}
@@ -304,10 +307,10 @@ private void internalPut(String hashedKey, byte[] encodedValue, int expiration)
} catch (IllegalStateException e) {
// operation did not get queued in time (queue is full)
errorCount.incrementAndGet();
- logger.error("Unable to queue cache operation.", e);
+ logger.error(UNABLE_TO_QUEUE_CACHE_OPERATION, e);
} catch (Throwable t) {
errorCount.incrementAndGet();
- logger.error("Unable to queue cache operation.", t);
+ logger.error(UNABLE_TO_QUEUE_CACHE_OPERATION, t);
}
}
diff --git a/core-common/src/main/java/org/apache/kylin/common/BackwardCompatibilityConfig.java b/core-common/src/main/java/org/apache/kylin/common/BackwardCompatibilityConfig.java
index cbe2e4c0c5..aeb7636059 100644
--- a/core-common/src/main/java/org/apache/kylin/common/BackwardCompatibilityConfig.java
+++ b/core-common/src/main/java/org/apache/kylin/common/BackwardCompatibilityConfig.java
@@ -40,15 +40,16 @@
private static final Logger logger = LoggerFactory.getLogger(BackwardCompatibilityConfig.class);
private static final String KYLIN_BACKWARD_COMPATIBILITY = "kylin-backward-compatibility";
+ private static final String PROPERTIES_SUFFIX = ".properties";
private final Map<String, String> old2new = Maps.newConcurrentMap();
private final Map<String, String> old2newPrefix = Maps.newConcurrentMap();
public BackwardCompatibilityConfig() {
ClassLoader loader = Thread.currentThread().getContextClassLoader();
- init(loader.getResourceAsStream(KYLIN_BACKWARD_COMPATIBILITY + ".properties"));
+ init(loader.getResourceAsStream(KYLIN_BACKWARD_COMPATIBILITY + PROPERTIES_SUFFIX));
for (int i = 0; i < 10; i++) {
- init(loader.getResourceAsStream(KYLIN_BACKWARD_COMPATIBILITY + (i) + ".properties"));
+ init(loader.getResourceAsStream(KYLIN_BACKWARD_COMPATIBILITY + (i) + PROPERTIES_SUFFIX));
}
}
@@ -213,6 +214,6 @@ else if (name.endsWith("-site.xml"))
return false;
else
return name.endsWith(".java") || name.endsWith(".js") || name.endsWith(".sh")
- || name.endsWith(".properties") || name.endsWith(".xml");
+ || name.endsWith(PROPERTIES_SUFFIX) || name.endsWith(".xml");
}
}
diff --git a/core-job/src/main/java/org/apache/kylin/job/JoinedFlatTable.java b/core-job/src/main/java/org/apache/kylin/job/JoinedFlatTable.java
index d7e3b72e28..ddd883d645 100644
--- a/core-job/src/main/java/org/apache/kylin/job/JoinedFlatTable.java
+++ b/core-job/src/main/java/org/apache/kylin/job/JoinedFlatTable.java
@@ -41,7 +41,7 @@
import org.apache.kylin.metadata.model.TableRef;
import org.apache.kylin.metadata.model.TblColRef;
-import static org.apache.kylin.job.util.FlatTableSqlQuoteUtils.quote;
+import static org.apache.kylin.job.util.FlatTableSqlQuoteUtils.quoteIdentifier;
import static org.apache.kylin.job.util.FlatTableSqlQuoteUtils.quoteIdentifierInSqlExpr;
import com.google.common.collect.Lists;
@@ -127,7 +127,7 @@ public static String generateInsertDataStatement(IJoinedFlatTableDesc flatDesc)
}
}
- return "INSERT OVERWRITE TABLE " + quote(flatDesc.getTableName()) + " " + generateSelectDataStatement(flatDesc)
+ return "INSERT OVERWRITE TABLE " + quoteIdentifier(flatDesc.getTableName()) + " " + generateSelectDataStatement(flatDesc)
+ ";\n";
}
@@ -150,13 +150,13 @@ public static String generateSelectDataStatement(IJoinedFlatTableDesc flatDesc,
}
String colTotalName = String.format(Locale.ROOT, "%s.%s", col.getTableRef().getTableName(), col.getName());
String quotedColTotalName = String.format(Locale.ROOT, "%s.%s",
- quote(col.getTableRef().getTableName()),
- quote(col.getName()));
+ quoteIdentifier(col.getTableRef().getTableName()),
+ quoteIdentifier(col.getName()));
if (skipAsList.contains(colTotalName)) {
sql.append(getQuotedColExpressionInSourceDB(flatDesc, col)).append(sep);
} else {
sql.append(getQuotedColExpressionInSourceDB(flatDesc, col)).append(" as ")
- .append(quote(colName(col))).append(sep);
+ .append(quoteIdentifier(colName(col))).append(sep);
}
}
appendJoinStatement(flatDesc, sql, singleLine);
@@ -171,7 +171,7 @@ static void appendJoinStatement(IJoinedFlatTableDesc flatDesc, StringBuilder sql
DataModelDesc model = flatDesc.getDataModel();
TableRef rootTable = model.getRootFactTable();
sql.append(" FROM ").append(flatDesc.getDataModel().getRootFactTable().getTableIdentityQuoted("`"))
- .append(" as ").append(quote(rootTable.getAlias())).append(sep);
+ .append(" as ").append(quoteIdentifier(rootTable.getAlias())).append(sep);
for (JoinTableDesc lookupDesc : model.getJoinTables()) {
JoinDesc join = lookupDesc.getJoin();
@@ -186,7 +186,7 @@ static void appendJoinStatement(IJoinedFlatTableDesc flatDesc, StringBuilder sql
String joinType = join.getType().toUpperCase(Locale.ROOT);
sql.append(joinType).append(" JOIN ").append(dimTable.getTableIdentityQuoted("`"))
- .append(" as ").append(quote(dimTable.getAlias())).append(sep);
+ .append(" as ").append(quoteIdentifier(dimTable.getAlias())).append(sep);
sql.append("ON ");
for (int i = 0; i < pk.length; i++) {
if (i > 0) {
@@ -277,7 +277,7 @@ private static String getHiveDataType(String javaDataType) {
public static String generateRedistributeFlatTableStatement(IJoinedFlatTableDesc flatDesc, CubeDesc cubeDesc) {
final String tableName = flatDesc.getTableName();
StringBuilder sql = new StringBuilder();
- sql.append("INSERT OVERWRITE TABLE " + quote(tableName) + " SELECT * FROM " + quote(tableName));
+ sql.append("INSERT OVERWRITE TABLE " + quoteIdentifier(tableName) + " SELECT * FROM " + quoteIdentifier(tableName));
if (flatDesc.getClusterBy() != null) {
appendClusterStatement(sql, flatDesc.getClusterBy());
@@ -305,8 +305,8 @@ public static String generateRedistributeFlatTableStatement(IJoinedFlatTableDesc
public static String getQuotedColExpressionInSourceDB(IJoinedFlatTableDesc flatDesc, TblColRef col) {
if (!col.getColumnDesc().isComputedColumn()) {
- return quote(col.getTableAlias()) + "."
- + quote(col.getName());
+ return quoteIdentifier(col.getTableAlias()) + "."
+ + quoteIdentifier(col.getName());
} else {
String computeExpr = col.getColumnDesc().getComputedColumnExpr();
return quoteIdentifierInSqlExpr(flatDesc, computeExpr, "`");
diff --git a/core-job/src/main/java/org/apache/kylin/job/util/FlatTableSqlQuoteUtils.java b/core-job/src/main/java/org/apache/kylin/job/util/FlatTableSqlQuoteUtils.java
index 4085d0a2ff..f2bb274813 100644
--- a/core-job/src/main/java/org/apache/kylin/job/util/FlatTableSqlQuoteUtils.java
+++ b/core-job/src/main/java/org/apache/kylin/job/util/FlatTableSqlQuoteUtils.java
@@ -42,7 +42,7 @@
* @param identifier
* @return
*/
- public static String quote(String identifier){
+ public static String quoteIdentifier(String identifier){
return QUOTE + identifier + QUOTE;
}
diff --git a/core-job/src/test/java/org/apache/kylin/job/util/FlatTableSqlQuoteUtilsTest.java b/core-job/src/test/java/org/apache/kylin/job/util/FlatTableSqlQuoteUtilsTest.java
index f40971c66b..1b5839f61d 100644
--- a/core-job/src/test/java/org/apache/kylin/job/util/FlatTableSqlQuoteUtilsTest.java
+++ b/core-job/src/test/java/org/apache/kylin/job/util/FlatTableSqlQuoteUtilsTest.java
@@ -129,4 +129,9 @@ public void testIsTableNameOrAliasNeedToQuote() {
Assert.assertFalse(FlatTableSqlQuoteUtils.isIdentifierNeedToQuote("KYLIN_SALES_PRICE * KYLIN_SALES_COUNT",
"kylin_sales", tablePatterns));
}
+
+ @Test
+ public void testQuoteWithIdentifier() {
+ Assert.assertEquals("`abc`", FlatTableSqlQuoteUtils.quoteIdentifier("abc"));
+ }
}
\ No newline at end of file
diff --git a/datasource-sdk/src/main/java/org/apache/kylin/sdk/datasource/framework/conv/ConvSqlWriter.java b/datasource-sdk/src/main/java/org/apache/kylin/sdk/datasource/framework/conv/ConvSqlWriter.java
index 3935e1324c..eb0630cb28 100644
--- a/datasource-sdk/src/main/java/org/apache/kylin/sdk/datasource/framework/conv/ConvSqlWriter.java
+++ b/datasource-sdk/src/main/java/org/apache/kylin/sdk/datasource/framework/conv/ConvSqlWriter.java
@@ -30,15 +30,11 @@
import org.apache.calcite.sql.SqlWriter;
import org.apache.calcite.sql.parser.SqlParserPos;
import org.apache.calcite.sql.pretty.SqlPrettyWriter;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
import java.sql.SQLException;
import java.util.Locale;
public class ConvSqlWriter extends SqlPrettyWriter {
- private static final Logger logger = LoggerFactory.getLogger(ConvSqlWriter.class);
-
private static final SqlOrderBy DUMMY_ORDER_BY_NODE = new SqlOrderBy(SqlParserPos.ZERO,
new DummySqlNode(SqlParserPos.ZERO),
new SqlNodeList(Lists.<SqlNode> newArrayList(SqlLiteral.createExactNumeric("1", SqlParserPos.ZERO)),
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
With regards,
Apache Git Services