From 9ee4e3ce3005309c57fa7092c542c3fa1a1d413c Mon Sep 17 00:00:00 2001 From: MaxKsyunz Date: Wed, 26 Apr 2023 22:43:38 -0700 Subject: [PATCH 1/2] Keep up with refactoring in OpenSearch. Signed-off-by: MaxKsyunz --- .../executor/GetIndexRequestRestListener.java | 4 ---- .../sql/legacy/util/CheckScriptContents.java | 2 -- .../opensearch/client/OpenSearchNodeClient.java | 8 ++++---- .../opensearch/client/OpenSearchRestClient.java | 17 ++++++++--------- .../client/OpenSearchNodeClientTest.java | 7 ++----- .../client/OpenSearchRestClientTest.java | 15 ++++++--------- 6 files changed, 20 insertions(+), 33 deletions(-) diff --git a/legacy/src/main/java/org/opensearch/sql/legacy/executor/GetIndexRequestRestListener.java b/legacy/src/main/java/org/opensearch/sql/legacy/executor/GetIndexRequestRestListener.java index ebd9648d5e..1adb0e745e 100644 --- a/legacy/src/main/java/org/opensearch/sql/legacy/executor/GetIndexRequestRestListener.java +++ b/legacy/src/main/java/org/opensearch/sql/legacy/executor/GetIndexRequestRestListener.java @@ -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. diff --git a/legacy/src/test/java/org/opensearch/sql/legacy/util/CheckScriptContents.java b/legacy/src/test/java/org/opensearch/sql/legacy/util/CheckScriptContents.java index 44baa8050b..595b6987a7 100644 --- a/legacy/src/test/java/org/opensearch/sql/legacy/util/CheckScriptContents.java +++ b/legacy/src/test/java/org/opensearch/sql/legacy/util/CheckScriptContents.java @@ -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; diff --git a/opensearch/src/main/java/org/opensearch/sql/opensearch/client/OpenSearchNodeClient.java b/opensearch/src/main/java/org/opensearch/sql/opensearch/client/OpenSearchNodeClient.java index 1c1498feb5..b26680b3ba 100644 --- a/opensearch/src/main/java/org/opensearch/sql/opensearch/client/OpenSearchNodeClient.java +++ b/opensearch/src/main/java/org/opensearch/sql/opensearch/client/OpenSearchNodeClient.java @@ -112,11 +112,11 @@ public Map getIndexMaxResultWindows(String... indexExpression) GetSettingsResponse settingsResponse = client.admin().indices().prepareGetSettings(indexExpression).setLocal(true).get(); ImmutableMap.Builder result = ImmutableMap.builder(); - for (ObjectObjectCursor indexToSetting : - settingsResponse.getIndexToSettings()) { - Settings settings = indexToSetting.value; + for (Map.Entry 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))); diff --git a/opensearch/src/main/java/org/opensearch/sql/opensearch/client/OpenSearchRestClient.java b/opensearch/src/main/java/org/opensearch/sql/opensearch/client/OpenSearchRestClient.java index d9f9dbbe5d..66cc067541 100644 --- a/opensearch/src/main/java/org/opensearch/sql/opensearch/client/OpenSearchRestClient.java +++ b/opensearch/src/main/java/org/opensearch/sql/opensearch/client/OpenSearchRestClient.java @@ -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 getIndexMaxResultWindows(String... indexExpression) .indices(indexExpression).includeDefaults(true); try { GetSettingsResponse response = client.indices().getSettings(request, RequestOptions.DEFAULT); - ImmutableOpenMap settings = response.getIndexToSettings(); - ImmutableOpenMap defaultSettings = response.getIndexToDefaultSettings(); + Map settings = response.getIndexToSettings(); + Map defaultSettings = response.getIndexToDefaultSettings(); Map 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); } }); diff --git a/opensearch/src/test/java/org/opensearch/sql/opensearch/client/OpenSearchNodeClientTest.java b/opensearch/src/test/java/org/opensearch/sql/opensearch/client/OpenSearchNodeClientTest.java index 352635bfc3..64330c733b 100644 --- a/opensearch/src/test/java/org/opensearch/sql/opensearch/client/OpenSearchNodeClientTest.java +++ b/opensearch/src/test/java/org/opensearch/sql/opensearch/client/OpenSearchNodeClientTest.java @@ -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 metadata = - new ImmutableOpenMap.Builder() - .fPut(indexName, IndexMetadata.fromXContent(createParser(indexMetadata)).getSettings()) - .build(); + Map metadata =Map.of(indexName, + IndexMetadata.fromXContent(createParser(indexMetadata)).getSettings()); when(mockResponse.getIndexToSettings()).thenReturn(metadata); } diff --git a/opensearch/src/test/java/org/opensearch/sql/opensearch/client/OpenSearchRestClientTest.java b/opensearch/src/test/java/org/opensearch/sql/opensearch/client/OpenSearchRestClientTest.java index dd5bfd4e6f..141e21c38a 100644 --- a/opensearch/src/test/java/org/opensearch/sql/opensearch/client/OpenSearchRestClientTest.java +++ b/opensearch/src/test/java/org/opensearch/sql/opensearch/client/OpenSearchRestClientTest.java @@ -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 indexToSettings = + Map indexToSettings = mockSettings(indexName, maxResultWindowSettings); - ImmutableOpenMap indexToDefaultSettings = + Map 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 indexToSettings = + Map indexToSettings = mockSettings(indexName, emptySettings); - ImmutableOpenMap indexToDefaultSettings = + Map indexToDefaultSettings = mockSettings(indexName, maxResultWindowSettings); when(response.getIndexToSettings()).thenReturn(indexToSettings); when(response.getIndexToDefaultSettings()).thenReturn(indexToDefaultSettings); @@ -427,10 +426,8 @@ private Map mockFieldMappings(String indexName, String return ImmutableMap.of(indexName, IndexMetadata.fromXContent(createParser(mappings)).mapping()); } - private ImmutableOpenMap mockSettings(String indexName, Settings settings) { - ImmutableOpenMap.Builder indexToSettingsBuilder = ImmutableOpenMap.builder(); - indexToSettingsBuilder.put(indexName, settings); - return indexToSettingsBuilder.build(); + private Map mockSettings(String indexName, Settings settings) { + return Map.of(indexName, settings); } private XContentParser createParser(String mappings) throws IOException { From 3f35d906806214b5fb57e248b2f39ee0a8d5226a Mon Sep 17 00:00:00 2001 From: MaxKsyunz Date: Thu, 27 Apr 2023 09:24:31 -0700 Subject: [PATCH 2/2] Updating code formatting. Signed-off-by: MaxKsyunz --- .../sql/opensearch/client/OpenSearchNodeClientTest.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/opensearch/src/test/java/org/opensearch/sql/opensearch/client/OpenSearchNodeClientTest.java b/opensearch/src/test/java/org/opensearch/sql/opensearch/client/OpenSearchNodeClientTest.java index 64330c733b..8af9a4bbfa 100644 --- a/opensearch/src/test/java/org/opensearch/sql/opensearch/client/OpenSearchNodeClientTest.java +++ b/opensearch/src/test/java/org/opensearch/sql/opensearch/client/OpenSearchNodeClientTest.java @@ -424,8 +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); - Map metadata =Map.of(indexName, - IndexMetadata.fromXContent(createParser(indexMetadata)).getSettings()); + Map metadata = Map.of(indexName, + IndexMetadata.fromXContent(createParser(indexMetadata)).getSettings()); when(mockResponse.getIndexToSettings()).thenReturn(metadata); }