Skip to content

Commit d2de909

Browse files
[Spotless] Adds new line at end of java files (opensearch-project#1896)
* Adding spotless plugin to project build.gradle. Signed-off-by: Mitchell Gale <[email protected]> Remove commented out spotless changes. Signed-off-by: Mitchell Gale <[email protected]> Adding Spotless to DEVELOPER_GUIDE.rst Signed-off-by: Mitchell Gale <[email protected]> Added Google Java format to spotless. Signed-off-by: Mitchell Gale <[email protected]> Update DEVELOPER_GUIDE.rst Co-authored-by: Yury-Fridlyand <[email protected]> * Added apply false for spotless Signed-off-by: Mitchell Gale <[email protected]> * Adding ratchetFrom to build.gradle Signed-off-by: Mitchell Gale <[email protected]> * Adding license header to build.gradle for spotless. Signed-off-by: Mitchell Gale <[email protected]> * Uncommenting all changes to build.gradle for spotless. Signed-off-by: Mitchell Gale <[email protected]> * Commented out spotless checks. Signed-off-by: Mitchell Gale <[email protected]> * Add specific version for java format spotless (1.17.0) Signed-off-by: Mitchell Gale <[email protected]> * Add spotless end with new line check. Signed-off-by: Mitchell Gale <[email protected]> * Add new line at end of files missing lines. Signed-off-by: Mitchell Gale <[email protected]> * Removed include path Signed-off-by: Mitchell Gale <[email protected]> * Correcting ending new line for QueryExemplars. Signed-off-by: Mitchell Gale <[email protected]> --------- Signed-off-by: Mitchell Gale <[email protected]> Signed-off-by: Mitchell Gale <[email protected]> Co-authored-by: Yury-Fridlyand <[email protected]>
1 parent d00dc4d commit d2de909

File tree

57 files changed

+286
-302
lines changed

Some content is hidden

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

57 files changed

+286
-302
lines changed

build.gradle

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -83,18 +83,18 @@ repositories {
8383
// Spotless checks will be added as PRs are applied to resolve each style issue is approved.
8484
spotless {
8585
java {
86-
// target fileTree('.') {
87-
// include '**/*.java', 'src/*/java/**/*.java'
88-
// exclude '**/build/**', '**/build-*/**'
89-
// }
86+
target fileTree('.') {
87+
include '**/*.java'
88+
exclude '**/build/**', '**/build-*/**'
89+
}
9090
// importOrder()
9191
// licenseHeader("/*\n" +
9292
// " * Copyright OpenSearch Contributors\n" +
9393
// " * SPDX-License-Identifier: Apache-2.0\n" +
94-
// " */\n\n\n")
94+
// " */\n\n")
9595
// removeUnusedImports()
9696
// trimTrailingWhitespace()
97-
// endWithNewline()
97+
endWithNewline()
9898
// googleJavaFormat('1.17.0').reflowLongStrings().groupArtifact('com.google.googlejavaformat:google-java-format')
9999
}
100100
}
Lines changed: 168 additions & 168 deletions
Original file line numberDiff line numberDiff line change
@@ -1,168 +1,168 @@
1-
/*
2-
* Copyright OpenSearch Contributors
3-
* SPDX-License-Identifier: Apache-2.0
4-
*/
5-
6-
package org.opensearch.sql.common.grok;
7-
8-
import java.time.Instant;
9-
import java.time.LocalDate;
10-
import java.time.LocalDateTime;
11-
import java.time.OffsetDateTime;
12-
import java.time.ZoneId;
13-
import java.time.ZoneOffset;
14-
import java.time.ZonedDateTime;
15-
import java.time.format.DateTimeFormatter;
16-
import java.time.temporal.TemporalAccessor;
17-
import java.util.AbstractMap;
18-
import java.util.Arrays;
19-
import java.util.Collection;
20-
import java.util.List;
21-
import java.util.Map;
22-
import java.util.function.Function;
23-
import java.util.regex.Pattern;
24-
import java.util.stream.Collectors;
25-
26-
/**
27-
* Convert String argument to the right type.
28-
*/
29-
public class Converter {
30-
31-
public enum Type {
32-
BYTE(Byte::valueOf),
33-
BOOLEAN(Boolean::valueOf),
34-
SHORT(Short::valueOf),
35-
INT(Integer::valueOf, "integer"),
36-
LONG(Long::valueOf),
37-
FLOAT(Float::valueOf),
38-
DOUBLE(Double::valueOf),
39-
DATETIME(new DateConverter(), "date"),
40-
STRING(v -> v, "text");
41-
42-
public final IConverter<? extends Object> converter;
43-
public final List<String> aliases;
44-
45-
Type(IConverter<? extends Object> converter, String... aliases) {
46-
this.converter = converter;
47-
this.aliases = Arrays.asList(aliases);
48-
}
49-
}
50-
51-
private static final Pattern SPLITTER = Pattern.compile("[:;]");
52-
53-
private static final Map<String, Type> TYPES =
54-
Arrays.stream(Type.values())
55-
.collect(Collectors.toMap(t -> t.name().toLowerCase(), t -> t));
56-
57-
private static final Map<String, Type> TYPE_ALIASES =
58-
Arrays.stream(Type.values())
59-
.flatMap(type -> type.aliases.stream()
60-
.map(alias -> new AbstractMap.SimpleEntry<>(alias, type)))
61-
.collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue));
62-
63-
private static Type getType(String key) {
64-
key = key.toLowerCase();
65-
Type type = TYPES.getOrDefault(key, TYPE_ALIASES.get(key));
66-
if (type == null) {
67-
throw new IllegalArgumentException("Invalid data type :" + key);
68-
}
69-
return type;
70-
}
71-
72-
/**
73-
* getConverters.
74-
*/
75-
public static Map<String, IConverter<? extends Object>>
76-
getConverters(Collection<String> groupNames, Object... params) {
77-
return groupNames.stream()
78-
.filter(Converter::containsDelimiter)
79-
.collect(Collectors.toMap(Function.identity(), key -> {
80-
String[] list = splitGrokPattern(key);
81-
IConverter<? extends Object> converter = getType(list[1]).converter;
82-
if (list.length == 3) {
83-
converter = converter.newConverter(list[2], params);
84-
}
85-
return converter;
86-
}));
87-
}
88-
89-
/**
90-
* getGroupTypes.
91-
*/
92-
public static Map<String, Type> getGroupTypes(Collection<String> groupNames) {
93-
return groupNames.stream()
94-
.filter(Converter::containsDelimiter)
95-
.map(Converter::splitGrokPattern)
96-
.collect(Collectors.toMap(
97-
l -> l[0],
98-
l -> getType(l[1])
99-
));
100-
}
101-
102-
public static String extractKey(String key) {
103-
return splitGrokPattern(key)[0];
104-
}
105-
106-
private static boolean containsDelimiter(String string) {
107-
return string.indexOf(':') >= 0 || string.indexOf(';') >= 0;
108-
}
109-
110-
private static String[] splitGrokPattern(String string) {
111-
return SPLITTER.split(string, 3);
112-
}
113-
114-
interface IConverter<T> {
115-
116-
T convert(String value);
117-
118-
default IConverter<T> newConverter(String param, Object... params) {
119-
return this;
120-
}
121-
}
122-
123-
124-
static class DateConverter implements IConverter<Instant> {
125-
126-
private final DateTimeFormatter formatter;
127-
private final ZoneId timeZone;
128-
129-
public DateConverter() {
130-
this.formatter = DateTimeFormatter.ISO_DATE_TIME;
131-
this.timeZone = ZoneOffset.UTC;
132-
}
133-
134-
private DateConverter(DateTimeFormatter formatter, ZoneId timeZone) {
135-
this.formatter = formatter;
136-
this.timeZone = timeZone;
137-
}
138-
139-
@Override
140-
public Instant convert(String value) {
141-
TemporalAccessor dt = formatter
142-
.parseBest(value.trim(), ZonedDateTime::from, LocalDateTime::from, OffsetDateTime::from,
143-
Instant::from,
144-
LocalDate::from);
145-
if (dt instanceof ZonedDateTime) {
146-
return ((ZonedDateTime) dt).toInstant();
147-
} else if (dt instanceof LocalDateTime) {
148-
return ((LocalDateTime) dt).atZone(timeZone).toInstant();
149-
} else if (dt instanceof OffsetDateTime) {
150-
return ((OffsetDateTime) dt).atZoneSameInstant(timeZone).toInstant();
151-
} else if (dt instanceof Instant) {
152-
return ((Instant) dt);
153-
} else if (dt instanceof LocalDate) {
154-
return ((LocalDate) dt).atStartOfDay(timeZone).toInstant();
155-
} else {
156-
return null;
157-
}
158-
}
159-
160-
@Override
161-
public DateConverter newConverter(String param, Object... params) {
162-
if (!(params.length == 1 && params[0] instanceof ZoneId)) {
163-
throw new IllegalArgumentException("Invalid parameters");
164-
}
165-
return new DateConverter(DateTimeFormatter.ofPattern(param), (ZoneId) params[0]);
166-
}
167-
}
168-
}
1+
/*
2+
* Copyright OpenSearch Contributors
3+
* SPDX-License-Identifier: Apache-2.0
4+
*/
5+
6+
package org.opensearch.sql.common.grok;
7+
8+
import java.time.Instant;
9+
import java.time.LocalDate;
10+
import java.time.LocalDateTime;
11+
import java.time.OffsetDateTime;
12+
import java.time.ZoneId;
13+
import java.time.ZoneOffset;
14+
import java.time.ZonedDateTime;
15+
import java.time.format.DateTimeFormatter;
16+
import java.time.temporal.TemporalAccessor;
17+
import java.util.AbstractMap;
18+
import java.util.Arrays;
19+
import java.util.Collection;
20+
import java.util.List;
21+
import java.util.Map;
22+
import java.util.function.Function;
23+
import java.util.regex.Pattern;
24+
import java.util.stream.Collectors;
25+
26+
/**
27+
* Convert String argument to the right type.
28+
*/
29+
public class Converter {
30+
31+
public enum Type {
32+
BYTE(Byte::valueOf),
33+
BOOLEAN(Boolean::valueOf),
34+
SHORT(Short::valueOf),
35+
INT(Integer::valueOf, "integer"),
36+
LONG(Long::valueOf),
37+
FLOAT(Float::valueOf),
38+
DOUBLE(Double::valueOf),
39+
DATETIME(new DateConverter(), "date"),
40+
STRING(v -> v, "text");
41+
42+
public final IConverter<? extends Object> converter;
43+
public final List<String> aliases;
44+
45+
Type(IConverter<? extends Object> converter, String... aliases) {
46+
this.converter = converter;
47+
this.aliases = Arrays.asList(aliases);
48+
}
49+
}
50+
51+
private static final Pattern SPLITTER = Pattern.compile("[:;]");
52+
53+
private static final Map<String, Type> TYPES =
54+
Arrays.stream(Type.values())
55+
.collect(Collectors.toMap(t -> t.name().toLowerCase(), t -> t));
56+
57+
private static final Map<String, Type> TYPE_ALIASES =
58+
Arrays.stream(Type.values())
59+
.flatMap(type -> type.aliases.stream()
60+
.map(alias -> new AbstractMap.SimpleEntry<>(alias, type)))
61+
.collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue));
62+
63+
private static Type getType(String key) {
64+
key = key.toLowerCase();
65+
Type type = TYPES.getOrDefault(key, TYPE_ALIASES.get(key));
66+
if (type == null) {
67+
throw new IllegalArgumentException("Invalid data type :" + key);
68+
}
69+
return type;
70+
}
71+
72+
/**
73+
* getConverters.
74+
*/
75+
public static Map<String, IConverter<? extends Object>>
76+
getConverters(Collection<String> groupNames, Object... params) {
77+
return groupNames.stream()
78+
.filter(Converter::containsDelimiter)
79+
.collect(Collectors.toMap(Function.identity(), key -> {
80+
String[] list = splitGrokPattern(key);
81+
IConverter<? extends Object> converter = getType(list[1]).converter;
82+
if (list.length == 3) {
83+
converter = converter.newConverter(list[2], params);
84+
}
85+
return converter;
86+
}));
87+
}
88+
89+
/**
90+
* getGroupTypes.
91+
*/
92+
public static Map<String, Type> getGroupTypes(Collection<String> groupNames) {
93+
return groupNames.stream()
94+
.filter(Converter::containsDelimiter)
95+
.map(Converter::splitGrokPattern)
96+
.collect(Collectors.toMap(
97+
l -> l[0],
98+
l -> getType(l[1])
99+
));
100+
}
101+
102+
public static String extractKey(String key) {
103+
return splitGrokPattern(key)[0];
104+
}
105+
106+
private static boolean containsDelimiter(String string) {
107+
return string.indexOf(':') >= 0 || string.indexOf(';') >= 0;
108+
}
109+
110+
private static String[] splitGrokPattern(String string) {
111+
return SPLITTER.split(string, 3);
112+
}
113+
114+
interface IConverter<T> {
115+
116+
T convert(String value);
117+
118+
default IConverter<T> newConverter(String param, Object... params) {
119+
return this;
120+
}
121+
}
122+
123+
124+
static class DateConverter implements IConverter<Instant> {
125+
126+
private final DateTimeFormatter formatter;
127+
private final ZoneId timeZone;
128+
129+
public DateConverter() {
130+
this.formatter = DateTimeFormatter.ISO_DATE_TIME;
131+
this.timeZone = ZoneOffset.UTC;
132+
}
133+
134+
private DateConverter(DateTimeFormatter formatter, ZoneId timeZone) {
135+
this.formatter = formatter;
136+
this.timeZone = timeZone;
137+
}
138+
139+
@Override
140+
public Instant convert(String value) {
141+
TemporalAccessor dt = formatter
142+
.parseBest(value.trim(), ZonedDateTime::from, LocalDateTime::from, OffsetDateTime::from,
143+
Instant::from,
144+
LocalDate::from);
145+
if (dt instanceof ZonedDateTime) {
146+
return ((ZonedDateTime) dt).toInstant();
147+
} else if (dt instanceof LocalDateTime) {
148+
return ((LocalDateTime) dt).atZone(timeZone).toInstant();
149+
} else if (dt instanceof OffsetDateTime) {
150+
return ((OffsetDateTime) dt).atZoneSameInstant(timeZone).toInstant();
151+
} else if (dt instanceof Instant) {
152+
return ((Instant) dt);
153+
} else if (dt instanceof LocalDate) {
154+
return ((LocalDate) dt).atStartOfDay(timeZone).toInstant();
155+
} else {
156+
return null;
157+
}
158+
}
159+
160+
@Override
161+
public DateConverter newConverter(String param, Object... params) {
162+
if (!(params.length == 1 && params[0] instanceof ZoneId)) {
163+
throw new IllegalArgumentException("Invalid parameters");
164+
}
165+
return new DateConverter(DateTimeFormatter.ofPattern(param), (ZoneId) params[0]);
166+
}
167+
}
168+
}

