Skip to content

Commit

Permalink
Keep up with refactoring in OpenSearch. (opensearch-project#1588)
Browse files Browse the repository at this point in the history
* Keep up with refactoring in OpenSearch.

Signed-off-by: MaxKsyunz <maxk@bitquilltech.com>

* Updating code formatting.

Signed-off-by: MaxKsyunz <maxk@bitquilltech.com>

---------

Signed-off-by: MaxKsyunz <maxk@bitquilltech.com>
  • Loading branch information
Max Ksyunz authored Apr 27, 2023
1 parent b90065f commit 3fc11a4
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,13 @@

package org.opensearch.sql.legacy.executor;

import com.carrotsearch.hppc.cursors.ObjectObjectCursor;
import java.io.IOException;
import java.util.List;
import java.util.Map;

import org.opensearch.action.admin.indices.get.GetIndexRequest;
import org.opensearch.action.admin.indices.get.GetIndexResponse;
import org.opensearch.cluster.metadata.AliasMetadata;
import org.opensearch.cluster.metadata.MappingMetadata;
import org.opensearch.common.collect.ImmutableOpenMap;
import org.opensearch.common.settings.Settings;
import org.opensearch.core.xcontent.ToXContent;
import org.opensearch.core.xcontent.XContentBuilder;
Expand All @@ -25,7 +22,6 @@
import org.opensearch.rest.RestStatus;
import org.opensearch.rest.action.RestBuilderListener;
import org.opensearch.sql.legacy.antlr.semantic.SemanticAnalysisException;
import org.opensearch.sql.legacy.domain.Field;

/**
* Created by Eliran on 6/10/2015.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,8 @@
import org.opensearch.cluster.ClusterState;
import org.opensearch.cluster.metadata.IndexMetadata;
import org.opensearch.cluster.metadata.IndexNameExpressionResolver;
import org.opensearch.cluster.metadata.MappingMetadata;
import org.opensearch.cluster.metadata.Metadata;
import org.opensearch.cluster.service.ClusterService;
import org.opensearch.common.collect.ImmutableOpenMap;
import org.opensearch.common.xcontent.XContentType;
import org.opensearch.core.xcontent.DeprecationHandler;
import org.opensearch.core.xcontent.NamedXContentRegistry;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,11 +112,11 @@ public Map<String, Integer> getIndexMaxResultWindows(String... indexExpression)
GetSettingsResponse settingsResponse =
client.admin().indices().prepareGetSettings(indexExpression).setLocal(true).get();
ImmutableMap.Builder<String, Integer> result = ImmutableMap.builder();
for (ObjectObjectCursor<String, Settings> indexToSetting :
settingsResponse.getIndexToSettings()) {
Settings settings = indexToSetting.value;
for (Map.Entry<String, Settings> indexToSetting :
settingsResponse.getIndexToSettings().entrySet()) {
Settings settings = indexToSetting.getValue();
result.put(
indexToSetting.key,
indexToSetting.getKey(),
settings.getAsInt(
IndexSettings.MAX_RESULT_WINDOW_SETTING.getKey(),
IndexSettings.MAX_RESULT_WINDOW_SETTING.getDefault(settings)));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
import org.opensearch.client.indices.GetMappingsResponse;
import org.opensearch.client.node.NodeClient;
import org.opensearch.cluster.metadata.AliasMetadata;
import org.opensearch.common.collect.ImmutableOpenMap;
import org.opensearch.common.settings.Settings;
import org.opensearch.sql.opensearch.mapping.IndexMapping;
import org.opensearch.sql.opensearch.request.OpenSearchRequest;
Expand Down Expand Up @@ -85,21 +84,21 @@ public Map<String, Integer> getIndexMaxResultWindows(String... indexExpression)
.indices(indexExpression).includeDefaults(true);
try {
GetSettingsResponse response = client.indices().getSettings(request, RequestOptions.DEFAULT);
ImmutableOpenMap<String, Settings> settings = response.getIndexToSettings();
ImmutableOpenMap<String, Settings> defaultSettings = response.getIndexToDefaultSettings();
Map<String, Settings> settings = response.getIndexToSettings();
Map<String, Settings> defaultSettings = response.getIndexToDefaultSettings();
Map<String, Integer> result = new HashMap<>();

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

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@
import org.opensearch.cluster.metadata.AliasMetadata;
import org.opensearch.cluster.metadata.IndexMetadata;
import org.opensearch.cluster.metadata.MappingMetadata;
import org.opensearch.common.collect.ImmutableOpenMap;
import org.opensearch.common.settings.Settings;
import org.opensearch.common.util.concurrent.ThreadContext;
import org.opensearch.common.xcontent.XContentType;
Expand Down Expand Up @@ -425,10 +424,8 @@ private void mockNodeClientSettings(String indexName, String indexMetadata)
GetSettingsResponse mockResponse = mock(GetSettingsResponse.class);
when(nodeClient.admin().indices().prepareGetSettings(any()).setLocal(anyBoolean()).get())
.thenReturn(mockResponse);
ImmutableOpenMap<String, Settings> metadata =
new ImmutableOpenMap.Builder<String, Settings>()
.fPut(indexName, IndexMetadata.fromXContent(createParser(indexMetadata)).getSettings())
.build();
Map<String, Settings> metadata = Map.of(indexName,
IndexMetadata.fromXContent(createParser(indexMetadata)).getSettings());

when(mockResponse.getIndexToSettings()).thenReturn(metadata);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@
import org.opensearch.client.indices.GetMappingsResponse;
import org.opensearch.cluster.metadata.IndexMetadata;
import org.opensearch.cluster.metadata.MappingMetadata;
import org.opensearch.common.collect.ImmutableOpenMap;
import org.opensearch.common.settings.Settings;
import org.opensearch.common.xcontent.XContentType;
import org.opensearch.core.xcontent.DeprecationHandler;
Expand Down Expand Up @@ -232,9 +231,9 @@ void getIndexMaxResultWindowsSettings() throws IOException {
.put("index.max_result_window", maxResultWindow)
.build();
Settings emptySettings = Settings.builder().build();
ImmutableOpenMap<String, Settings> indexToSettings =
Map<String, Settings> indexToSettings =
mockSettings(indexName, maxResultWindowSettings);
ImmutableOpenMap<String, Settings> indexToDefaultSettings =
Map<String, Settings> indexToDefaultSettings =
mockSettings(indexName, emptySettings);
when(response.getIndexToSettings()).thenReturn(indexToSettings);
when(response.getIndexToDefaultSettings()).thenReturn(indexToDefaultSettings);
Expand All @@ -256,9 +255,9 @@ void getIndexMaxResultWindowsDefaultSettings() throws IOException {
.put("index.max_result_window", maxResultWindow)
.build();
Settings emptySettings = Settings.builder().build();
ImmutableOpenMap<String, Settings> indexToSettings =
Map<String, Settings> indexToSettings =
mockSettings(indexName, emptySettings);
ImmutableOpenMap<String, Settings> indexToDefaultSettings =
Map<String, Settings> indexToDefaultSettings =
mockSettings(indexName, maxResultWindowSettings);
when(response.getIndexToSettings()).thenReturn(indexToSettings);
when(response.getIndexToDefaultSettings()).thenReturn(indexToDefaultSettings);
Expand Down Expand Up @@ -427,10 +426,8 @@ private Map<String, MappingMetadata> mockFieldMappings(String indexName, String
return ImmutableMap.of(indexName, IndexMetadata.fromXContent(createParser(mappings)).mapping());
}

private ImmutableOpenMap<String, Settings> mockSettings(String indexName, Settings settings) {
ImmutableOpenMap.Builder<String, Settings> indexToSettingsBuilder = ImmutableOpenMap.builder();
indexToSettingsBuilder.put(indexName, settings);
return indexToSettingsBuilder.build();
private Map<String, Settings> mockSettings(String indexName, Settings settings) {
return Map.of(indexName, settings);
}

private XContentParser createParser(String mappings) throws IOException {
Expand Down

0 comments on commit 3fc11a4

Please sign in to comment.