Skip to content

Commit 74c82db

Browse files
authored
[Enhancement] Add ArrayInit check in Checkstyle (StarRocks#10399)
1 parent d01c1c6 commit 74c82db

6 files changed

Lines changed: 28 additions & 29 deletions

File tree

fe/checkstyle.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ https://github.com/checkstyle/checkstyle/blob/master/src/main/resources/google_c
111111
<property name="allowEmptyLoops" value="true"/>
112112
<property name="ignoreEnhancedForColon" value="false"/>
113113
<property name="tokens"
114-
value="ASSIGN, BAND, BAND_ASSIGN, BOR, BOR_ASSIGN, BSR, BSR_ASSIGN, BXOR,
114+
value="ASSIGN, ARRAY_INIT, BAND, BAND_ASSIGN, BOR, BOR_ASSIGN, BSR, BSR_ASSIGN, BXOR,
115115
BXOR_ASSIGN, COLON, DIV, DIV_ASSIGN, DO_WHILE, EQUAL, GE, GT, LAMBDA, LAND,
116116
LCURLY, LE, LITERAL_CATCH, LITERAL_DO, LITERAL_ELSE, LITERAL_FINALLY,
117117
LITERAL_FOR, LITERAL_IF, LITERAL_RETURN, LITERAL_SWITCH, LITERAL_SYNCHRONIZED,

fe/fe-core/src/main/java/com/starrocks/external/hive/Utils.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ public static String getTypeKeyword(String type) {
158158
public static int[] getPrecisionAndScale(String typeStr) throws DdlException {
159159
Matcher matcher = Pattern.compile(DECIMAL_PATTERN).matcher(typeStr.toLowerCase(Locale.ROOT));
160160
if (matcher.find()) {
161-
return new int[]{Integer.parseInt(matcher.group(1)), Integer.parseInt(matcher.group(2))};
161+
return new int[] {Integer.parseInt(matcher.group(1)), Integer.parseInt(matcher.group(2))};
162162
}
163163
throw new DdlException("Failed to get precision and scale at " + typeStr);
164164
}

fe/fe-core/src/main/java/com/starrocks/sql/analyzer/DecimalV3FunctionAnalyzer.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ public static Function getFunctionOfRound(FunctionCallExpr node, Function fn, Li
170170
returnScale = originalScale;
171171
returnType = ScalarType.createType(returnPrimitiveType, -1, returnPrecision, returnScale);
172172
} else {
173-
return Expr.getBuiltinFunction(fn.getFunctionName().getFunction(), new Type[]{Type.DOUBLE, Type.INT},
173+
return Expr.getBuiltinFunction(fn.getFunctionName().getFunction(), new Type[] {Type.DOUBLE, Type.INT},
174174
Function.CompareMode.IS_NONSTRICT_SUPERTYPE_OF);
175175
}
176176

@@ -231,7 +231,7 @@ public static AggregateFunction rectifyAggregationFunction(AggregateFunction fn,
231231
// without decimal type rectification.
232232
public static Function convertSumToMultiDistinctSum(Function sumFn, Type argType) {
233233
AggregateFunction fn = (AggregateFunction) Expr.getBuiltinFunction(FunctionSet.MULTI_DISTINCT_SUM,
234-
new Type[]{argType},
234+
new Type[] {argType},
235235
IS_NONSTRICT_SUPERTYPE_OF);
236236
Preconditions.checkArgument(fn != null);
237237
// Only rectify decimal typed functions.

fe/fe-core/src/test/java/com/starrocks/catalog/TypeTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ public void testGetMysqlResultSetMetaData() {
139139

140140
@Test
141141
public void testCanonicalName() {
142-
Object[][] testCases = new Object[][]{
142+
Object[][] testCases = new Object[][] {
143143
{ScalarType.createDecimalV3NarrowestType(9, 2), "DECIMAL(9,2)"},
144144
{ScalarType.createDecimalV3NarrowestType(18, 4), "DECIMAL(18,4)"},
145145
{ScalarType.createDecimalV3NarrowestType(38, 6), "DECIMAL(38,6)"},

fe/fe-core/src/test/java/com/starrocks/proc/FrontendsProcNodeTest.java

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
// This file is licensed under the Elastic License 2.0. Copyright 2021-present, StarRocks Inc.
22
package com.starrocks.proc;
33

4-
54
import com.starrocks.common.proc.FrontendsProcNode;
65
import com.starrocks.ha.FrontendNodeType;
76
import com.starrocks.system.Frontend;
@@ -52,18 +51,18 @@ private void mockAddress() {
5251
}
5352

5453
@Test
55-
public void testIsJoin() throws ClassNotFoundException,
56-
NoSuchMethodException,
57-
SecurityException,
58-
IllegalAccessException,
59-
IllegalArgumentException,
54+
public void testIsJoin() throws ClassNotFoundException,
55+
NoSuchMethodException,
56+
SecurityException,
57+
IllegalAccessException,
58+
IllegalArgumentException,
6059
InvocationTargetException {
6160
mockAddress();
6261
List<InetSocketAddress> list = new ArrayList<InetSocketAddress>();
6362
list.add(socketAddr1);
64-
63+
6564
Class<?> clazz = Class.forName(FrontendsProcNode.class.getName());
66-
Method isJoin = clazz.getDeclaredMethod("isJoin", new Class[]{List.class, Frontend.class});
65+
Method isJoin = clazz.getDeclaredMethod("isJoin", List.class, Frontend.class);
6766
isJoin.setAccessible(true);
6867

6968
Frontend feCouldFoundByIP = new Frontend(FrontendNodeType.LEADER, "test", "127.0.0.1", 1000);
@@ -83,7 +82,7 @@ public void testIsJoin() throws ClassNotFoundException,
8382
Assert.assertTrue(!result4);
8483
}
8584

86-
@Test
85+
@Test
8786
public void testIPTitle() {
8887
Assert.assertTrue(FrontendsProcNode.TITLE_NAMES.get(1).equals("IP"));
8988
}

fe/fe-core/src/test/java/com/starrocks/service/FrontendOptionsTest.java

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -92,39 +92,39 @@ public void initAddrUseIp(List<InetAddress> hosts) {
9292
}
9393

9494
@Test
95-
public void enableFQDNTest() throws UnknownHostException,
96-
NoSuchFieldException,
97-
SecurityException,
98-
IllegalArgumentException,
95+
public void enableFQDNTest() throws UnknownHostException,
96+
NoSuchFieldException,
97+
SecurityException,
98+
IllegalArgumentException,
9999
IllegalAccessException {
100100
mockNet();
101101
Field field = FrontendOptions.class.getDeclaredField("localAddr");
102102
field.setAccessible(true);
103103
field.set(null, addr);
104104
Field field1 = FrontendOptions.class.getDeclaredField("useFqdn");
105105
field1.setAccessible(true);
106-
106+
107107
field1.set(null, true);
108108
Assert.assertTrue(FrontendOptions.getLocalHostAddress().equals("sandbox"));
109109
field1.set(null, false);
110110
Assert.assertTrue(FrontendOptions.getLocalHostAddress().equals("127.0.0.10"));
111111
}
112112

113-
@Test
113+
@Test
114114
public void testChooseHostType() throws UnknownHostException {
115115
mockNet();
116116
useFqdn = true;
117-
FrontendOptions.init(new String[]{"-host_type", "ip"});
117+
FrontendOptions.init(new String[] {"-host_type", "ip"});
118118
Assert.assertTrue(!useFqdn);
119119
useFqdn = false;
120-
FrontendOptions.init(new String[]{"-host_type", "fqdn"});
120+
FrontendOptions.init(new String[] {"-host_type", "fqdn"});
121121
Assert.assertTrue(useFqdn);
122122
useFqdn = false;
123-
FrontendOptions.init(new String[]{});
123+
FrontendOptions.init(new String[] {});
124124
Assert.assertTrue(useFqdn);
125125
}
126126

127-
127+
128128
private void mkdir(boolean hasFqdn, String metaPath) {
129129
File dir = new File(metaPath);
130130
if (!dir.exists()) {
@@ -146,7 +146,7 @@ private void mkdir(boolean hasFqdn, String metaPath) {
146146
fw.write(line4);
147147
fw.write(line1);
148148
if (hasFqdn) {
149-
fw.write(line2);
149+
fw.write(line2);
150150
}
151151
fw.flush();
152152
fw.close();
@@ -156,7 +156,7 @@ private void mkdir(boolean hasFqdn, String metaPath) {
156156
}
157157

158158
private void deleteDir(File dir) {
159-
159+
160160
if (!dir.exists()) {
161161
return;
162162
}
@@ -178,14 +178,14 @@ public void testChooseHostTypeByFile() throws UnknownHostException {
178178
// fqdn
179179
mkdir(true, metaPath);
180180
useFqdnFile = false;
181-
FrontendOptions.init(new String[]{});
181+
FrontendOptions.init(new String[] {});
182182
Assert.assertTrue(useFqdnFile);
183183
File dir = new File(metaPath);
184184
deleteDir(dir);
185185
// ip
186186
mkdir(false, metaPath);
187187
useFqdnFile = true;
188-
FrontendOptions.init(new String[]{});
188+
FrontendOptions.init(new String[] {});
189189
Assert.assertTrue(!useFqdnFile);
190190
dir = new File(metaPath);
191191
deleteDir(dir);
@@ -290,7 +290,7 @@ public void testSaveStartType() throws FileNotFoundException, IOException {
290290
FrontendOptions.saveStartType();
291291
String roleFilePath = Config.meta_dir + "/image/ROLE";
292292
File roleFile = new File(roleFilePath);
293-
293+
294294
Properties prop = new Properties();
295295
String hostType;
296296
try (FileInputStream in = new FileInputStream(roleFile)) {

0 commit comments

Comments
 (0)