Skip to content

Commit

Permalink
[improve][modules] code cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
wgzhao committed Oct 30, 2024
1 parent f1e637b commit a6050c7
Show file tree
Hide file tree
Showing 17 changed files with 48 additions and 46 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public String asString()
catch (Exception e) {
throw AddaxException.asAddaxException(
ErrorCode.CONVERT_NOT_SUPPORT,
String.format("Bytes[%s] cannot be converted to String .", this.toString()));
String.format("Bytes[%s] cannot be converted to String .", this));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public class Configuration
* 对于加密的keyPath,需要记录下来
* 为的是后面分布式情况下将该值加密后抛到 AddaxServer中
*/
private Set<String> secretKeyPathSet =
private final Set<String> secretKeyPathSet =
new HashSet<>();

private Object root;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,7 @@ public static BigDecimal sum(BigDecimal v1, BigDecimal... valList)
if (null == v1) {
v1 = BigDecimal.ZERO;
}
if (null == valList || valList.length == 0) {
if (null == valList) {
return v1;
}
for (BigDecimal val : valList) {
Expand Down Expand Up @@ -386,7 +386,7 @@ public static String avg(String... valList)
public static BigDecimal max(BigDecimal v1, BigDecimal... valList)
{
BigDecimal max = v1;
if (null == valList || valList.length == 0) {
if (null == valList) {
return max;
}
for (BigDecimal val : valList) {
Expand Down Expand Up @@ -422,7 +422,7 @@ public static BigDecimal maxArr(BigDecimal... valList)
public static BigDecimal min(BigDecimal v1, BigDecimal... valList)
{
BigDecimal min = v1;
if (null == valList || valList.length == 0) {
if (null == valList) {
return min;
}
for (BigDecimal val : valList) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -765,7 +765,7 @@ private void postJobRunStatistic(String url, int timeoutMills, String jsonStr)
LOG.info("The job results were uploaded successfully");
}
else {
LOG.warn("Uploading the job results failed: {}", httpResponse.toString());
LOG.warn("Uploading the job results failed: {}", httpResponse);
}
}
catch (IOException e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@

import java.math.BigDecimal;
import java.math.BigInteger;
import java.math.RoundingMode;
import java.net.InetAddress;
import java.nio.ByteBuffer;
import java.util.ArrayList;
Expand Down Expand Up @@ -468,7 +469,7 @@ public static List<Configuration> splitJob(int adviceNumber, Configuration jobCo
BigDecimal minToken = BigDecimal.valueOf(-1);
BigDecimal maxToken = new BigDecimal(new BigInteger("2").pow(127));
BigDecimal step = maxToken.subtract(minToken)
.divide(BigDecimal.valueOf(adviceNumber), 2, BigDecimal.ROUND_HALF_EVEN);
.divide(BigDecimal.valueOf(adviceNumber), 2, RoundingMode.HALF_EVEN);
for (int i = 0; i < adviceNumber; i++) {
BigInteger l = minToken.add(step.multiply(BigDecimal.valueOf(i))).toBigInteger();
BigInteger r = minToken.add(step.multiply(BigDecimal.valueOf(i + 1))).toBigInteger();
Expand All @@ -485,7 +486,7 @@ else if (partitioner.endsWith("Murmur3Partitioner")) {
BigDecimal minToken = BigDecimal.valueOf(Long.MIN_VALUE);
BigDecimal maxToken = BigDecimal.valueOf(Long.MAX_VALUE);
BigDecimal step = maxToken.subtract(minToken)
.divide(BigDecimal.valueOf(adviceNumber), 2, BigDecimal.ROUND_HALF_EVEN);
.divide(BigDecimal.valueOf(adviceNumber), 2, RoundingMode.HALF_EVEN);
for (int i = 0; i < adviceNumber; i++) {
long l = minToken.add(step.multiply(BigDecimal.valueOf(i))).longValue();
long r = minToken.add(step.multiply(BigDecimal.valueOf(i + 1))).longValue();
Expand Down Expand Up @@ -553,9 +554,9 @@ public static String getQueryString(Configuration taskConfig, Cluster cluster)
boolean allowFiltering = taskConfig.getBool(MyKey.ALLOW_FILTERING, false);

StringBuilder select = new StringBuilder();
select.append("SELECT ").append(columns.toString()).append(" FROM ").append(table);
select.append("SELECT ").append(columns).append(" FROM ").append(table);
if (where.length() > 0) {
select.append(" where ").append(where.toString());
select.append(" where ").append(where);
}
if (allowFiltering) {
select.append(" ALLOW FILTERING");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
import org.apache.commons.rng.simple.RandomSource;

import java.math.BigDecimal;
import java.math.RoundingMode;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
Expand Down Expand Up @@ -472,7 +473,7 @@ private Column buildOneColumn(Configuration eachColumnConfig, int columnIndex)
// specify fixed scale or not ?
if (scale > 0) {
BigDecimal b = BigDecimal.valueOf(rng.nextDouble(param1Int, param2Int + 1))
.setScale(scale, BigDecimal.ROUND_HALF_UP);
.setScale(scale, RoundingMode.HALF_UP);
return new DoubleColumn(b.doubleValue());
}
else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public class NormalTask
extends HbaseAbstractTask
{
private final List<HbaseColumnCell> hbaseColumnCells;
private List<Map> column;
private final List<Map> column;

public NormalTask(Configuration configuration)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ protected MultiVersionTask(Configuration configuration)
super(configuration);

this.maxVersion = configuration.getInt(HBaseKey.MAX_VERSION);
this.column = configuration.getList(HBaseKey.COLUMN, Map.class);
this.familyQualifierMap = Hbase20xHelper.parseColumnOfMultiversionMode(this.column);
column = configuration.getList(HBaseKey.COLUMN, Map.class);
this.familyQualifierMap = Hbase20xHelper.parseColumnOfMultiversionMode(column);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ public static class Task
private URIBuilder uriBuilder;
private String username;
private String password;
private BasicCredentialsProvider credsProvider = new BasicCredentialsProvider();
private final BasicCredentialsProvider credsProvider = new BasicCredentialsProvider();
private HttpHost proxy = null;
private Request request;
private String method;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
import org.slf4j.LoggerFactory;

import java.math.BigDecimal;
import java.math.RoundingMode;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
Expand Down Expand Up @@ -449,7 +450,7 @@ private Column buildOneColumn(Configuration eachColumnConfig, int columnIndex)
// specify fixed scale or not ?
if (scale > 0) {
BigDecimal b = BigDecimal.valueOf(rng.nextDouble(param1Int, param2Int + 1))
.setScale(scale, BigDecimal.ROUND_HALF_UP);
.setScale(scale, RoundingMode.HALF_UP);
return new DoubleColumn(b.doubleValue());
} else {
return new DoubleColumn(rng.nextDouble(param1Int, param2Int + 1));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ public void init()

Insert insertStmt = QueryBuilder.insertInto(table);
for (String colunmnName : columnMeta) {
if (colunmnName.toLowerCase().equals(CassandraKey.WRITE_TIME)) {
if (colunmnName.equalsIgnoreCase(CassandraKey.WRITE_TIME)) {
if (writeTimeCol != -1) {
throw AddaxException
.asAddaxException(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public class DorisKey

public enum StreamLoadFormat
{
CSV, JSON;
CSV, JSON
}

private static final String FLUSH_INTERVAL = "flushInterval";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,11 +124,11 @@ private String genMappings(String typeName)
String colName = jo.getString("name");
String colTypeStr = jo.getString("type");
if (colTypeStr == null) {
throw AddaxException.asAddaxException(CONFIG_ERROR, col.toString() + " column must have type");
throw AddaxException.asAddaxException(CONFIG_ERROR, col + " column must have type");
}
ESFieldType colType = ESFieldType.getESFieldType(colTypeStr);
if (colType == null) {
throw AddaxException.asAddaxException(NOT_SUPPORT_TYPE, col.toString() + " unsupported type");
throw AddaxException.asAddaxException(NOT_SUPPORT_TYPE, col + " unsupported type");
}

ESColumn columnItem = new ESColumn();
Expand Down Expand Up @@ -387,7 +387,7 @@ private long doBatchInsert(final List<Record> writerBuffer)
data.put(columnName, dateStr);
}
catch (Exception e) {
getTaskPluginCollector().collectDirtyRecord(record, String.format("时间类型解析失败 [%s:%s] exception: %s", columnName, column.toString(), e.toString()));
getTaskPluginCollector().collectDirtyRecord(record, String.format("时间类型解析失败 [%s:%s] exception: %s", columnName, column.toString(), e));
}
break;
case KEYWORD:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,8 +128,8 @@ private void validateParameter()
if (eachColumnConf.getString(Key.TYPE).toUpperCase().startsWith("DECIMAL")) {
String type = eachColumnConf.getString(Key.TYPE);
eachColumnConf.set(Key.TYPE, "decimal");
eachColumnConf.set(Key.PRECISION, (Object) getDecimalPrecision(type));
eachColumnConf.set(Key.SCALE, (Object) getDecimalScale(type));
eachColumnConf.set(Key.PRECISION, getDecimalPrecision(type));
eachColumnConf.set(Key.SCALE, getDecimalScale(type));
columns.set(i, eachColumnConf);
rewriteFlag = true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,27 +57,26 @@ public void doStreamLoad(StarRocksFlushTuple flushData)
if (null == host) {
throw new IOException("None of the host in `load_url` could be connected.");
}
String loadUrl = new StringBuilder(host)
.append("/api/")
.append(writerOptions.getDatabase())
.append("/")
.append(writerOptions.getTable())
.append("/_stream_load")
.toString();
String loadUrl = host +
"/api/" +
writerOptions.getDatabase() +
"/" +
writerOptions.getTable() +
"/_stream_load";
LOG.debug(String.format("Start to join batch data: rows[%d] bytes[%d] label[%s].", flushData.getRows().size(), flushData.getBytes(), flushData.getLabel()));
Map<String, Object> loadResult = doHttpPut(loadUrl, flushData.getLabel(), joinRows(flushData.getRows(), flushData.getBytes().intValue()));
final String keyStatus = "Status";
if (null == loadResult || !loadResult.containsKey(keyStatus)) {
throw new IOException("Unable to flush data to StarRocks: unknown result status.");
}
LOG.debug(new StringBuilder("StreamLoad response:\n").append(JSON.toJSONString(loadResult)).toString());
LOG.debug("StreamLoad response:\n" + JSON.toJSONString(loadResult));
if (RESULT_FAILED.equals(loadResult.get(keyStatus))) {
throw new IOException(
new StringBuilder("Failed to flush data to StarRocks.\n").append(JSON.toJSONString(loadResult)).toString()
"Failed to flush data to StarRocks.\n" + JSON.toJSONString(loadResult)
);
}
else if (RESULT_LABEL_EXISTED.equals(loadResult.get(keyStatus))) {
LOG.debug(new StringBuilder("StreamLoad response:\n").append(JSON.toJSONString(loadResult)).toString());
LOG.debug("StreamLoad response:\n" + JSON.toJSONString(loadResult));
// has to block-checking the state to get the final result
checkLabelState(host, flushData.getLabel());
}
Expand All @@ -88,7 +87,7 @@ private String getAvailableHost()
List<String> hostList = writerOptions.getLoadUrlList();
long tmp = pos + hostList.size();
for (; pos < tmp; pos++) {
String host = new StringBuilder("http://").append(hostList.get((int) (pos % hostList.size()))).toString();
String host = "http://" + hostList.get((int) (pos % hostList.size()));
if (tryHttpConnection(host)) {
return host;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,14 +51,14 @@ public class DefaultDataHandler
private static final String DEFAULT_USERNAME = "root";
private static final String DEFAULT_PASSWORD = "taosdata";
private static final boolean DEFAULT_IGNORE_TAGS_UNMATCHED = false;
private String username;
private String password;
private String jdbcUrl;
private int batchSize;
private boolean ignoreTagsUnmatched;

private List<String> tables;
private List<String> columns;
private final String username;
private final String password;
private final String jdbcUrl;
private final int batchSize;
private final boolean ignoreTagsUnmatched;

private final List<String> tables;
private final List<String> columns;

private Map<String, TableMeta> tableMetas;
private SchemaManager schemaManager;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,9 @@ public class OpentsdbDataHandler
private static final Logger LOG = LoggerFactory.getLogger(OpentsdbDataHandler.class);
private SchemalessWriter writer;

private String jdbcUrl;
private String user;
private String password;
private final String jdbcUrl;
private final String user;
private final String password;
int batchSize;

public OpentsdbDataHandler(Configuration config)
Expand All @@ -59,7 +59,7 @@ public OpentsdbDataHandler(Configuration config)
public int handle(RecordReceiver lineReceiver, TaskPluginCollector collector)
{
int count;
try (Connection conn = DriverManager.getConnection(jdbcUrl, user, password);) {
try (Connection conn = DriverManager.getConnection(jdbcUrl, user, password)) {
LOG.info("connection[ jdbcUrl: " + jdbcUrl + ", username: " + user + "] established.");
writer = new SchemalessWriter(conn);
count = write(lineReceiver, batchSize);
Expand Down

0 comments on commit a6050c7

Please sign in to comment.