Skip to content

Commit

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

* Keep up with refactoring in OpenSearch.



* Updating code formatting.



---------


(cherry picked from commit 3fc11a4)

Signed-off-by: MaxKsyunz <maxk@bitquilltech.com>
Co-authored-by: Max Ksyunz <maxk@bitquilltech.com>
  • Loading branch information
opensearch-trigger-bot[bot] and Max Ksyunz authored Jul 5, 2023
1 parent 63e317b commit babbe90
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 @@ -59,7 +59,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.unit.TimeValue;
import org.opensearch.common.util.concurrent.ThreadContext;
Expand Down Expand Up @@ -453,10 +452,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 @@ -54,7 +54,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.unit.TimeValue;
import org.opensearch.common.xcontent.XContentType;
Expand Down Expand Up @@ -240,9 +239,9 @@ void get_index_max_result_windows_settings() 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 @@ -264,9 +263,9 @@ void get_index_max_result_windows_default_settings() 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 @@ -451,10 +450,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 babbe90

Please sign in to comment.