Skip to content

Commit b035b13

Browse files
[Spotless] Applying Google Code Format for sql files #11 (opensearch-project#1968)
* [Spotless] Applying Google Code Format for sql files #11 (#330) * Spotless apply, ignore checkstyle, manual java doc fixes. Signed-off-by: Mitchell Gale <[email protected]> * Spotless apply Signed-off-by: Mitchell Gale <[email protected]> --------- Signed-off-by: Mitchell Gale <[email protected]> * Apply suggestions from code review Co-authored-by: Guian Gumpac <[email protected]> Signed-off-by: Mitchell Gale <[email protected]> --------- Signed-off-by: Mitchell Gale <[email protected]> Signed-off-by: Mitchell Gale <[email protected]> Co-authored-by: Guian Gumpac <[email protected]>
1 parent 491a73b commit b035b13

32 files changed

+1221
-1638
lines changed

build.gradle

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,9 +84,10 @@ repositories {
8484
spotless {
8585
java {
8686
target fileTree('.') {
87-
include 'common/**/*.java',
88-
'datasources/**/*.java',
87+
include 'datasources/**/*.java',
8988
'core/**/*.java',
89+
'sql/**/*.java',
90+
'common/**/*.java',
9091
'ppl/**/*.java'
9192
exclude '**/build/**', '**/build-*/**'
9293
}

sql/build.gradle

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,11 @@ dependencies {
5858
testImplementation(testFixtures(project(":core")))
5959
}
6060

61+
// Being ignored as a temporary measure before being removed in favour of
62+
// spotless https://github.com/opensearch-project/sql/issues/1101
63+
checkstyleTest.ignoreFailures = true
64+
checkstyleMain.ignoreFailures = true
65+
6166
test {
6267
useJUnitPlatform()
6368
testLogging {

sql/src/main/java/org/opensearch/sql/sql/SQLService.java

Lines changed: 12 additions & 12 deletions
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.sql;
87

98
import java.util.Optional;
@@ -21,9 +20,7 @@
2120
import org.opensearch.sql.sql.parser.AstBuilder;
2221
import org.opensearch.sql.sql.parser.AstStatementBuilder;
2322

24-
/**
25-
* SQL service.
26-
*/
23+
/** SQL service. */
2724
@RequiredArgsConstructor
2825
public class SQLService {
2926

@@ -69,15 +66,19 @@ private AbstractPlan plan(
6966
if (request.getCursor().isPresent()) {
7067
// Handle v2 cursor here -- legacy cursor was handled earlier.
7168
if (isExplainRequest) {
72-
throw new UnsupportedOperationException("Explain of a paged query continuation "
73-
+ "is not supported. Use `explain` for the initial query request.");
69+
throw new UnsupportedOperationException(
70+
"Explain of a paged query continuation "
71+
+ "is not supported. Use `explain` for the initial query request.");
7472
}
7573
if (request.isCursorCloseRequest()) {
76-
return queryExecutionFactory.createCloseCursor(request.getCursor().get(),
77-
queryListener.orElse(null));
74+
return queryExecutionFactory.createCloseCursor(
75+
request.getCursor().get(), queryListener.orElse(null));
7876
}
79-
return queryExecutionFactory.create(request.getCursor().get(),
80-
isExplainRequest, queryListener.orElse(null), explainListener.orElse(null));
77+
return queryExecutionFactory.create(
78+
request.getCursor().get(),
79+
isExplainRequest,
80+
queryListener.orElse(null),
81+
explainListener.orElse(null));
8182
} else {
8283
// 1.Parse query and convert parse tree (CST) to abstract syntax tree (AST)
8384
ParseTree cst = parser.parse(request.getQuery());
@@ -90,8 +91,7 @@ private AbstractPlan plan(
9091
.fetchSize(request.getFetchSize())
9192
.build()));
9293

93-
return queryExecutionFactory.create(
94-
statement, queryListener, explainListener);
94+
return queryExecutionFactory.create(statement, queryListener, explainListener);
9595
}
9696
}
9797
}

sql/src/main/java/org/opensearch/sql/sql/antlr/AnonymizerListener.java

Lines changed: 8 additions & 14 deletions
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.sql.antlr;
87

98
import static org.opensearch.sql.sql.antlr.parser.OpenSearchSQLLexer.BACKTICK_QUOTE_ID;
@@ -31,21 +30,17 @@
3130
import org.antlr.v4.runtime.tree.ParseTreeListener;
3231
import org.antlr.v4.runtime.tree.TerminalNode;
3332

34-
/**
35-
* Parse tree listener for anonymizing SQL requests.
36-
*/
33+
/** Parse tree listener for anonymizing SQL requests. */
3734
public class AnonymizerListener implements ParseTreeListener {
3835
private String anonymizedQueryString = "";
3936
private static final int NO_TYPE = -1;
4037
private int previousType = NO_TYPE;
4138

4239
@Override
43-
public void enterEveryRule(ParserRuleContext ctx) {
44-
}
40+
public void enterEveryRule(ParserRuleContext ctx) {}
4541

4642
@Override
47-
public void exitEveryRule(ParserRuleContext ctx) {
48-
}
43+
public void exitEveryRule(ParserRuleContext ctx) {}
4944

5045
@Override
5146
public void visitTerminal(TerminalNode node) {
@@ -57,10 +52,11 @@ public void visitTerminal(TerminalNode node) {
5752
int token = node.getSymbol().getType();
5853
boolean isDotIdentifiers = token == DOT || previousType == DOT;
5954
boolean isComma = token == COMMA;
60-
boolean isEqualComparison = ((token == EQUAL_SYMBOL)
55+
boolean isEqualComparison =
56+
((token == EQUAL_SYMBOL)
6157
&& (previousType == LESS_SYMBOL
62-
|| previousType == GREATER_SYMBOL
63-
|| previousType == EXCLAMATION_SYMBOL));
58+
|| previousType == GREATER_SYMBOL
59+
|| previousType == EXCLAMATION_SYMBOL));
6460
boolean isNotEqualComparisonAlternative =
6561
previousType == LESS_SYMBOL && token == GREATER_SYMBOL;
6662
if (!isDotIdentifiers && !isComma && !isEqualComparison && !isNotEqualComparisonAlternative) {
@@ -103,9 +99,7 @@ public void visitTerminal(TerminalNode node) {
10399
}
104100

105101
@Override
106-
public void visitErrorNode(ErrorNode node) {
107-
108-
}
102+
public void visitErrorNode(ErrorNode node) {}
109103

110104
public String getAnonymizedQueryString() {
111105
return "(" + anonymizedQueryString + ")";

sql/src/main/java/org/opensearch/sql/sql/antlr/SQLSyntaxParser.java

Lines changed: 4 additions & 6 deletions
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.sql.antlr;
87

98
import org.antlr.v4.runtime.CommonTokenStream;
@@ -16,16 +15,15 @@
1615
import org.opensearch.sql.sql.antlr.parser.OpenSearchSQLLexer;
1716
import org.opensearch.sql.sql.antlr.parser.OpenSearchSQLParser;
1817

19-
/**
20-
* SQL syntax parser which encapsulates an ANTLR parser.
21-
*/
18+
/** SQL syntax parser which encapsulates an ANTLR parser. */
2219
public class SQLSyntaxParser implements Parser {
2320
private static final Logger LOG = LogManager.getLogger(SQLSyntaxParser.class);
2421

2522
/**
2623
* Parse a SQL query by ANTLR parser.
27-
* @param query a SQL query
28-
* @return parse tree root
24+
*
25+
* @param query a SQL query
26+
* @return parse tree root
2927
*/
3028
@Override
3129
public ParseTree parse(String query) {

sql/src/main/java/org/opensearch/sql/sql/domain/SQLQueryRequest.java

Lines changed: 32 additions & 40 deletions
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.sql.domain;
87

98
import java.util.Collections;
@@ -20,43 +19,30 @@
2019
import org.json.JSONObject;
2120
import org.opensearch.sql.protocol.response.format.Format;
2221

23-
/**
24-
* SQL query request.
25-
*/
22+
/** SQL query request. */
2623
@ToString
2724
@EqualsAndHashCode
2825
@RequiredArgsConstructor
2926
public class SQLQueryRequest {
3027
private static final String QUERY_FIELD_CURSOR = "cursor";
31-
private static final Set<String> SUPPORTED_FIELDS = Set.of(
32-
"query", "fetch_size", "parameters", QUERY_FIELD_CURSOR);
28+
private static final Set<String> SUPPORTED_FIELDS =
29+
Set.of("query", "fetch_size", "parameters", QUERY_FIELD_CURSOR);
3330
private static final String QUERY_PARAMS_FORMAT = "format";
3431
private static final String QUERY_PARAMS_SANITIZE = "sanitize";
3532

36-
/**
37-
* JSON payload in REST request.
38-
*/
33+
/** JSON payload in REST request. */
3934
private final JSONObject jsonContent;
4035

41-
/**
42-
* SQL query.
43-
*/
44-
@Getter
45-
private final String query;
36+
/** SQL query. */
37+
@Getter private final String query;
4638

47-
/**
48-
* Request path.
49-
*/
39+
/** Request path. */
5040
private final String path;
5141

52-
/**
53-
* Request format.
54-
*/
42+
/** Request format. */
5543
private final String format;
5644

57-
/**
58-
* Request params.
59-
*/
45+
/** Request params. */
6046
private Map<String, String> params = Collections.emptyMap();
6147

6248
@Getter
@@ -65,11 +51,13 @@ public class SQLQueryRequest {
6551

6652
private String cursor;
6753

68-
/**
69-
* Constructor of SQLQueryRequest that passes request params.
70-
*/
71-
public SQLQueryRequest(JSONObject jsonContent, String query, String path,
72-
Map<String, String> params, String cursor) {
54+
/** Constructor of SQLQueryRequest that passes request params. */
55+
public SQLQueryRequest(
56+
JSONObject jsonContent,
57+
String query,
58+
String path,
59+
Map<String, String> params,
60+
String cursor) {
7361
this.jsonContent = jsonContent;
7462
this.query = query;
7563
this.path = path;
@@ -80,24 +68,30 @@ public SQLQueryRequest(JSONObject jsonContent, String query, String path,
8068
}
8169

8270
/**
71+
*
72+
*
73+
* <pre>
8374
* Pre-check if the request can be supported by meeting ALL the following criteria:
8475
* 1.Only supported fields present in request body, ex. "filter" and "cursor" are not supported
8576
* 2.Response format is default or can be supported.
77+
* </pre>
8678
*
8779
* @return true if supported.
8880
*/
8981
public boolean isSupported() {
9082
var noCursor = !isCursor();
9183
var noQuery = query == null;
92-
var noUnsupportedParams = params.isEmpty()
93-
|| (params.size() == 1 && params.containsKey(QUERY_PARAMS_FORMAT));
84+
var noUnsupportedParams =
85+
params.isEmpty() || (params.size() == 1 && params.containsKey(QUERY_PARAMS_FORMAT));
9486
var noContent = jsonContent == null || jsonContent.isEmpty();
9587

96-
return ((!noCursor && noQuery
97-
&& noUnsupportedParams && noContent) // if cursor is given, but other things
98-
|| (noCursor && !noQuery)) // or if cursor is not given, but query
99-
&& isOnlySupportedFieldInPayload() // and request has supported fields only
100-
&& isSupportedFormat(); // and request is in supported format
88+
return ((!noCursor
89+
&& noQuery
90+
&& noUnsupportedParams
91+
&& noContent) // if cursor is given, but other things
92+
|| (noCursor && !noQuery)) // or if cursor is not given, but query
93+
&& isOnlySupportedFieldInPayload() // and request has supported fields only
94+
&& isSupportedFormat(); // and request is in supported format
10195
}
10296

10397
private boolean isCursor() {
@@ -106,6 +100,7 @@ private boolean isCursor() {
106100

107101
/**
108102
* Check if request is to explain rather than execute the query.
103+
*
109104
* @return true if it is an explain request
110105
*/
111106
public boolean isExplainRequest() {
@@ -116,16 +111,14 @@ public boolean isCursorCloseRequest() {
116111
return path.endsWith("/close");
117112
}
118113

119-
/**
120-
* Decide on the formatter by the requested format.
121-
*/
114+
/** Decide on the formatter by the requested format. */
122115
public Format format() {
123116
Optional<Format> optionalFormat = Format.of(format);
124117
if (optionalFormat.isPresent()) {
125118
return optionalFormat.get();
126119
} else {
127120
throw new IllegalArgumentException(
128-
String.format(Locale.ROOT,"response in %s format is not supported.", format));
121+
String.format(Locale.ROOT, "response in %s format is not supported.", format));
129122
}
130123
}
131124

@@ -155,5 +148,4 @@ private boolean shouldSanitize(Map<String, String> params) {
155148
}
156149
return true;
157150
}
158-
159151
}

0 commit comments

Comments
 (0)