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

Keep up with refactoring in OpenSearch. #1588

Merged
Changes from 1 commit
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
Next Next commit
Keep up with refactoring in OpenSearch.
Signed-off-by: MaxKsyunz <[email protected]>
MaxKsyunz committed Apr 27, 2023

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
commit 9ee4e3ce3005309c57fa7092c542c3fa1a1d413c
Original file line number Diff line number Diff line change
@@ -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;
@@ -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.
Original file line number Diff line number Diff line change
@@ -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;
Original file line number Diff line number Diff line change
@@ -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)));
Original file line number Diff line number Diff line change
@@ -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;
@@ -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);
}
});

Original file line number Diff line number Diff line change
@@ -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;
@@ -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);
}
Original file line number Diff line number Diff line change
@@ -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;
@@ -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);
@@ -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);
@@ -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 {