Skip to content

Commit 126a295

Browse files
author
dapeng
committed
代码优化
1 parent 42db63e commit 126a295

File tree

10 files changed

+56
-43
lines changed

10 files changed

+56
-43
lines changed

core/src/main/java/com/dtstack/flink/sql/environment/StreamEnvConfigManager.java

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -258,6 +258,8 @@ private static Optional<StateBackend> createStateBackend(String backendType, Str
258258
checkpointDataUriEmptyCheck(checkpointDataUri, backendType);
259259
stateBackend = new RocksDBStateBackend(checkpointDataUri, BooleanUtils.toBoolean(backendIncremental));
260260
break;
261+
default:
262+
break;
261263
}
262264
return stateBackend == null ? Optional.empty() : Optional.of(stateBackend);
263265
}
@@ -317,14 +319,14 @@ private static void verityTtl(String ttlMintimeStr, String ttlMaxtimeStr) {
317319
* @return
318320
*/
319321
private static Long getTtlTime(Integer timeNumber, String timeUnit) {
320-
if (timeUnit.equalsIgnoreCase("d")) {
321-
return timeNumber * 1000l * 60 * 60 * 24;
322-
} else if (timeUnit.equalsIgnoreCase("h")) {
323-
return timeNumber * 1000l * 60 * 60;
324-
} else if (timeUnit.equalsIgnoreCase("m")) {
325-
return timeNumber * 1000l * 60;
326-
} else if (timeUnit.equalsIgnoreCase("s")) {
327-
return timeNumber * 1000l;
322+
if ("d".equalsIgnoreCase(timeUnit)) {
323+
return timeNumber * 1000L * 60 * 60 * 24;
324+
} else if ("h".equalsIgnoreCase(timeUnit)) {
325+
return timeNumber * 1000L * 60 * 60;
326+
} else if ("m".equalsIgnoreCase(timeUnit)) {
327+
return timeNumber * 1000L * 60;
328+
} else if ("s".equalsIgnoreCase(timeUnit)) {
329+
return timeNumber * 1000L;
328330
} else {
329331
throw new RuntimeException("not support " + timeNumber + timeUnit);
330332
}

core/src/main/java/com/dtstack/flink/sql/option/OptionParser.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ public List<String> getProgramExeArgList() throws Exception {
114114
}
115115

116116
public static void main(String[] args) throws Exception {
117-
OptionParser OptionParser = new OptionParser(args);
118-
System.out.println(OptionParser.getOptions());
117+
OptionParser optionParser = new OptionParser(args);
118+
System.out.println(optionParser.getOptions());
119119
}
120120
}

core/src/main/java/com/dtstack/flink/sql/parser/CreateFuncParser.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,18 +32,18 @@
3232

3333
public class CreateFuncParser implements IParser {
3434

35-
private static final String funcPatternStr = "(?i)\\s*create\\s+(scala|table|aggregate)\\s+function\\s+(\\S+)\\s+WITH\\s+(\\S+)";
35+
private static final String FUNC_PATTERN_STR = "(?i)\\s*create\\s+(scala|table|aggregate)\\s+function\\s+(\\S+)\\s+WITH\\s+(\\S+)";
3636

37-
private static final Pattern funcPattern = Pattern.compile(funcPatternStr);
37+
private static final Pattern FUNC_PATTERN = Pattern.compile(FUNC_PATTERN_STR);
3838

3939
@Override
4040
public boolean verify(String sql) {
41-
return funcPattern.matcher(sql).find();
41+
return FUNC_PATTERN.matcher(sql).find();
4242
}
4343

4444
@Override
4545
public void parseSql(String sql, SqlTree sqlTree) {
46-
Matcher matcher = funcPattern.matcher(sql);
46+
Matcher matcher = FUNC_PATTERN.matcher(sql);
4747
if(matcher.find()){
4848
String type = matcher.group(1);
4949
String funcName = matcher.group(2);

core/src/main/java/com/dtstack/flink/sql/side/SidePredicatesParser.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,8 @@ private void parseSql(SqlNode sqlNode, Map<String, SideTableInfo> sideTableMap,
101101
parseSql(unionLeft, sideTableMap, tabMapping);
102102
parseSql(unionRight, sideTableMap, tabMapping);
103103
break;
104+
default:
105+
break;
104106
}
105107
}
106108

core/src/main/java/com/dtstack/flink/sql/side/SideSQLParser.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,8 @@ private void checkAndReplaceMultiJoin(SqlNode sqlNode, Set<String> sideTableSet)
131131
checkAndReplaceMultiJoin(unionLeft, sideTableSet);
132132
checkAndReplaceMultiJoin(unionRight, sideTableSet);
133133
break;
134+
default:
135+
break;
134136
}
135137
}
136138

@@ -204,6 +206,8 @@ private Object parseSql(SqlNode sqlNode, Set<String> sideTableSet, Queue<Object>
204206
case ORDER_BY:
205207
SqlOrderBy sqlOrderBy = (SqlOrderBy) sqlNode;
206208
parseSql(sqlOrderBy.query, sideTableSet, queueInfo, parentWhere, parentSelectList);
209+
default:
210+
break;
207211
}
208212
return "";
209213
}

core/src/main/java/com/dtstack/flink/sql/side/SideSqlExec.java

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ public class SideSqlExec {
9090

9191
private String tmpFields = null;
9292

93-
private SideSQLParser sideSQLParser = new SideSQLParser();
93+
private SideSQLParser sideSqlParser = new SideSQLParser();
9494
private SidePredicatesParser sidePredicatesParser = new SidePredicatesParser();
9595

9696
private Map<String, Table> localTableCache = Maps.newHashMap();
@@ -109,8 +109,8 @@ public void exec(String sql, Map<String, SideTableInfo> sideTableMap, StreamTabl
109109
LOG.error("fill predicates for sideTable fail ", e);
110110
}
111111

112-
sideSQLParser.setLocalTableCache(localTableCache);
113-
Queue<Object> exeQueue = sideSQLParser.getExeQueue(sql, sideTableMap.keySet());
112+
sideSqlParser.setLocalTableCache(localTableCache);
113+
Queue<Object> exeQueue = sideSqlParser.getExeQueue(sql, sideTableMap.keySet());
114114
Object pollObj = null;
115115

116116
//need clean
@@ -140,7 +140,7 @@ public void exec(String sql, Map<String, SideTableInfo> sideTableMap, StreamTabl
140140
LOG.info("exec sql: " + pollSqlNode.toString());
141141
}
142142
}else if(pollSqlNode.getKind() == AS){
143-
AliasInfo aliasInfo = parseASNode(pollSqlNode);
143+
AliasInfo aliasInfo = parseAsNode(pollSqlNode);
144144
Table table = tableEnv.sqlQuery(aliasInfo.getName());
145145
tableEnv.registerTable(aliasInfo.getAlias(), table);
146146
localTableCache.put(aliasInfo.getAlias(), table);
@@ -151,9 +151,9 @@ public void exec(String sql, Map<String, SideTableInfo> sideTableMap, StreamTabl
151151
}
152152
} else if (pollSqlNode.getKind() == WITH_ITEM) {
153153
SqlWithItem sqlWithItem = (SqlWithItem) pollSqlNode;
154-
String TableAlias = sqlWithItem.name.toString();
154+
String tableAlias = sqlWithItem.name.toString();
155155
Table table = tableEnv.sqlQuery(sqlWithItem.query.toString());
156-
tableEnv.registerTable(TableAlias, table);
156+
tableEnv.registerTable(tableAlias, table);
157157
}
158158

159159
}else if (pollObj instanceof JoinInfo){
@@ -253,11 +253,13 @@ private void addAliasForFieldNode(SqlNode pollSqlNode, List<String> fieldList, H
253253
}
254254
}
255255
break;
256+
default:
257+
break;
256258
}
257259
}
258260

