Skip to content

Commit a3411b4

Browse files
committed
fix checkstyle
1 parent 20eee0b commit a3411b4

17 files changed

+253
-128
lines changed

fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/literal/DateLiteral.java

+15-7
Original file line numberDiff line numberDiff line change
@@ -44,17 +44,17 @@
4444
public class DateLiteral extends Literal {
4545
public static final String JAVA_DATE_FORMAT = "yyyy-MM-dd";
4646

47+
public static final Set<Character> punctuations = ImmutableSet.of('!', '@', '#', '$', '%', '^', '&', '*', '(', ')',
48+
'-', '+', '=', '_', '{', '}', '[', ']', '|', '\\', ':', ';', '"', '\'', '<', '>', ',', '.', '?', '/', '~',
49+
'`');
50+
4751
// for cast datetime type to date type.
4852
private static final LocalDateTime START_OF_A_DAY = LocalDateTime.of(0, 1, 1, 0, 0, 0);
4953
private static final LocalDateTime END_OF_A_DAY = LocalDateTime.of(9999, 12, 31, 23, 59, 59, 999999000);
5054
private static final DateLiteral MIN_DATE = new DateLiteral(0, 1, 1);
5155
private static final DateLiteral MAX_DATE = new DateLiteral(9999, 12, 31);
5256
private static final int[] DAYS_IN_MONTH = new int[] {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
5357

54-
public static final Set<Character> punctuations = ImmutableSet.of('!', '@', '#', '$', '%', '^', '&', '*', '(', ')',
55-
'-', '+', '=', '_', '{', '}', '[', ']', '|', '\\', ':', ';', '"', '\'', '<', '>', ',', '.', '?', '/', '~',
56-
'`');
57-
5858
protected long year;
5959
protected long month;
6060
protected long day;
@@ -209,7 +209,9 @@ static Result<String, AnalysisException> normalize(String s) {
209209
}
210210
} else {
211211
final String currentString = s;
212-
return Result.err(() -> new AnalysisException("date/datetime literal [" + currentString + "] is invalid"));
212+
return Result.err(
213+
() -> new AnalysisException("date/datetime literal [" + currentString + "] is invalid")
214+
);
213215
}
214216
i = j;
215217
partNumber += 1;
@@ -230,7 +232,9 @@ static Result<String, AnalysisException> normalize(String s) {
230232
sb.append(':');
231233
} else {
232234
final String currentString = s;
233-
return Result.err(() -> new AnalysisException("date/datetime literal [" + currentString + "] is invalid"));
235+
return Result.err(
236+
() -> new AnalysisException("date/datetime literal [" + currentString + "] is invalid")
237+
);
234238
}
235239
} else {
236240
break;
@@ -264,6 +268,7 @@ static Result<String, AnalysisException> normalize(String s) {
264268
return Result.ok(sb.toString());
265269
}
266270

271+
/** parseDateLiteral */
267272
public static Result<DateLiteral, AnalysisException> parseDateLiteral(String s) {
268273
Result<TemporalAccessor, AnalysisException> parseResult = parseDateTime(s);
269274
if (parseResult.isError()) {
@@ -280,6 +285,7 @@ public static Result<DateLiteral, AnalysisException> parseDateLiteral(String s)
280285
return Result.ok(new DateLiteral(year, month, day));
281286
}
282287

288+
/** parseDateTime */
283289
public static Result<TemporalAccessor, AnalysisException> parseDateTime(String s) {
284290
// fast parse '2022-01-01'
285291
if (s.length() == 10 && s.charAt(4) == '-' && s.charAt(7) == '-') {
@@ -336,7 +342,9 @@ public static Result<TemporalAccessor, AnalysisException> parseDateTime(String s
336342

337343
// if Year is not present, throw exception
338344
if (!dateTime.isSupported(ChronoField.YEAR)) {
339-
return Result.err(() -> new AnalysisException("date/datetime literal [" + originalString + "] is invalid"));
345+
return Result.err(
346+
() -> new AnalysisException("date/datetime literal [" + originalString + "] is invalid")
347+
);
340348
}
341349

342350
return Result.ok(dateTime);

fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/literal/DateTimeLiteral.java

+1
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,7 @@ public static int determineScale(String s) {
130130
return scale;
131131
}
132132

133+
/** parseDateTimeLiteral */
133134
public static Result<DateTimeLiteral, AnalysisException> parseDateTimeLiteral(String s, boolean isV2) {
134135
Result<TemporalAccessor, AnalysisException> parseResult = parseDateTime(s);
135136
if (parseResult.isError()) {

fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/literal/FloatLiteral.java

-38
Original file line numberDiff line numberDiff line change
@@ -48,42 +48,4 @@ public <R, C> R accept(ExpressionVisitor<R, C> visitor, C context) {
4848
public LiteralExpr toLegacyLiteral() {
4949
return new org.apache.doris.analysis.FloatLiteral(getDouble(), Type.FLOAT);
5050
}
51-
52-
public static boolean isValidFloat(String str) {
53-
if (str == null || str.isEmpty()) {
54-
return true;
55-
}
56-
57-
int index = 0;
58-
char c = str.charAt(index);
59-
if (c == '+' || c == '-') {
60-
index++;
61-
}
62-
63-
while (index < str.length()) {
64-
c = str.charAt(index++);
65-
if (c == 'E' || c == '.') {
66-
break;
67-
}
68-
if (!Character.isDigit(c)) {
69-
return false;
70-
}
71-
}
72-
73-
for (; index < str.length(); index++) {
74-
c = str.charAt(index);
75-
if (!('0' <= c && c <= '9')) {
76-
return false;
77-
}
78-
}
79-
return true;
80-
}
81-
82-
// private boolean parseIntegerParts(String str, int index) {
83-
// int index = 0;
84-
// char c = str.charAt(index);
85-
// if (c == '+' || c == '-') {
86-
// index++;
87-
// }
88-
// }
8951
}

fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/literal/IntegerLikeLiteral.java

-28
Original file line numberDiff line numberDiff line change
@@ -39,32 +39,4 @@ public long getLongValue() {
3939
}
4040

4141
public abstract Number getNumber();
42-
43-
public static boolean isValidInteger(String str) {
44-
if (str == null || str.isEmpty()) {
45-
return true;
46-
}
47-
48-
int index = 0;
49-
50-
char c = str.charAt(index);
51-
if (c == '+' || c == '-') {
52-
index++;
53-
}
54-
55-
for (; index < str.length(); index++) {
56-
c = str.charAt(index);
57-
if (!('0' <= c && c <= '9')) {
58-
return false;
59-
}
60-
}
61-
return true;
62-
}
63-
64-
public static void main(String[] args) {
65-
System.out.println(isValidInteger("01"));
66-
System.out.println(isValidInteger("+01"));
67-
System.out.println(isValidInteger("-01"));
68-
System.out.println(isValidInteger("- 01"));
69-
}
7042
}

fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/literal/format/AndChecker.java

+18
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,25 @@
1+
// Licensed to the Apache Software Foundation (ASF) under one
2+
// or more contributor license agreements. See the NOTICE file
3+
// distributed with this work for additional information
4+
// regarding copyright ownership. The ASF licenses this file
5+
// to you under the Apache License, Version 2.0 (the
6+
// "License"); you may not use this file except in compliance
7+
// with 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,
12+
// software distributed under the License is distributed on an
13+
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
// KIND, either express or implied. See the License for the
15+
// specific language governing permissions and limitations
16+
// under the License.
17+
118
package org.apache.doris.nereids.trees.expressions.literal.format;
219

320
import java.util.List;
421

22+
/** AndChecker */
523
public class AndChecker extends FormatChecker {
624
private final List<FormatChecker> checkers;
725

fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/literal/format/AtLeastChecker.java

+1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919

2020
import java.util.function.Predicate;
2121

22+
/** AtLeastChecker */
2223
public class AtLeastChecker extends FormatChecker {
2324
private int minCount;
2425
private int maxRead;

fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/literal/format/CharChecker.java

+18
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,23 @@
1+
// Licensed to the Apache Software Foundation (ASF) under one
2+
// or more contributor license agreements. See the NOTICE file
3+
// distributed with this work for additional information
4+
// regarding copyright ownership. The ASF licenses this file
5+
// to you under the Apache License, Version 2.0 (the
6+
// "License"); you may not use this file except in compliance
7+
// with 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,
12+
// software distributed under the License is distributed on an
13+
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
// KIND, either express or implied. See the License for the
15+
// specific language governing permissions and limitations
16+
// under the License.
17+
118
package org.apache.doris.nereids.trees.expressions.literal.format;
219

20+
/** CharChecker */
321
public class CharChecker extends FormatChecker {
422
public final char c;
523

fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/literal/format/CustomCharChecker.java

+18-1
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,25 @@
1-
package org.apache.doris.nereids.trees.expressions.literal.format;
1+
// Licensed to the Apache Software Foundation (ASF) under one
2+
// or more contributor license agreements. See the NOTICE file
3+
// distributed with this work for additional information
4+
// regarding copyright ownership. The ASF licenses this file
5+
// to you under the Apache License, Version 2.0 (the
6+
// "License"); you may not use this file except in compliance
7+
// with 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,
12+
// software distributed under the License is distributed on an
13+
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
// KIND, either express or implied. See the License for the
15+
// specific language governing permissions and limitations
16+
// under the License.
217

18+
package org.apache.doris.nereids.trees.expressions.literal.format;
319

420
import java.util.function.Predicate;
521

22+
/** CustomCharChecker */
623
public class CustomCharChecker extends FormatChecker {
724
private Predicate<Character> checker;
825

fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/literal/format/DateTimeChecker.java

+57-39
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,25 @@
1+
// Licensed to the Apache Software Foundation (ASF) under one
2+
// or more contributor license agreements. See the NOTICE file
3+
// distributed with this work for additional information
4+
// regarding copyright ownership. The ASF licenses this file
5+
// to you under the Apache License, Version 2.0 (the
6+
// "License"); you may not use this file except in compliance
7+
// with 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,
12+
// software distributed under the License is distributed on an
13+
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
// KIND, either express or implied. See the License for the
15+
// specific language governing permissions and limitations
16+
// under the License.
17+
118
package org.apache.doris.nereids.trees.expressions.literal.format;
219

320
import org.apache.doris.nereids.trees.expressions.literal.DateLiteral;
421

22+
/** DateTimeChecker */
523
public class DateTimeChecker extends FormatChecker {
624
private DateTimeChecker(StringInspect stringInspect) {
725
super(stringInspect);
@@ -15,47 +33,47 @@ public static boolean isValidDateTime(String str) {
1533
@Override
1634
protected boolean doCheck() {
1735
FormatChecker dateFormatChecker = and(
18-
or(
19-
// date
20-
and(
21-
or(
22-
// 20241012
23-
number(8, 8),
24-
// 2024-10-12
25-
and(
26-
number(4, 4), // year
27-
chars(DateLiteral.punctuations::contains),
28-
number(2, 2), // month
29-
chars(DateLiteral.punctuations::contains),
30-
number(2, 2) // day
31-
)
32-
),
33-
option(ch('Z'))
34-
),
35-
// datetime
36-
and(
37-
or(
38-
// 20241012010203
39-
number(14, 14),
40-
// 2024-01-01 01:02:03
41-
and(
42-
number(4, 4), // year
43-
chars(DateLiteral.punctuations::contains),
44-
number(2, 2), // month
45-
chars(DateLiteral.punctuations::contains),
46-
number(2, 2), // day
47-
atLeast(1, c -> c == 'T' || c == ' ' || DateLiteral.punctuations.contains(c)),
48-
number(2, 2), // hour
49-
chars(DateLiteral.punctuations::contains),
50-
number(2, 2), // minute
51-
chars(DateLiteral.punctuations::contains),
52-
number(2, 2) // second
53-
)
36+
or(
37+
// date
38+
and(
39+
or(
40+
// 20241012
41+
number(8, 8),
42+
// 2024-10-12
43+
and(
44+
number(4, 4), // year
45+
chars(DateLiteral.punctuations::contains),
46+
number(2, 2), // month
47+
chars(DateLiteral.punctuations::contains),
48+
number(2, 2) // day
49+
)
50+
),
51+
option(ch('Z'))
5452
),
55-
option(nanoSecond()),
56-
option(timeZone())
53+
// datetime
54+
and(
55+
or(
56+
// 20241012010203
57+
number(14, 14),
58+
// 2024-01-01 01:02:03
59+
and(
60+
number(4, 4), // year
61+
chars(DateLiteral.punctuations::contains),
62+
number(2, 2), // month
63+
chars(DateLiteral.punctuations::contains),
64+
number(2, 2), // day
65+
atLeast(1, c -> c == 'T' || c == ' ' || DateLiteral.punctuations.contains(c)),
66+
number(2, 2), // hour
67+
chars(DateLiteral.punctuations::contains),
68+
number(2, 2), // minute
69+
chars(DateLiteral.punctuations::contains),
70+
number(2, 2) // second
71+
)
72+
),
73+
option(nanoSecond()),
74+
option(timeZone())
75+
)
5776
)
58-
)
5977
);
6078
return dateFormatChecker.check();
6179
}

0 commit comments

Comments
 (0)