Skip to content

Commit

Permalink
Issue 3597 fix sonar issues (apache#375)
Browse files Browse the repository at this point in the history
* KYLIN-3597 fix sonar issues
  • Loading branch information
whuwb authored and shaofengshi committed Dec 8, 2018
1 parent 2979f40 commit 39878ba
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,9 @@ public class MemcachedCache {
- 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;
Expand Down Expand Up @@ -264,11 +267,11 @@ protected byte[] internalGet(String hashedKey) {
} 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;
}

Expand Down Expand Up @@ -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);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,15 +40,16 @@ public class BackwardCompatibilityConfig {
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));
}
}

Expand Down Expand Up @@ -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");
}
}
20 changes: 10 additions & 10 deletions core-job/src/main/java/org/apache/kylin/job/JoinedFlatTable.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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";
}

Expand All @@ -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);
Expand All @@ -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();
Expand All @@ -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) {
Expand Down Expand Up @@ -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());
Expand Down Expand Up @@ -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, "`");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public class FlatTableSqlQuoteUtils {
* @param identifier
* @return
*/
public static String quote(String identifier){
public static String quoteIdentifier(String identifier){
return QUOTE + identifier + QUOTE;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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)),
Expand Down

0 comments on commit 39878ba

Please sign in to comment.