Skip to content

Commit b977f1e

Browse files
[Spotless] Applying Google Code Format for opensearch directory (pt 2/2) #17 (opensearch-project#1978)
* spotless apply for OpenSearch P2. Signed-off-by: Mitchell Gale <[email protected]> * Spotlesss apply run Signed-off-by: Mitchell Gale <[email protected]> * Addressed PR comments 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]> * spotless apply Signed-off-by: Mitchell Gale <[email protected]> * fixed json formatting in test. 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 56aa572 commit b977f1e

File tree

82 files changed

+2396
-2776
lines changed

Some content is hidden

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

82 files changed

+2396
-2776
lines changed

build.gradle

+3-1
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,9 @@ spotless {
9393
'spark/**/*.java',
9494
'plugin/**/*.java',
9595
'ppl/**/*.java',
96-
'integ-test/**/*java'
96+
'integ-test/**/*java',
97+
'core/**/*.java',
98+
'opensearch/**/*.java'
9799
exclude '**/build/**', '**/build-*/**'
98100
}
99101
importOrder()

opensearch/src/main/java/org/opensearch/sql/opensearch/client/OpenSearchNodeClient.java

+25-34
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.opensearch.client;
87

98
import com.google.common.collect.ImmutableList;
@@ -40,18 +39,16 @@ public class OpenSearchNodeClient implements OpenSearchClient {
4039
/** Node client provided by OpenSearch container. */
4140
private final NodeClient client;
4241

43-
/**
44-
* Constructor of OpenSearchNodeClient.
45-
*/
42+
/** Constructor of OpenSearchNodeClient. */
4643
public OpenSearchNodeClient(NodeClient client) {
4744
this.client = client;
4845
}
4946

5047
@Override
5148
public boolean exists(String indexName) {
5249
try {
53-
IndicesExistsResponse checkExistResponse = client.admin().indices()
54-
.exists(new IndicesExistsRequest(indexName)).actionGet();
50+
IndicesExistsResponse checkExistResponse =
51+
client.admin().indices().exists(new IndicesExistsRequest(indexName)).actionGet();
5552
return checkExistResponse.isExists();
5653
} catch (Exception e) {
5754
throw new IllegalStateException("Failed to check if index [" + indexName + "] exists", e);
@@ -83,13 +80,12 @@ public void createIndex(String indexName, Map<String, Object> mappings) {
8380
@Override
8481
public Map<String, IndexMapping> getIndexMappings(String... indexExpression) {
8582
try {
86-
GetMappingsResponse mappingsResponse = client.admin().indices()
87-
.prepareGetMappings(indexExpression)
88-
.setLocal(true)
89-
.get();
90-
return mappingsResponse.mappings().entrySet().stream().collect(Collectors.toUnmodifiableMap(
91-
Map.Entry::getKey,
92-
cursor -> new IndexMapping(cursor.getValue())));
83+
GetMappingsResponse mappingsResponse =
84+
client.admin().indices().prepareGetMappings(indexExpression).setLocal(true).get();
85+
return mappingsResponse.mappings().entrySet().stream()
86+
.collect(
87+
Collectors.toUnmodifiableMap(
88+
Map.Entry::getKey, cursor -> new IndexMapping(cursor.getValue())));
9389
} catch (IndexNotFoundException e) {
9490
// Re-throw directly to be treated as client error finally
9591
throw e;
@@ -127,15 +123,11 @@ public Map<String, Integer> getIndexMaxResultWindows(String... indexExpression)
127123
}
128124
}
129125

130-
/**
131-
* TODO: Scroll doesn't work for aggregation. Support aggregation later.
132-
*/
126+
/** TODO: Scroll doesn't work for aggregation. Support aggregation later. */
133127
@Override
134128
public OpenSearchResponse search(OpenSearchRequest request) {
135129
return request.search(
136-
req -> client.search(req).actionGet(),
137-
req -> client.searchScroll(req).actionGet()
138-
);
130+
req -> client.search(req).actionGet(), req -> client.searchScroll(req).actionGet());
139131
}
140132

141133
/**
@@ -145,13 +137,12 @@ public OpenSearchResponse search(OpenSearchRequest request) {
145137
*/
146138
@Override
147139
public List<String> indices() {
148-
final GetIndexResponse indexResponse = client.admin().indices()
149-
.prepareGetIndex()
150-
.setLocal(true)
151-
.get();
140+
final GetIndexResponse indexResponse =
141+
client.admin().indices().prepareGetIndex().setLocal(true).get();
152142
final Stream<String> aliasStream =
153143
ImmutableList.copyOf(indexResponse.aliases().values()).stream()
154-
.flatMap(Collection::stream).map(AliasMetadata::alias);
144+
.flatMap(Collection::stream)
145+
.map(AliasMetadata::alias);
155146

156147
return Stream.concat(Arrays.stream(indexResponse.getIndices()), aliasStream)
157148
.collect(Collectors.toList());
@@ -164,20 +155,20 @@ public List<String> indices() {
164155
*/
165156
@Override
166157
public Map<String, String> meta() {
167-
return ImmutableMap.of(META_CLUSTER_NAME,
168-
client.settings().get("cluster.name", "opensearch"));
158+
return ImmutableMap.of(META_CLUSTER_NAME, client.settings().get("cluster.name", "opensearch"));
169159
}
170160

171161
@Override
172162
public void cleanup(OpenSearchRequest request) {
173-
request.clean(scrollId -> {
174-
try {
175-
client.prepareClearScroll().addScrollId(scrollId).get();
176-
} catch (Exception e) {
177-
throw new IllegalStateException(
178-
"Failed to clean up resources for search request " + request, e);
179-
}
180-
});
163+
request.clean(
164+
scrollId -> {
165+
try {
166+
client.prepareClearScroll().addScrollId(scrollId).get();
167+
} catch (Exception e) {
168+
throw new IllegalStateException(
169+
"Failed to clean up resources for search request " + request, e);
170+
}
171+
});
181172
}
182173

183174
@Override

opensearch/src/main/java/org/opensearch/sql/opensearch/client/OpenSearchRestClient.java

+35-33
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.opensearch.client;
87

98
import com.google.common.collect.ImmutableList;
@@ -49,8 +48,7 @@ public class OpenSearchRestClient implements OpenSearchClient {
4948
@Override
5049
public boolean exists(String indexName) {
5150
try {
52-
return client.indices().exists(
53-
new GetIndexRequest(indexName), RequestOptions.DEFAULT);
51+
return client.indices().exists(new GetIndexRequest(indexName), RequestOptions.DEFAULT);
5452
} catch (IOException e) {
5553
throw new IllegalStateException("Failed to check if index [" + indexName + "] exist", e);
5654
}
@@ -59,8 +57,9 @@ public boolean exists(String indexName) {
5957
@Override
6058
public void createIndex(String indexName, Map<String, Object> mappings) {
6159
try {
62-
client.indices().create(
63-
new CreateIndexRequest(indexName).mapping(mappings), RequestOptions.DEFAULT);
60+
client
61+
.indices()
62+
.create(new CreateIndexRequest(indexName).mapping(mappings), RequestOptions.DEFAULT);
6463
} catch (IOException e) {
6564
throw new IllegalStateException("Failed to create index [" + indexName + "]", e);
6665
}
@@ -80,27 +79,29 @@ public Map<String, IndexMapping> getIndexMappings(String... indexExpression) {
8079

8180
@Override
8281
public Map<String, Integer> getIndexMaxResultWindows(String... indexExpression) {
83-
GetSettingsRequest request = new GetSettingsRequest()
84-
.indices(indexExpression).includeDefaults(true);
82+
GetSettingsRequest request =
83+
new GetSettingsRequest().indices(indexExpression).includeDefaults(true);
8584
try {
8685
GetSettingsResponse response = client.indices().getSettings(request, RequestOptions.DEFAULT);
8786
Map<String, Settings> settings = response.getIndexToSettings();
8887
Map<String, Settings> defaultSettings = response.getIndexToDefaultSettings();
8988
Map<String, Integer> result = new HashMap<>();
9089

91-
defaultSettings.forEach((key, value) -> {
92-
Integer maxResultWindow = value.getAsInt("index.max_result_window", null);
93-
if (maxResultWindow != null) {
94-
result.put(key, maxResultWindow);
95-
}
96-
});
97-
98-
settings.forEach((key, value) -> {
99-
Integer maxResultWindow = value.getAsInt("index.max_result_window", null);
100-
if (maxResultWindow != null) {
101-
result.put(key, maxResultWindow);
102-
}
103-
});
90+
defaultSettings.forEach(
91+
(key, value) -> {
92+
Integer maxResultWindow = value.getAsInt("index.max_result_window", null);
93+
if (maxResultWindow != null) {
94+
result.put(key, maxResultWindow);
95+
}
96+
});
97+
98+
settings.forEach(
99+
(key, value) -> {
100+
Integer maxResultWindow = value.getAsInt("index.max_result_window", null);
101+
if (maxResultWindow != null) {
102+
result.put(key, maxResultWindow);
103+
}
104+
});
104105

105106
return result;
106107
} catch (IOException e) {
@@ -126,8 +127,7 @@ public OpenSearchResponse search(OpenSearchRequest request) {
126127
throw new IllegalStateException(
127128
"Failed to perform scroll operation with request " + req, e);
128129
}
129-
}
130-
);
130+
});
131131
}
132132

133133
/**
@@ -142,7 +142,8 @@ public List<String> indices() {
142142
client.indices().get(new GetIndexRequest(), RequestOptions.DEFAULT);
143143
final Stream<String> aliasStream =
144144
ImmutableList.copyOf(indexResponse.getAliases().values()).stream()
145-
.flatMap(Collection::stream).map(AliasMetadata::alias);
145+
.flatMap(Collection::stream)
146+
.map(AliasMetadata::alias);
146147
return Stream.concat(Arrays.stream(indexResponse.getIndices()), aliasStream)
147148
.collect(Collectors.toList());
148149
} catch (IOException e) {
@@ -173,16 +174,17 @@ public Map<String, String> meta() {
173174

174175
@Override
175176
public void cleanup(OpenSearchRequest request) {
176-
request.clean(scrollId -> {
177-
try {
178-
ClearScrollRequest clearRequest = new ClearScrollRequest();
179-
clearRequest.addScrollId(scrollId);
180-
client.clearScroll(clearRequest, RequestOptions.DEFAULT);
181-
} catch (IOException e) {
182-
throw new IllegalStateException(
183-
"Failed to clean up resources for search request " + request, e);
184-
}
185-
});
177+
request.clean(
178+
scrollId -> {
179+
try {
180+
ClearScrollRequest clearRequest = new ClearScrollRequest();
181+
clearRequest.addScrollId(scrollId);
182+
client.clearScroll(clearRequest, RequestOptions.DEFAULT);
183+
} catch (IOException e) {
184+
throw new IllegalStateException(
185+
"Failed to clean up resources for search request " + request, e);
186+
}
187+
});
186188
}
187189

188190
@Override

opensearch/src/main/java/org/opensearch/sql/opensearch/data/type/OpenSearchGeoPointType.java

+2-3
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,15 @@
33
* SPDX-License-Identifier: Apache-2.0
44
*/
55

6-
76
package org.opensearch.sql.opensearch.data.type;
87

98
import static org.opensearch.sql.data.type.ExprCoreType.UNKNOWN;
109

1110
import lombok.EqualsAndHashCode;
1211

1312
/**
14-
* The type of a geo_point value. See
15-
* <a href="https://opensearch.org/docs/latest/opensearch/supported-field-types/geo-point/">doc</a>
13+
* The type of a geo_point value. See <a
14+
* href="https://opensearch.org/docs/latest/opensearch/supported-field-types/geo-point/">doc</a>
1615
*/
1716
@EqualsAndHashCode(callSuper = false)
1817
public class OpenSearchGeoPointType extends OpenSearchDataType {

opensearch/src/main/java/org/opensearch/sql/opensearch/data/type/OpenSearchIpType.java

+2-3
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,15 @@
33
* SPDX-License-Identifier: Apache-2.0
44
*/
55

6-
76
package org.opensearch.sql.opensearch.data.type;
87

98
import static org.opensearch.sql.data.type.ExprCoreType.UNKNOWN;
109

1110
import lombok.EqualsAndHashCode;
1211

1312
/**
14-
* The type of an ip value. See
15-
* <a href="https://opensearch.org/docs/latest/opensearch/supported-field-types/ip/">doc</a>
13+
* The type of an ip value. See <a
14+
* href="https://opensearch.org/docs/latest/opensearch/supported-field-types/ip/">doc</a>
1615
*/
1716
@EqualsAndHashCode(callSuper = false)
1817
public class OpenSearchIpType extends OpenSearchDataType {

opensearch/src/main/java/org/opensearch/sql/opensearch/data/type/OpenSearchTextType.java

+5-5
Original file line numberDiff line numberDiff line change
@@ -15,17 +15,16 @@
1515
import org.opensearch.sql.data.type.ExprType;
1616

1717
/**
18-
* The type of a text value. See
19-
* <a href="https://opensearch.org/docs/latest/opensearch/supported-field-types/text/">doc</a>
18+
* The type of text value. See <a
19+
* href="https://opensearch.org/docs/latest/opensearch/supported-field-types/text/">doc</a>
2020
*/
2121
public class OpenSearchTextType extends OpenSearchDataType {
2222

2323
private static final OpenSearchTextType instance = new OpenSearchTextType();
2424

2525
// text could have fields
2626
// a read-only collection
27-
@EqualsAndHashCode.Exclude
28-
Map<String, OpenSearchDataType> fields = ImmutableMap.of();
27+
@EqualsAndHashCode.Exclude Map<String, OpenSearchDataType> fields = ImmutableMap.of();
2928

3029
private OpenSearchTextType() {
3130
super(MappingType.Text);
@@ -34,6 +33,7 @@ private OpenSearchTextType() {
3433

3534
/**
3635
* Constructs a Text Type using the passed in fields argument.
36+
*
3737
* @param fields The fields to be used to construct the text type.
3838
* @return A new OpenSeachTextTypeObject
3939
*/
@@ -67,7 +67,7 @@ protected OpenSearchDataType cloneEmpty() {
6767
}
6868

6969
/**
70-
* Text field doesn't have doc value (exception thrown even when you call "get")
70+
* Text field doesn't have doc value (exception thrown even when you call "get")<br>
7171
* Limitation: assume inner field name is always "keyword".
7272
*/
7373
public static String convertTextToKeyword(String fieldName, ExprType fieldType) {

opensearch/src/main/java/org/opensearch/sql/opensearch/data/utils/Content.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,12 @@
1010
import org.apache.commons.lang3.tuple.Pair;
1111

1212
/**
13-
*
1413
* Regardless the underling data format, the {@link Content} define the data in abstract manner.
1514
* which could be parsed by ElasticsearchExprValueFactory. There are two major use cases:
15+
*
1616
* <ol>
17-
* <li>Represent the JSON data retrieve from OpenSearch search response.</li>
18-
* <li>Represent the Object data extract from the OpenSearch aggregation response.</li>
17+
* <li>Represent the JSON data retrieve from OpenSearch search response.
18+
* <li>Represent the Object data extract from the OpenSearch aggregation response.
1919
* </ol>
2020
*/
2121
public interface Content {

0 commit comments

Comments
 (0)