core/src/main/java/org/opensearch/sql/ast/tree/RareTopN.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,4 +57,3 @@ public enum CommandType {
5757
RARE
5858
}
5959
}
60-

core/src/main/java/org/opensearch/sql/expression/operator/arthmetic/ArithmeticFunction.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -265,4 +265,4 @@ private static DefaultFunctionResolver subtract() {
265265
private static DefaultFunctionResolver subtractFunction() {
266266
return subtractBase(BuiltinFunctionName.SUBTRACTFUNCTION.getName());
267267
}
268-
}
268+
}

core/src/main/java/org/opensearch/sql/expression/text/TextFunction.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -379,4 +379,3 @@ private static ExprValue exprReverse(ExprValue str) {
379379
return new ExprStringValue(new StringBuilder(str.stringValue()).reverse().toString());
380380
}
381381
}
382-

core/src/test/java/org/opensearch/sql/planner/logical/LogicalRelationTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,4 +33,4 @@ public void logicalRelationWithDataSourceHasNoInput() {
3333
assertEquals(0, relation.getChild().size());
3434
}
3535

36-
}
36+
}

core/src/test/java/org/opensearch/sql/planner/streaming/watermark/BoundedOutOfOrderWatermarkGeneratorTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,4 +58,4 @@ public AssertionHelper shouldGenerateWatermark(long expected) {
5858
return this;
5959
}
6060
}
61-
}
61+
}

core/src/test/java/org/opensearch/sql/planner/streaming/windowing/WindowTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,4 @@ void test() {
1818
assertEquals(2000, window.getEndTime());
1919
assertEquals(1999, window.maxTimestamp());
2020
}
21-
}
21+
}

0 commit comments

Comments
 (0)