Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Spotless] Applying Google Code Format for opensearch directory (pt 2/2) #17 #1978

Merged
merged 6 commits into from
Aug 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,9 @@ spotless {
'spark/**/*.java',
'plugin/**/*.java',
'ppl/**/*.java',
'integ-test/**/*java'
'integ-test/**/*java',
'core/**/*.java',
'opensearch/**/*.java'
exclude '**/build/**', '**/build-*/**'
}
importOrder()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
* SPDX-License-Identifier: Apache-2.0
*/


package org.opensearch.sql.opensearch.client;

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

/**
* Constructor of OpenSearchNodeClient.
*/
/** Constructor of OpenSearchNodeClient. */
public OpenSearchNodeClient(NodeClient client) {
this.client = client;
}

@Override
public boolean exists(String indexName) {
try {
IndicesExistsResponse checkExistResponse = client.admin().indices()
.exists(new IndicesExistsRequest(indexName)).actionGet();
IndicesExistsResponse checkExistResponse =
client.admin().indices().exists(new IndicesExistsRequest(indexName)).actionGet();
return checkExistResponse.isExists();
} catch (Exception e) {
throw new IllegalStateException("Failed to check if index [" + indexName + "] exists", e);
Expand Down Expand Up @@ -83,13 +80,12 @@ public void createIndex(String indexName, Map<String, Object> mappings) {
@Override
public Map<String, IndexMapping> getIndexMappings(String... indexExpression) {
try {
GetMappingsResponse mappingsResponse = client.admin().indices()
.prepareGetMappings(indexExpression)
.setLocal(true)
.get();
return mappingsResponse.mappings().entrySet().stream().collect(Collectors.toUnmodifiableMap(
Map.Entry::getKey,
cursor -> new IndexMapping(cursor.getValue())));
GetMappingsResponse mappingsResponse =
client.admin().indices().prepareGetMappings(indexExpression).setLocal(true).get();
return mappingsResponse.mappings().entrySet().stream()
.collect(
Collectors.toUnmodifiableMap(
Map.Entry::getKey, cursor -> new IndexMapping(cursor.getValue())));
} catch (IndexNotFoundException e) {
// Re-throw directly to be treated as client error finally
throw e;
Expand Down Expand Up @@ -127,15 +123,11 @@ public Map<String, Integer> getIndexMaxResultWindows(String... indexExpression)
}
}

/**
* TODO: Scroll doesn't work for aggregation. Support aggregation later.
*/
/** TODO: Scroll doesn't work for aggregation. Support aggregation later. */
@Override
public OpenSearchResponse search(OpenSearchRequest request) {
return request.search(
req -> client.search(req).actionGet(),
req -> client.searchScroll(req).actionGet()
);
req -> client.search(req).actionGet(), req -> client.searchScroll(req).actionGet());
}

/**
Expand All @@ -145,13 +137,12 @@ public OpenSearchResponse search(OpenSearchRequest request) {
*/
@Override
public List<String> indices() {
final GetIndexResponse indexResponse = client.admin().indices()
.prepareGetIndex()
.setLocal(true)
.get();
final GetIndexResponse indexResponse =
client.admin().indices().prepareGetIndex().setLocal(true).get();
final Stream<String> aliasStream =
ImmutableList.copyOf(indexResponse.aliases().values()).stream()
.flatMap(Collection::stream).map(AliasMetadata::alias);
.flatMap(Collection::stream)
.map(AliasMetadata::alias);

return Stream.concat(Arrays.stream(indexResponse.getIndices()), aliasStream)
.collect(Collectors.toList());
Expand All @@ -164,20 +155,20 @@ public List<String> indices() {
*/
@Override
public Map<String, String> meta() {
return ImmutableMap.of(META_CLUSTER_NAME,
client.settings().get("cluster.name", "opensearch"));
return ImmutableMap.of(META_CLUSTER_NAME, client.settings().get("cluster.name", "opensearch"));
}

@Override
public void cleanup(OpenSearchRequest request) {
request.clean(scrollId -> {
try {
client.prepareClearScroll().addScrollId(scrollId).get();
} catch (Exception e) {
throw new IllegalStateException(
"Failed to clean up resources for search request " + request, e);
}
});
request.clean(
scrollId -> {
try {
client.prepareClearScroll().addScrollId(scrollId).get();
} catch (Exception e) {
throw new IllegalStateException(
"Failed to clean up resources for search request " + request, e);
}
});
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
* SPDX-License-Identifier: Apache-2.0
*/


package org.opensearch.sql.opensearch.client;

import com.google.common.collect.ImmutableList;
Expand Down Expand Up @@ -49,8 +48,7 @@ public class OpenSearchRestClient implements OpenSearchClient {
@Override
public boolean exists(String indexName) {
try {
return client.indices().exists(
new GetIndexRequest(indexName), RequestOptions.DEFAULT);
return client.indices().exists(new GetIndexRequest(indexName), RequestOptions.DEFAULT);
} catch (IOException e) {
throw new IllegalStateException("Failed to check if index [" + indexName + "] exist", e);
}
Expand All @@ -59,8 +57,9 @@ public boolean exists(String indexName) {
@Override
public void createIndex(String indexName, Map<String, Object> mappings) {
try {
client.indices().create(
new CreateIndexRequest(indexName).mapping(mappings), RequestOptions.DEFAULT);
client
.indices()
.create(new CreateIndexRequest(indexName).mapping(mappings), RequestOptions.DEFAULT);
} catch (IOException e) {
throw new IllegalStateException("Failed to create index [" + indexName + "]", e);
}
Expand All @@ -80,27 +79,29 @@ public Map<String, IndexMapping> getIndexMappings(String... indexExpression) {

@Override
public Map<String, Integer> getIndexMaxResultWindows(String... indexExpression) {
GetSettingsRequest request = new GetSettingsRequest()
.indices(indexExpression).includeDefaults(true);
GetSettingsRequest request =
new GetSettingsRequest().indices(indexExpression).includeDefaults(true);
try {
GetSettingsResponse response = client.indices().getSettings(request, RequestOptions.DEFAULT);
Map<String, Settings> settings = response.getIndexToSettings();
Map<String, Settings> defaultSettings = response.getIndexToDefaultSettings();
Map<String, Integer> result = new HashMap<>();

defaultSettings.forEach((key, value) -> {
Integer maxResultWindow = value.getAsInt("index.max_result_window", null);
if (maxResultWindow != null) {
result.put(key, maxResultWindow);
}
});

settings.forEach((key, value) -> {
Integer maxResultWindow = value.getAsInt("index.max_result_window", null);
if (maxResultWindow != null) {
result.put(key, maxResultWindow);
}
});
defaultSettings.forEach(
(key, value) -> {
Integer maxResultWindow = value.getAsInt("index.max_result_window", null);
if (maxResultWindow != null) {
result.put(key, maxResultWindow);
}
});

settings.forEach(
(key, value) -> {
Integer maxResultWindow = value.getAsInt("index.max_result_window", null);
if (maxResultWindow != null) {
result.put(key, maxResultWindow);
}
});

return result;
} catch (IOException e) {
Expand All @@ -126,8 +127,7 @@ public OpenSearchResponse search(OpenSearchRequest request) {
throw new IllegalStateException(
"Failed to perform scroll operation with request " + req, e);
}
}
);
});
}

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

@Override
public void cleanup(OpenSearchRequest request) {
request.clean(scrollId -> {
try {
ClearScrollRequest clearRequest = new ClearScrollRequest();
clearRequest.addScrollId(scrollId);
client.clearScroll(clearRequest, RequestOptions.DEFAULT);
} catch (IOException e) {
throw new IllegalStateException(
"Failed to clean up resources for search request " + request, e);
}
});
request.clean(
scrollId -> {
try {
ClearScrollRequest clearRequest = new ClearScrollRequest();
clearRequest.addScrollId(scrollId);
client.clearScroll(clearRequest, RequestOptions.DEFAULT);
} catch (IOException e) {
throw new IllegalStateException(
"Failed to clean up resources for search request " + request, e);
}
});
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,15 @@
* SPDX-License-Identifier: Apache-2.0
*/


package org.opensearch.sql.opensearch.data.type;

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

import lombok.EqualsAndHashCode;

/**
* The type of a geo_point value. See
* <a href="https://opensearch.org/docs/latest/opensearch/supported-field-types/geo-point/">doc</a>
* The type of a geo_point value. See <a
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this isn't going to work

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It works

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

image

* href="https://opensearch.org/docs/latest/opensearch/supported-field-types/geo-point/">doc</a>
*/
@EqualsAndHashCode(callSuper = false)
public class OpenSearchGeoPointType extends OpenSearchDataType {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,15 @@
* SPDX-License-Identifier: Apache-2.0
*/


package org.opensearch.sql.opensearch.data.type;

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

import lombok.EqualsAndHashCode;

/**
* The type of an ip value. See
* <a href="https://opensearch.org/docs/latest/opensearch/supported-field-types/ip/">doc</a>
* The type of an ip value. See <a
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ditto

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ditto

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ditto

* href="https://opensearch.org/docs/latest/opensearch/supported-field-types/ip/">doc</a>
*/
@EqualsAndHashCode(callSuper = false)
public class OpenSearchIpType extends OpenSearchDataType {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,16 @@
import org.opensearch.sql.data.type.ExprType;

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

private static final OpenSearchTextType instance = new OpenSearchTextType();

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

private OpenSearchTextType() {
super(MappingType.Text);
Expand All @@ -34,6 +33,7 @@ private OpenSearchTextType() {

/**
* Constructs a Text Type using the passed in fields argument.
*
* @param fields The fields to be used to construct the text type.
* @return A new OpenSeachTextTypeObject
*/
Expand Down Expand Up @@ -67,7 +67,7 @@ protected OpenSearchDataType cloneEmpty() {
}

/**
* Text field doesn't have doc value (exception thrown even when you call "get")
* Text field doesn't have doc value (exception thrown even when you call "get")<br>
* Limitation: assume inner field name is always "keyword".
*/
public static String convertTextToKeyword(String fieldName, ExprType fieldType) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@
import org.apache.commons.lang3.tuple.Pair;

/**
*
* Regardless the underling data format, the {@link Content} define the data in abstract manner.
* which could be parsed by ElasticsearchExprValueFactory. There are two major use cases:
*
* <ol>
* <li>Represent the JSON data retrieve from OpenSearch search response.</li>
* <li>Represent the Object data extract from the OpenSearch aggregation response.</li>
* <li>Represent the JSON data retrieve from OpenSearch search response.
* <li>Represent the Object data extract from the OpenSearch aggregation response.
* </ol>
*/
public interface Content {
Expand Down
Loading