Skip to content

Commit 7703be0

Browse files
authored
Add code style check and fix some bad code (apache#710)
1 parent 0487736 commit 7703be0

File tree

173 files changed

+1519
-1107
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

173 files changed

+1519
-1107
lines changed

codeStyle.xml

+122
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
1+
<!--
2+
~ Licensed to the Apache Software Foundation (ASF) under one or more
3+
~ contributor license agreements. See the NOTICE file distributed with
4+
~ this work for additional information regarding copyright ownership.
5+
~ The ASF licenses this file to You under the Apache License, Version 2.0
6+
~ (the "License"); you may not use this file except in compliance with
7+
~ the License. You may obtain a copy of the License at
8+
~
9+
~ http://www.apache.org/licenses/LICENSE-2.0
10+
~
11+
~ Unless required by applicable law or agreed to in writing, software
12+
~ distributed under the License is distributed on an "AS IS" BASIS,
13+
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
~ See the License for the specific language governing permissions and
15+
~ limitations under the License.
16+
~
17+
-->
18+
<code_scheme name="sea-tunnel" version="173">
19+
<option name="USE_SAME_INDENTS" value="true" />
20+
<option name="IGNORE_SAME_INDENTS_FOR_LANGUAGES" value="true" />
21+
<option name="OTHER_INDENT_OPTIONS">
22+
<value>
23+
<option name="CONTINUATION_INDENT_SIZE" value="4" />
24+
</value>
25+
</option>
26+
<JavaCodeStyleSettings>
27+
<option name="GENERATE_FINAL_LOCALS" value="true" />
28+
<option name="GENERATE_FINAL_PARAMETERS" value="true" />
29+
<option name="CLASS_NAMES_IN_JAVADOC" value="3" />
30+
<option name="CLASS_COUNT_TO_USE_IMPORT_ON_DEMAND" value="999" />
31+
<option name="NAMES_COUNT_TO_USE_IMPORT_ON_DEMAND" value="999" />
32+
<option name="INSERT_OVERRIDE_ANNOTATION" value="true" />
33+
<option name="PACKAGES_TO_USE_IMPORT_ON_DEMAND">
34+
<value />
35+
</option>
36+
<option name="IMPORT_LAYOUT_TABLE">
37+
<value>
38+
<package name="" withSubpackages="true" static="false" />
39+
<emptyLine />
40+
<package name="" withSubpackages="true" static="true" />
41+
</value>
42+
</option>
43+
<option name="JD_P_AT_EMPTY_LINES" value="false" />
44+
</JavaCodeStyleSettings>
45+
<XML>
46+
<option name="XML_LEGACY_SETTINGS_IMPORTED" value="true" />
47+
</XML>
48+
<ADDITIONAL_INDENT_OPTIONS fileType="haml">
49+
<option name="INDENT_SIZE" value="2" />
50+
</ADDITIONAL_INDENT_OPTIONS>
51+
<codeStyleSettings language="Groovy">
52+
<option name="KEEP_CONTROL_STATEMENT_IN_ONE_LINE" value="false" />
53+
<option name="KEEP_BLANK_LINES_IN_DECLARATIONS" value="1" />
54+
<option name="KEEP_BLANK_LINES_IN_CODE" value="1" />
55+
<option name="KEEP_BLANK_LINES_BEFORE_RBRACE" value="1" />
56+
<option name="ALIGN_MULTILINE_PARAMETERS" value="false" />
57+
<option name="ALIGN_MULTILINE_FOR" value="false" />
58+
<option name="SPACE_AFTER_TYPE_CAST" value="false" />
59+
<option name="METHOD_PARAMETERS_WRAP" value="1" />
60+
<option name="METHOD_ANNOTATION_WRAP" value="1" />
61+
<option name="CLASS_ANNOTATION_WRAP" value="1" />
62+
<option name="FIELD_ANNOTATION_WRAP" value="1" />
63+
<indentOptions>
64+
<option name="CONTINUATION_INDENT_SIZE" value="4" />
65+
</indentOptions>
66+
</codeStyleSettings>
67+
<codeStyleSettings language="HOCON">
68+
<option name="KEEP_BLANK_LINES_BEFORE_RBRACE" value="1" />
69+
<option name="PARENT_SETTINGS_INSTALLED" value="true" />
70+
</codeStyleSettings>
71+
<codeStyleSettings language="JAVA">
72+
<option name="KEEP_FIRST_COLUMN_COMMENT" value="false" />
73+
<option name="KEEP_CONTROL_STATEMENT_IN_ONE_LINE" value="false" />
74+
<option name="KEEP_BLANK_LINES_IN_DECLARATIONS" value="1" />
75+
<option name="KEEP_BLANK_LINES_IN_CODE" value="1" />
76+
<option name="KEEP_BLANK_LINES_BEFORE_RBRACE" value="1" />
77+
<option name="BLANK_LINES_BEFORE_PACKAGE" value="1" />
78+
<option name="WHILE_ON_NEW_LINE" value="true" />
79+
<option name="ALIGN_MULTILINE_CHAINED_METHODS" value="true" />
80+
<option name="ALIGN_MULTILINE_PARAMETERS_IN_CALLS" value="true" />
81+
<option name="ALIGN_MULTILINE_FOR" value="false" />
82+
<option name="ALIGN_MULTILINE_ARRAY_INITIALIZER_EXPRESSION" value="true" />
83+
<option name="SPACE_BEFORE_ARRAY_INITIALIZER_LBRACE" value="true" />
84+
<option name="CALL_PARAMETERS_WRAP" value="1" />
85+
<option name="CALL_PARAMETERS_LPAREN_ON_NEXT_LINE" value="true" />
86+
<option name="CALL_PARAMETERS_RPAREN_ON_NEXT_LINE" value="true" />
87+
<option name="METHOD_PARAMETERS_WRAP" value="5" />
88+
<option name="METHOD_CALL_CHAIN_WRAP" value="5" />
89+
<option name="ARRAY_INITIALIZER_WRAP" value="2" />
90+
<option name="ARRAY_INITIALIZER_LBRACE_ON_NEXT_LINE" value="true" />
91+
<option name="ARRAY_INITIALIZER_RBRACE_ON_NEXT_LINE" value="true" />
92+
<option name="WRAP_COMMENTS" value="true" />
93+
<indentOptions>
94+
<option name="CONTINUATION_INDENT_SIZE" value="4" />
95+
</indentOptions>
96+
</codeStyleSettings>
97+
<codeStyleSettings language="JSON">
98+
<option name="KEEP_BLANK_LINES_IN_CODE" value="1" />
99+
</codeStyleSettings>
100+
<codeStyleSettings language="Scala">
101+
<option name="KEEP_BLANK_LINES_IN_DECLARATIONS" value="1" />
102+
<option name="KEEP_BLANK_LINES_IN_CODE" value="1" />
103+
<option name="KEEP_BLANK_LINES_BEFORE_RBRACE" value="1" />
104+
<option name="WHILE_ON_NEW_LINE" value="true" />
105+
<option name="ALIGN_MULTILINE_PARAMETERS" value="false" />
106+
<option name="ALIGN_MULTILINE_FOR" value="false" />
107+
<option name="METHOD_PARAMETERS_WRAP" value="1" />
108+
<option name="METHOD_ANNOTATION_WRAP" value="1" />
109+
<option name="CLASS_ANNOTATION_WRAP" value="1" />
110+
<option name="FIELD_ANNOTATION_WRAP" value="1" />
111+
<indentOptions>
112+
<option name="INDENT_SIZE" value="4" />
113+
<option name="CONTINUATION_INDENT_SIZE" value="4" />
114+
<option name="TAB_SIZE" value="4" />
115+
</indentOptions>
116+
</codeStyleSettings>
117+
<codeStyleSettings language="XML">
118+
<indentOptions>
119+
<option name="CONTINUATION_INDENT_SIZE" value="4" />
120+
</indentOptions>
121+
</codeStyleSettings>
122+
</code_scheme>

plugin-flink-sink-console/src/main/java/io/github/interestinglab/waterdrop/flink/sink/ConsoleSink.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
* See the License for the specific language governing permissions and
1515
* limitations under the License.
1616
*/
17+
1718
package io.github.interestinglab.waterdrop.flink.sink;
1819

1920
import io.github.interestinglab.waterdrop.config.Config;
@@ -31,7 +32,7 @@
3132

3233
import java.io.IOException;
3334

34-
public class ConsoleSink extends RichOutputFormat<Row> implements FlinkBatchSink<Row, Row>, FlinkStreamSink<Row,Row> {
35+
public class ConsoleSink extends RichOutputFormat<Row> implements FlinkBatchSink<Row, Row>, FlinkStreamSink<Row, Row> {
3536

3637
private Config config;
3738

@@ -57,7 +58,7 @@ public Config getConfig() {
5758

5859
@Override
5960
public CheckResult checkConfig() {
60-
return new CheckResult(true,"");
61+
return new CheckResult(true, "");
6162
}
6263

6364
@Override
@@ -76,7 +77,6 @@ public void open(int taskNumber, int numTasks) throws IOException {
7677

7778
@Override
7879
public void writeRecord(Row record) throws IOException {
79-
System.out.println(record);
8080
}
8181

8282
@Override

plugin-flink-sink-elasticsearch/src/main/java/io/github/interestinglab/waterdrop/flink/sink/Elasticsearch.java

+1-3
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
* See the License for the specific language governing permissions and
1515
* limitations under the License.
1616
*/
17+
1718
package io.github.interestinglab.waterdrop.flink.sink;
1819

1920
import io.github.interestinglab.waterdrop.config.Config;
@@ -42,7 +43,6 @@
4243
import java.util.List;
4344
import java.util.Map;
4445

45-
4646
public class Elasticsearch implements FlinkStreamSink<Row, Row>, FlinkBatchSink<Row, Row> {
4747

4848
private Config config;
@@ -67,7 +67,6 @@ public CheckResult checkConfig() {
6767
}
6868
}
6969

70-
7170
@Override
7271
public void prepare(FlinkEnvironment env) {
7372
Config defaultConfig = ConfigFactory.parseMap(new HashMap<String, String>(2) {
@@ -115,7 +114,6 @@ public void process(Row element, RuntimeContext ctx, RequestIndexer indexer) {
115114
}
116115
);
117116

118-
119117
// configuration for the bulk requests; this instructs the sink to emit after every element, otherwise they would be buffered
120118
esSinkBuilder.setBulkFlushMaxActions(1);
121119

plugin-flink-sink-elasticsearch/src/main/java/io/github/interestinglab/waterdrop/flink/sink/ElasticsearchOutputFormat.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
* See the License for the specific language governing permissions and
1515
* limitations under the License.
1616
*/
17+
1718
package io.github.interestinglab.waterdrop.flink.sink;
1819

1920
import io.github.interestinglab.waterdrop.config.Config;
@@ -35,7 +36,6 @@
3536
import java.net.InetAddress;
3637
import java.util.List;
3738

38-
3939
public class ElasticsearchOutputFormat<T> extends RichOutputFormat<T> {
4040

4141
private Config config;

plugin-flink-sink-file/src/main/java/io/github/interestinglab/waterdrop/flink/sink/CsvRowOutputFormat.java

+1-2
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
* See the License for the specific language governing permissions and
1515
* limitations under the License.
1616
*/
17+
1718
package io.github.interestinglab.waterdrop.flink.sink;
1819

1920
import org.apache.flink.api.common.io.FileOutputFormat;
@@ -33,7 +34,6 @@ public class CsvRowOutputFormat extends FileOutputFormat<Row> {
3334

3435
public static final String DEFAULT_FIELD_DELIMITER = CsvInputFormat.DEFAULT_FIELD_DELIMITER;
3536

36-
3737
private transient Writer wrt;
3838

3939
private String fieldDelimiter;
@@ -131,7 +131,6 @@ public void setQuoteStrings(boolean quoteStrings) {
131131
this.quoteStrings = quoteStrings;
132132
}
133133

134-
135134
@Override
136135
public void open(int taskNumber, int numTasks) throws IOException {
137136
super.open(taskNumber, numTasks);

plugin-flink-sink-file/src/main/java/io/github/interestinglab/waterdrop/flink/sink/FileSink.java

+3-2
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
* See the License for the specific language governing permissions and
1515
* limitations under the License.
1616
*/
17+
1718
package io.github.interestinglab.waterdrop.flink.sink;
1819

1920
import io.github.interestinglab.waterdrop.config.Config;
@@ -85,7 +86,7 @@ public DataSink<Row> outputBatch(FlinkEnvironment env, DataSet<Row> dataSet) {
8586
break;
8687

8788
}
88-
if (config.hasPath(WRITE_MODE)){
89+
if (config.hasPath(WRITE_MODE)) {
8990
String mode = config.getString(WRITE_MODE);
9091
outputFormat.setWriteMode(FileSystem.WriteMode.valueOf(mode));
9192
}
@@ -104,7 +105,7 @@ public Config getConfig() {
104105

105106
@Override
106107
public CheckResult checkConfig() {
107-
return CheckConfigUtil.check(config,PATH,FORMAT);
108+
return CheckConfigUtil.check(config, PATH, FORMAT);
108109
}
109110

110111
@Override

plugin-flink-sink-file/src/main/java/io/github/interestinglab/waterdrop/flink/sink/JsonRowOutputFormat.java

+18-21
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
* See the License for the specific language governing permissions and
1515
* limitations under the License.
1616
*/
17+
1718
package io.github.interestinglab.waterdrop.flink.sink;
1819

1920
import com.alibaba.fastjson.JSONArray;
@@ -42,12 +43,11 @@ public class JsonRowOutputFormat extends FileOutputFormat<Row> {
4243

4344
private RowTypeInfo rowTypeInfo;
4445

45-
46-
public JsonRowOutputFormat(Path outputPath,RowTypeInfo rowTypeInfo) {
47-
this(outputPath, rowTypeInfo,"UTF-8");
46+
public JsonRowOutputFormat(Path outputPath, RowTypeInfo rowTypeInfo) {
47+
this(outputPath, rowTypeInfo, "UTF-8");
4848
}
4949

50-
public JsonRowOutputFormat(Path outputPath,RowTypeInfo rowTypeInfo, String charset) {
50+
public JsonRowOutputFormat(Path outputPath, RowTypeInfo rowTypeInfo, String charset) {
5151
super(outputPath);
5252
this.rowTypeInfo = rowTypeInfo;
5353
this.charsetName = charset;
@@ -69,18 +69,15 @@ public void setCharsetName(String charsetName) throws IllegalCharsetNameExceptio
6969
this.charsetName = charsetName;
7070
}
7171

72-
7372
@Override
7473
public void open(int taskNumber, int numTasks) throws IOException {
7574
super.open(taskNumber, numTasks);
7675

7776
try {
7877
this.charset = Charset.forName(charsetName);
79-
}
80-
catch (IllegalCharsetNameException e) {
78+
} catch (IllegalCharsetNameException e) {
8179
throw new IOException("The charset " + charsetName + " is not valid.", e);
82-
}
83-
catch (UnsupportedCharsetException e) {
80+
} catch (UnsupportedCharsetException e) {
8481
throw new IOException("The charset " + charsetName + " is not supported.", e);
8582
}
8683
}
@@ -93,34 +90,34 @@ public void writeRecord(Row record) throws IOException {
9390
this.stream.write(NEWLINE);
9491
}
9592

96-
private JSONObject getJson(Row record,RowTypeInfo rowTypeInfo){
93+
private JSONObject getJson(Row record, RowTypeInfo rowTypeInfo) {
9794
String[] fieldNames = rowTypeInfo.getFieldNames();
9895
int i = 0;
9996
JSONObject json = new JSONObject();
100-
for (String name : fieldNames){
97+
for (String name : fieldNames) {
10198
Object field = record.getField(i);
10299
final TypeInformation type = rowTypeInfo.getTypeAt(i);
103-
if (type.isBasicType()){
100+
if (type.isBasicType()) {
104101
json.put(name, field);
105-
}else if (type instanceof ObjectArrayTypeInfo){
102+
} else if (type instanceof ObjectArrayTypeInfo) {
106103
ObjectArrayTypeInfo arrayTypeInfo = (ObjectArrayTypeInfo) type;
107104
TypeInformation componentInfo = arrayTypeInfo.getComponentInfo();
108105
JSONArray jsonArray = new JSONArray();
109-
if (componentInfo instanceof RowTypeInfo){
106+
if (componentInfo instanceof RowTypeInfo) {
110107
final Row[] rows = (Row[]) field;
111-
for (Row r : rows){
112-
jsonArray.add(getJson(r,(RowTypeInfo)componentInfo));
108+
for (Row r : rows) {
109+
jsonArray.add(getJson(r, (RowTypeInfo) componentInfo));
113110
}
114-
}else {
111+
} else {
115112
final Object[] objects = (Object[]) field;
116-
for (Object o : objects){
113+
for (Object o : objects) {
117114
jsonArray.add(o);
118115
}
119116
}
120-
json.put(name,jsonArray);
121-
}else if (type instanceof RowTypeInfo){
117+
json.put(name, jsonArray);
118+
} else if (type instanceof RowTypeInfo) {
122119
RowTypeInfo typeInfo = (RowTypeInfo) type;
123-
json.put(name,getJson((Row)field,typeInfo));
120+
json.put(name, getJson((Row) field, typeInfo));
124121
}
125122
i++;
126123
}

0 commit comments

Comments
 (0)