259261

260-
public AliasInfo parseASNode(SqlNode sqlNode) throws SqlParseException {
262+
public AliasInfo parseAsNode(SqlNode sqlNode) throws SqlParseException {
261263
SqlKind sqlKind = sqlNode.getKind();
262264
if(sqlKind != AS){
263265
throw new RuntimeException(sqlNode + " is not 'as' operator");
@@ -487,6 +489,8 @@ public SqlNode filterNodeWithTargetName(SqlNode sqlNode, String targetTableName)
487489
}else{
488490
return null;
489491
}
492+
default:
493+
break;
490494
}
491495

492496
return null;
@@ -709,7 +713,7 @@ public void registerTmpTable(CreateTmpTableParser.SqlParserResult result,
709713
}
710714

711715
localTableCache.putAll(tableCache);
712-
Queue<Object> exeQueue = sideSQLParser.getExeQueue(result.getExecSql(), sideTableMap.keySet());
716+
Queue<Object> exeQueue = sideSqlParser.getExeQueue(result.getExecSql(), sideTableMap.keySet());
713717
Object pollObj = null;
714718

715719
//need clean
@@ -759,7 +763,7 @@ public void registerTmpTable(CreateTmpTableParser.SqlParserResult result,
759763
}
760764

761765
protected void dealAsSourceTable(StreamTableEnvironment tableEnv, SqlNode pollSqlNode) throws SqlParseException {
762-
AliasInfo aliasInfo = parseASNode(pollSqlNode);
766+
AliasInfo aliasInfo = parseAsNode(pollSqlNode);
763767
if (localTableCache.containsKey(aliasInfo.getName())) {
764768
return;
765769
}

core/src/main/java/com/dtstack/flink/sql/table/AbsSideTableParser.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ protected void parseCacheProp(SideTableInfo sideTableInfo, Map<String, Object> p
8787
if(props.containsKey(SideTableInfo.CACHE_MODE_KEY.toLowerCase())){
8888
String cachemode = MathUtil.getString(props.get(SideTableInfo.CACHE_MODE_KEY.toLowerCase()));
8989

90-
if(!cachemode.equalsIgnoreCase("ordered") && !cachemode.equalsIgnoreCase("unordered")){
90+
if(!"ordered".equalsIgnoreCase(cachemode) && !"unordered".equalsIgnoreCase(cachemode)){
9191
throw new RuntimeException("cachemode must ordered or unordered!");
9292
}
9393
sideTableInfo.setCacheMode(cachemode.toLowerCase());

core/src/main/java/com/dtstack/flink/sql/util/ClassUtil.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,8 @@ public static Class<?> stringConvertClass(String str) {
8686
case "decimal":
8787
case "decimalunsigned":
8888
return BigDecimal.class;
89-
89+
default:
90+
break;
9091
}
9192

9293
throw new RuntimeException("不支持 " + str + " 类型");

core/src/main/java/com/dtstack/flink/sql/util/DateUtil.java

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -116,9 +116,9 @@ public static long getTodayStart(long day) {
116116
* @return
117117
*/
118118
public static long getTodayStart(long day,String scope) {
119-
if(scope.equals("MS")){
119+
if("MS".equals(scope)){
120120
return getTodayStart(day)*1000;
121-
}else if(scope.equals("S")){
121+
}else if("S".equals(scope)){
122122
return getTodayStart(day);
123123
}else{
124124
return getTodayStart(day);
@@ -154,9 +154,9 @@ public static long getNextDayStart(long day) {
154154
* @return
155155
*/
156156
public static long getNextDayStart(long day,String scope) {
157-
if(scope.equals("MS")){
157+
if("MS".equals(scope)){
158158
return getNextDayStart(day)*1000;
159-
}else if(scope.equals("S")){
159+
}else if("S".equals(scope)){
160160
return getNextDayStart(day);
161161
}else{
162162
return getNextDayStart(day);
@@ -335,7 +335,7 @@ public static String get30DaysLaterByString(String day, String inFormat, String
335335
* @return String
336336
* @throws ParseException
337337
*/
338-
public static String getDateStrTOFormat(String day, String inFormat, String outFormat) throws ParseException {
338+
public static String getDateStrToFormat(String day, String inFormat, String outFormat) throws ParseException {
339339
SimpleDateFormat sdf = new SimpleDateFormat(inFormat);
340340
Date date = sdf.parse(day);
341341
Calendar calendar = Calendar.getInstance();
@@ -344,7 +344,7 @@ public static String getDateStrTOFormat(String day, String inFormat, String outF
344344
return dayBefore;
345345
}
346346

347-
public static long getDateMillTOFormat(String day, String inFormat) throws ParseException {
347+
public static long getDateMillToFormat(String day, String inFormat) throws ParseException {
348348
SimpleDateFormat sdf = new SimpleDateFormat(inFormat);
349349
Date date = sdf.parse(day);
350350
Calendar calendar = Calendar.getInstance();
@@ -470,11 +470,11 @@ public static long getMillByDay(int severalDays,String condition) {
470470
if(condition==null){
471471
return getMillToDay(cal,dateT);
472472
}
473-
if(condition.equals("-")){
473+
if("-".equals(condition)){
474474
dateT = (cal.get(Calendar.DATE) - severalDays);
475475
return getMillToDay(cal,dateT);
476476
}
477-
if(condition.equals("+")){
477+
if("+".equals(condition)){
478478
dateT = (cal.get(Calendar.DATE) + severalDays);
479479
return getMillToDay(cal,dateT);
480480
}
@@ -490,11 +490,11 @@ public static long getStampByDay(int severalDays,String condition) {
490490
if(condition==null){
491491
return getStampToDay(cal,dateT);
492492
}
493-
if(condition.equals("-")){
493+
if("-".equals(condition)){
494494
dateT = (cal.get(Calendar.DATE) - severalDays);
495495
return getStampToDay(cal,dateT);
496496
}
497-
if(condition.equals("+")){
497+
if("+".equals(condition)){
498498
dateT = (cal.get(Calendar.DATE) + severalDays);
499499
return getStampToDay(cal,dateT);
500500
}
@@ -575,8 +575,8 @@ public static String getDate(Date date, String format) {
575575
*/
576576
public static long stringToLong(String day, String format) throws ParseException {
577577
SimpleDateFormat dateFormat = new SimpleDateFormat(format);
578-
long Date = dateFormat.parse(day).getTime();
579-
return Date;
578+
long date = dateFormat.parse(day).getTime();
579+
return date;
580580
}
581581

582582
/**
@@ -588,8 +588,8 @@ public static long stringToLong(String day, String format) throws ParseException
588588
public static Date stringToDate(String day, String format) {
589589
try {
590590
SimpleDateFormat dateFormat = new SimpleDateFormat(format);
591-
Date Date = dateFormat.parse(day);
592-
return Date;
591+
Date date = dateFormat.parse(day);
592+
return date;
593593
} catch (ParseException e) {
594594
return new Date();
595595
}
@@ -608,8 +608,8 @@ public static String longToString(long day, String format) throws ParseException
608608
day=day*1000;
609609
}
610610
SimpleDateFormat dateFormat = new SimpleDateFormat(format);
611-
String Date = dateFormat.format(day);
612-
return Date;
611+
String date = dateFormat.format(day);
612+
return date;
613613
}
614614

615615
/**

core/src/main/java/com/dtstack/flink/sql/util/JDBCUtils.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,10 @@ public class JDBCUtils {
2828

2929
private static final Logger LOG = LoggerFactory.getLogger(ClassUtil.class);
3030

31-
public final static String lock_str = "jdbc_lock_str";
31+
public final static String LOCK_STR = "jdbc_lock_str";
3232

3333
public static void forName(String clazz, ClassLoader classLoader) {
34-
synchronized (lock_str){
34+
synchronized (LOCK_STR){
3535
try {
3636
Class.forName(clazz, true, classLoader);
3737
DriverManager.setLoginTimeout(10);

0 commit comments

Comments
 (0)