Skip to content

Commit e377cf2

Browse files
[Spotless] Applying Google Code Format for common #7 (#1940)
* Spotless apply for common directory. Signed-off-by: Mitchell Gale <[email protected]> * Igoring checkstyle for common Signed-off-by: Mitchell Gale <[email protected]> * Spotless apply on string utils, Signed-off-by: Mitchell Gale <[email protected]> * Typo fix Signed-off-by: Yury-Fridlyand <[email protected]> --------- Signed-off-by: Mitchell Gale <[email protected]> Signed-off-by: Yury-Fridlyand <[email protected]> Co-authored-by: Yury-Fridlyand <[email protected]>
1 parent 245c4f8 commit e377cf2

28 files changed

+421
-495
lines changed

build.gradle

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,8 @@ repositories {
8484
spotless {
8585
java {
8686
target fileTree('.') {
87-
include 'datasources/**/*.java',
87+
include 'common/**/*.java',
88+
'datasources/**/*.java',
8889
'core/**/*.java'
8990
exclude '**/build/**', '**/build-*/**'
9091
}

common/build.gradle

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,11 @@ repositories {
3131
mavenCentral()
3232
}
3333

34+
// Being ignored as a temporary measure before being removed in favour of
35+
// spotless https://github.com/opensearch-project/sql/issues/1101
36+
checkstyleTest.ignoreFailures = true
37+
checkstyleMain.ignoreFailures = true
38+
3439
dependencies {
3540
api "org.antlr:antlr4-runtime:4.7.1"
3641
api group: 'com.google.guava', name: 'guava', version: '32.0.1-jre'
@@ -62,4 +67,4 @@ configurations.all {
6267
resolutionStrategy.force "org.apache.httpcomponents:httpcore:4.4.13"
6368
resolutionStrategy.force "joda-time:joda-time:2.10.12"
6469
resolutionStrategy.force "org.slf4j:slf4j-api:1.7.36"
65-
}
70+
}

common/src/main/java/org/opensearch/sql/common/antlr/CaseInsensitiveCharStream.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
* SPDX-License-Identifier: Apache-2.0
44
*/
55

6-
76
package org.opensearch.sql.common.antlr;
87

98
import org.antlr.v4.runtime.CharStream;

common/src/main/java/org/opensearch/sql/common/antlr/SyntaxAnalysisErrorListener.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
* SPDX-License-Identifier: Apache-2.0
44
*/
55

6-
76
package org.opensearch.sql.common.antlr;
87

98
import java.util.Locale;

common/src/main/java/org/opensearch/sql/common/antlr/SyntaxCheckException.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
* SPDX-License-Identifier: Apache-2.0
44
*/
55

6-
76
package org.opensearch.sql.common.antlr;
87

98
public class SyntaxCheckException extends RuntimeException {

common/src/main/java/org/opensearch/sql/common/authinterceptors/AwsSigningInterceptor.java

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -31,15 +31,17 @@ public class AwsSigningInterceptor implements Interceptor {
3131
private static final Logger LOG = LogManager.getLogger();
3232

3333
/**
34-
* AwsSigningInterceptor which intercepts http requests
35-
* and adds required headers for sigv4 authentication.
34+
* AwsSigningInterceptor which intercepts http requests and adds required headers for sigv4
35+
* authentication.
3636
*
3737
* @param awsCredentialsProvider awsCredentialsProvider.
3838
* @param region region.
3939
* @param serviceName serviceName.
4040
*/
41-
public AwsSigningInterceptor(@NonNull AWSCredentialsProvider awsCredentialsProvider,
42-
@NonNull String region, @NonNull String serviceName) {
41+
public AwsSigningInterceptor(
42+
@NonNull AWSCredentialsProvider awsCredentialsProvider,
43+
@NonNull String region,
44+
@NonNull String serviceName) {
4345
this.okHttpAwsV4Signer = new OkHttpAwsV4Signer(region, serviceName);
4446
this.awsCredentialsProvider = awsCredentialsProvider;
4547
}
@@ -48,25 +50,27 @@ public AwsSigningInterceptor(@NonNull AWSCredentialsProvider awsCredentialsProvi
4850
public Response intercept(Interceptor.Chain chain) throws IOException {
4951
Request request = chain.request();
5052

51-
DateTimeFormatter timestampFormat = DateTimeFormatter.ofPattern("yyyyMMdd'T'HHmmss'Z'")
52-
.withZone(ZoneId.of("GMT"));
53+
DateTimeFormatter timestampFormat =
54+
DateTimeFormatter.ofPattern("yyyyMMdd'T'HHmmss'Z'").withZone(ZoneId.of("GMT"));
5355

54-
55-
Request.Builder newRequestBuilder = request.newBuilder()
56-
.addHeader("x-amz-date", timestampFormat.format(ZonedDateTime.now()))
57-
.addHeader("host", request.url().host());
56+
Request.Builder newRequestBuilder =
57+
request
58+
.newBuilder()
59+
.addHeader("x-amz-date", timestampFormat.format(ZonedDateTime.now()))
60+
.addHeader("host", request.url().host());
5861

5962
AWSCredentials awsCredentials = awsCredentialsProvider.getCredentials();
6063
if (awsCredentialsProvider instanceof STSAssumeRoleSessionCredentialsProvider) {
61-
newRequestBuilder.addHeader("x-amz-security-token",
64+
newRequestBuilder.addHeader(
65+
"x-amz-security-token",
6266
((STSAssumeRoleSessionCredentialsProvider) awsCredentialsProvider)
6367
.getCredentials()
6468
.getSessionToken());
6569
}
6670
Request newRequest = newRequestBuilder.build();
67-
Request signed = okHttpAwsV4Signer.sign(newRequest,
68-
awsCredentials.getAWSAccessKeyId(), awsCredentials.getAWSSecretKey());
71+
Request signed =
72+
okHttpAwsV4Signer.sign(
73+
newRequest, awsCredentials.getAWSAccessKeyId(), awsCredentials.getAWSSecretKey());
6974
return chain.proceed(signed);
7075
}
71-
7276
}

common/src/main/java/org/opensearch/sql/common/authinterceptors/BasicAuthenticationInterceptor.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,11 @@ public BasicAuthenticationInterceptor(@NonNull String username, @NonNull String
2222
this.credentials = Credentials.basic(username, password);
2323
}
2424

25-
2625
@Override
2726
public Response intercept(Interceptor.Chain chain) throws IOException {
2827
Request request = chain.request();
29-
Request authenticatedRequest = request.newBuilder()
30-
.header("Authorization", credentials).build();
28+
Request authenticatedRequest =
29+
request.newBuilder().header("Authorization", credentials).build();
3130
return chain.proceed(authenticatedRequest);
3231
}
33-
3432
}

common/src/main/java/org/opensearch/sql/common/grok/Converter.java

Lines changed: 27 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,7 @@
2323
import java.util.regex.Pattern;
2424
import java.util.stream.Collectors;
2525

26-
/**
27-
* Convert String argument to the right type.
28-
*/
26+
/** Convert String argument to the right type. */
2927
public class Converter {
3028

3129
public enum Type {
@@ -51,13 +49,13 @@ public enum Type {
5149
private static final Pattern SPLITTER = Pattern.compile("[:;]");
5250

5351
private static final Map<String, Type> TYPES =
54-
Arrays.stream(Type.values())
55-
.collect(Collectors.toMap(t -> t.name().toLowerCase(), t -> t));
52+
Arrays.stream(Type.values()).collect(Collectors.toMap(t -> t.name().toLowerCase(), t -> t));
5653

5754
private static final Map<String, Type> TYPE_ALIASES =
5855
Arrays.stream(Type.values())
59-
.flatMap(type -> type.aliases.stream()
60-
.map(alias -> new AbstractMap.SimpleEntry<>(alias, type)))
56+
.flatMap(
57+
type ->
58+
type.aliases.stream().map(alias -> new AbstractMap.SimpleEntry<>(alias, type)))
6159
.collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue));
6260

6361
private static Type getType(String key) {
@@ -69,34 +67,30 @@ private static Type getType(String key) {
6967
return type;
7068
}
7169

72-
/**
73-
* getConverters.
74-
*/
75-
public static Map<String, IConverter<? extends Object>>
76-
getConverters(Collection<String> groupNames, Object... params) {
70+
/** getConverters. */
71+
public static Map<String, IConverter<? extends Object>> getConverters(
72+
Collection<String> groupNames, Object... params) {
7773
return groupNames.stream()
7874
.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-
}));
75+
.collect(
76+
Collectors.toMap(
77+
Function.identity(),
78+
key -> {
79+
String[] list = splitGrokPattern(key);
80+
IConverter<? extends Object> converter = getType(list[1]).converter;
81+
if (list.length == 3) {
82+
converter = converter.newConverter(list[2], params);
83+
}
84+
return converter;
85+
}));
8786
}
8887

89-
/**
90-
* getGroupTypes.
91-
*/
88+
/** getGroupTypes. */
9289
public static Map<String, Type> getGroupTypes(Collection<String> groupNames) {
9390
return groupNames.stream()
9491
.filter(Converter::containsDelimiter)
9592
.map(Converter::splitGrokPattern)
96-
.collect(Collectors.toMap(
97-
l -> l[0],
98-
l -> getType(l[1])
99-
));
93+
.collect(Collectors.toMap(l -> l[0], l -> getType(l[1])));
10094
}
10195

10296
public static String extractKey(String key) {
@@ -120,7 +114,6 @@ default IConverter<T> newConverter(String param, Object... params) {
120114
}
121115
}
122116

123-
124117
static class DateConverter implements IConverter<Instant> {
125118

126119
private final DateTimeFormatter formatter;
@@ -138,8 +131,12 @@ private DateConverter(DateTimeFormatter formatter, ZoneId timeZone) {
138131

139132
@Override
140133
public Instant convert(String value) {
141-
TemporalAccessor dt = formatter
142-
.parseBest(value.trim(), ZonedDateTime::from, LocalDateTime::from, OffsetDateTime::from,
134+
TemporalAccessor dt =
135+
formatter.parseBest(
136+
value.trim(),
137+
ZonedDateTime::from,
138+
LocalDateTime::from,
139+
OffsetDateTime::from,
143140
Instant::from,
144141
LocalDate::from);
145142
if (dt instanceof ZonedDateTime) {

common/src/main/java/org/opensearch/sql/common/grok/Grok.java

Lines changed: 27 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -16,36 +16,29 @@
1616
import org.opensearch.sql.common.grok.Converter.IConverter;
1717

1818
/**
19-
* {@code Grok} parse arbitrary text and structure it.
20-
* <br>
21-
* {@code Grok} is simple API that allows you to easily parse logs
22-
* and other files (single line). With {@code Grok},
23-
* you can turn unstructured log and event data into structured data.
19+
* {@code Grok} parse arbitrary text and structure it. <br>
20+
* {@code Grok} is simple API that allows you to easily parse logs and other files (single line).
21+
* With {@code Grok}, you can turn unstructured log and event data into structured data.
2422
*
2523
* @since 0.0.1
2624
*/
2725
public class Grok implements Serializable {
28-
/**
29-
* Named regex of the originalGrokPattern.
30-
*/
26+
/** Named regex of the originalGrokPattern. */
3127
private final String namedRegex;
28+
3229
/**
33-
* Map of the named regex of the originalGrokPattern
34-
* with id = namedregexid and value = namedregex.
30+
* Map of the named regex of the originalGrokPattern with id = namedregexid and value =
31+
* namedregex.
3532
*/
3633
private final Map<String, String> namedRegexCollection;
37-
/**
38-
* Original {@code Grok} pattern (expl: %{IP}).
39-
*/
34+
35+
/** Original {@code Grok} pattern (expl: %{IP}). */
4036
private final String originalGrokPattern;
41-
/**
42-
* Pattern of the namedRegex.
43-
*/
37+
38+
/** Pattern of the namedRegex. */
4439
private final Pattern compiledNamedRegex;
4540

46-
/**
47-
* {@code Grok} patterns definition.
48-
*/
41+
/** {@code Grok} patterns definition. */
4942
private final Map<String, String> grokPatternDefinition;
5043

5144
public final Set<String> namedGroups;
@@ -54,19 +47,16 @@ public class Grok implements Serializable {
5447

5548
public final Map<String, IConverter<? extends Object>> converters;
5649

57-
/**
58-
* only use in grok discovery.
59-
*/
50+
/** only use in grok discovery. */
6051
private String savedPattern = "";
6152

62-
/**
63-
* Grok.
64-
*/
65-
public Grok(String pattern,
66-
String namedRegex,
67-
Map<String, String> namedRegexCollection,
68-
Map<String, String> patternDefinitions,
69-
ZoneId defaultTimeZone) {
53+
/** Grok. */
54+
public Grok(
55+
String pattern,
56+
String namedRegex,
57+
Map<String, String> namedRegexCollection,
58+
Map<String, String> patternDefinitions,
59+
ZoneId defaultTimeZone) {
7060
this.originalGrokPattern = pattern;
7161
this.namedRegex = namedRegex;
7262
this.compiledNamedRegex = Pattern.compile(namedRegex);
@@ -132,8 +122,8 @@ public Map<String, String> getNamedRegexCollection() {
132122
}
133123

134124
/**
135-
* Match the given <tt>log</tt> with the named regex.
136-
* And return the json representation of the matched element
125+
* Match the given <tt>log</tt> with the named regex. And return the json representation of the
126+
* matched element
137127
*
138128
* @param log : log to match
139129
* @return map containing matches
@@ -144,8 +134,8 @@ public Map<String, Object> capture(String log) {
144134
}
145135

146136
/**
147-
* Match the given list of <tt>log</tt> with the named regex
148-
* and return the list of json representation of the matched elements.
137+
* Match the given list of <tt>log</tt> with the named regex and return the list of json
138+
* representation of the matched elements.
149139
*
150140
* @param logs : list of log
151141
* @return list of maps containing matches
@@ -159,8 +149,8 @@ public ArrayList<Map<String, Object>> capture(List<String> logs) {
159149
}
160150

161151
/**
162-
* Match the given <tt>text</tt> with the named regex
163-
* {@code Grok} will extract data from the string and get an extence of {@link Match}.
152+
* Match the given <tt>text</tt> with the named regex {@code Grok} will extract data from the
153+
* string and get an extence of {@link Match}.
164154
*
165155
* @param text : Single line of log
166156
* @return Grok Match
@@ -172,9 +162,7 @@ public Match match(CharSequence text) {
172162

173163
Matcher matcher = compiledNamedRegex.matcher(text);
174164
if (matcher.find()) {
175-
return new Match(
176-
text, this, matcher, matcher.start(0), matcher.end(0)
177-
);
165+
return new Match(text, this, matcher, matcher.start(0), matcher.end(0));
178166
}
179167

180168
return Match.EMPTY;

0 commit comments

Comments
 (0)