You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@kylin.apache.org by sh...@apache.org on 2018/10/15 01:27:43 UTC
[kylin] branch master updated: KYLIN-3597 improve code smell
This is an automated email from the ASF dual-hosted git repository.
shaofengshi pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/kylin.git
The following commit(s) were added to refs/heads/master by this push:
new 5f6007f KYLIN-3597 improve code smell
5f6007f is described below
commit 5f6007ff2b5aead4781c876fa3203dd67188d90b
Author: shaofengshi <sh...@apache.org>
AuthorDate: Mon Oct 15 09:24:07 2018 +0800
KYLIN-3597 improve code smell
---
.../main/java/org/apache/kylin/jdbc/Driver.java | 2 +-
.../java/org/apache/kylin/source/jdbc/SqlUtil.java | 7 +++---
.../hbase/lookup/LookupTableToHFileJob.java | 5 ++--
.../hbase/util/GridTableHBaseBenchmark.java | 29 +++++++++++-----------
4 files changed, 21 insertions(+), 22 deletions(-)
diff --git a/jdbc/src/main/java/org/apache/kylin/jdbc/Driver.java b/jdbc/src/main/java/org/apache/kylin/jdbc/Driver.java
index 5200b8c..0bd3e09 100644
--- a/jdbc/src/main/java/org/apache/kylin/jdbc/Driver.java
+++ b/jdbc/src/main/java/org/apache/kylin/jdbc/Driver.java
@@ -78,7 +78,7 @@ public class Driver extends UnregisteredDriver {
/**
* These calcite props can be configured by jdbc connection
*/
- public static final Set<String> CLIENT_CALCITE_PROP_NAMES = Sets.newHashSet(
+ protected static final Set<String> CLIENT_CALCITE_PROP_NAMES = Sets.newHashSet(
"caseSensitive",
"unquotedCasing",
"quoting",
diff --git a/source-hive/src/main/java/org/apache/kylin/source/jdbc/SqlUtil.java b/source-hive/src/main/java/org/apache/kylin/source/jdbc/SqlUtil.java
index b9cb391..239b898 100644
--- a/source-hive/src/main/java/org/apache/kylin/source/jdbc/SqlUtil.java
+++ b/source-hive/src/main/java/org/apache/kylin/source/jdbc/SqlUtil.java
@@ -32,6 +32,7 @@ import org.slf4j.LoggerFactory;
public class SqlUtil {
private static final Logger logger = LoggerFactory.getLogger(SqlUtil.class);
+ private static final Random r = new Random();
private SqlUtil() {
throw new IllegalStateException("Class CheckUtil is an utility class !");
@@ -61,7 +62,7 @@ public class SqlUtil {
}
}
- public static int tryTimes = 5;
+ public static final int tryTimes = 5;
public static Connection getConnection(DBConnConf dbconf) {
if (dbconf.getUrl() == null)
@@ -74,7 +75,6 @@ public class SqlUtil {
}
boolean got = false;
int times = 0;
- Random r = new Random();
while (!got && times < tryTimes) {
times++;
try {
@@ -86,11 +86,12 @@ public class SqlUtil {
int rt = r.nextInt(10);
Thread.sleep(rt * 1000);
} catch (InterruptedException e1) {
+ Thread.interrupted();
}
}
}
if (null == con) {
- throw new RuntimeException("Can not connect to the data source.");
+ throw new IllegalStateException("Can not connect to the data source.");
}
return con;
}
diff --git a/storage-hbase/src/main/java/org/apache/kylin/storage/hbase/lookup/LookupTableToHFileJob.java b/storage-hbase/src/main/java/org/apache/kylin/storage/hbase/lookup/LookupTableToHFileJob.java
index 0135a22..0b6e313 100644
--- a/storage-hbase/src/main/java/org/apache/kylin/storage/hbase/lookup/LookupTableToHFileJob.java
+++ b/storage-hbase/src/main/java/org/apache/kylin/storage/hbase/lookup/LookupTableToHFileJob.java
@@ -72,7 +72,7 @@ public class LookupTableToHFileJob extends AbstractHadoopJob {
protected static final Logger logger = LoggerFactory.getLogger(LookupTableToHFileJob.class);
private static String ALPHA_NUM = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
-
+ private static final Random ran = new Random();
private static int HBASE_TABLE_LENGTH = 10;
public int run(String[] args) throws Exception {
@@ -261,9 +261,8 @@ public class LookupTableToHFileJob extends AbstractHadoopJob {
+ IRealizationConstants.LookupHbaseStorageLocationPrefix + tableName + "_";
String namespace = kylinConfig.getHBaseStorageNameSpace();
String hTableName;
- Random ran = new Random();
do {
- StringBuffer sb = new StringBuffer();
+ StringBuilder sb = new StringBuilder();
if ((namespace.equals("default") || namespace.equals("")) == false) {
sb.append(namespace).append(":");
}
diff --git a/storage-hbase/src/main/java/org/apache/kylin/storage/hbase/util/GridTableHBaseBenchmark.java b/storage-hbase/src/main/java/org/apache/kylin/storage/hbase/util/GridTableHBaseBenchmark.java
index 20b67c1..6dd16fe 100644
--- a/storage-hbase/src/main/java/org/apache/kylin/storage/hbase/util/GridTableHBaseBenchmark.java
+++ b/storage-hbase/src/main/java/org/apache/kylin/storage/hbase/util/GridTableHBaseBenchmark.java
@@ -77,7 +77,7 @@ public class GridTableHBaseBenchmark {
}
public static void testGridTable(double hitRatio, double indexRatio) throws IOException {
- logger.info("Testing grid table scanning, hit ratio " + hitRatio + ", index ratio " + indexRatio);
+ logger.info("Testing grid table scanning, hit ratio {}, index ratio {}", hitRatio, indexRatio);
StorageURL hbaseUrl = StorageURL.valueOf("default@hbase"); // use hbase-site.xml on classpath
Connection conn = HBaseConnection.get(hbaseUrl);
@@ -87,8 +87,7 @@ public class GridTableHBaseBenchmark {
Hits hits = new Hits(N_ROWS, hitRatio, indexRatio);
for (int i = 0; i < ROUND; i++) {
- logger.info("==================================== ROUND " + (i + 1)
- + " ========================================");
+ logger.info("==================================== ROUND {} ========================================", (i + 1));
testRowScanWithIndex(conn, hits.getHitsForRowScanWithIndex());
testRowScanNoIndexFullScan(conn, hits.getHitsForRowScanNoIndex());
testRowScanNoIndexSkipScan(conn, hits.getHitsForRowScanNoIndex());
@@ -173,7 +172,8 @@ public class GridTableHBaseBenchmark {
int i = 0;
while (i < N_ROWS) {
- int start, end;
+ int start;
+ int end;
for (start = i; start < N_ROWS; start++) {
if (hits[start])
break;
@@ -225,25 +225,25 @@ public class GridTableHBaseBenchmark {
}
if (nRows > 0) {
- logger.info(nRows + " existing rows");
+ logger.info("{} existing rows", nRows);
if (nRows != N_ROWS)
throw new IOException("Expect " + N_ROWS + " rows but it is not");
return;
}
// insert rows into empty table
- logger.info("Writing " + N_ROWS + " rows to " + TEST_TABLE);
+ logger.info("Writing {} rows to {}", N_ROWS, TEST_TABLE);
long nBytes = 0;
for (int i = 0; i < N_ROWS; i++) {
byte[] rowkey = Bytes.toBytes(i);
Put put = new Put(rowkey);
byte[] cell = randomBytes();
- put.add(CF, QN, cell);
+ put.addColumn(CF, QN, cell);
table.put(put);
nBytes += cell.length;
dot(i, N_ROWS);
}
- logger.info("Written " + N_ROWS + " rows, " + nBytes + " bytes");
+ logger.info("Written {} rows, {} bytes", N_ROWS, nBytes);
} finally {
IOUtils.closeQuietly(table);
@@ -253,7 +253,7 @@ public class GridTableHBaseBenchmark {
private static void dot(int i, int nRows) {
if (i % (nRows / 100) == 0)
- System.out.print(".");
+ logger.info(".");
}
private static byte[] randomBytes() {
@@ -276,11 +276,11 @@ public class GridTableHBaseBenchmark {
}
if (tableExist) {
- logger.info("HTable '" + tableName + "' already exists");
+ logger.info("HTable '{}' already exists", tableName);
return;
}
- logger.info("Creating HTable '" + tableName + "'");
+ logger.info("Creating HTable '{}'", tableName);
HTableDescriptor desc = new HTableDescriptor(TableName.valueOf(tableName));
@@ -289,7 +289,7 @@ public class GridTableHBaseBenchmark {
desc.addFamily(fd);
hbase.createTable(desc);
- logger.info("HTable '" + tableName + "' created");
+ logger.info("HTable '{}' created", tableName);
} finally {
hbase.close();
}
@@ -383,14 +383,13 @@ public class GridTableHBaseBenchmark {
}
public void markStart() {
- logger.info(name + " starts");
+ logger.info("{} starts", name);
startTime = System.currentTimeMillis();
}
public void markEnd() {
endTime = System.currentTimeMillis();
- logger.info(name + " ends, " + (endTime - startTime) + " ms, " + rowsRead + " rows read, "
- + bytesRead + " bytes read");
+ logger.info("{} ends, {} ms, {} rows read, {} bytes read", name, (endTime - startTime), rowsRead, bytesRead);
}
}