From 809e6567e77e5f47a93f3475e4badb7e3053b88c Mon Sep 17 00:00:00 2001 From: Yury-Fridlyand Date: Fri, 28 Jul 2023 17:36:20 -0700 Subject: [PATCH] Fix breaking changes. Disable some flaky tests in legacy. Signed-off-by: Yury-Fridlyand --- .../org/opensearch/sql/legacy/DateFunctionsIT.java | 8 ++++---- .../org/opensearch/sql/legacy/JSONRequestIT.java | 8 ++++---- .../org/opensearch/sql/legacy/MathFunctionsIT.java | 8 ++++---- .../opensearch/sql/legacy/NestedFieldQueryIT.java | 8 ++++---- .../org/opensearch/sql/legacy/QueryFunctionsIT.java | 8 ++++---- .../org/opensearch/sql/legacy/SQLFunctionsIT.java | 9 ++++----- .../org/opensearch/sql/legacy/SourceFieldIT.java | 8 ++++---- .../java/org/opensearch/sql/sql/ConditionalIT.java | 8 ++++---- .../sql/legacy/executor/join/ElasticUtils.java | 5 ++--- .../sql/legacy/query/join/JoinRequestBuilder.java | 5 ++--- .../query/join/NestedLoopsElasticRequestBuilder.java | 3 +-- .../legacy/query/multi/MultiQueryRequestBuilder.java | 4 ++-- .../opensearch/sql/legacy/request/SqlRequest.java | 12 ++++++------ .../sql/legacy/utils/JsonPrettyFormatter.java | 9 ++++++--- .../opensearch/sql/legacy/util/AggregationUtils.java | 12 ++++++------ .../opensearch/client/OpenSearchRestClientTest.java | 7 ------- .../response/AggregationResponseUtils.java | 12 ++++++------ .../dsl/BucketAggregationBuilderTest.java | 8 +------- .../sql/plugin/rest/RestQuerySettingsAction.java | 3 +-- 19 files changed, 65 insertions(+), 80 deletions(-) diff --git a/integ-test/src/test/java/org/opensearch/sql/legacy/DateFunctionsIT.java b/integ-test/src/test/java/org/opensearch/sql/legacy/DateFunctionsIT.java index c4f5a4a351..369984d0a3 100644 --- a/integ-test/src/test/java/org/opensearch/sql/legacy/DateFunctionsIT.java +++ b/integ-test/src/test/java/org/opensearch/sql/legacy/DateFunctionsIT.java @@ -11,6 +11,7 @@ import static org.hamcrest.Matchers.lessThan; import static org.hamcrest.Matchers.matchesPattern; +import com.fasterxml.jackson.core.JsonFactory; import java.io.IOException; import java.time.Month; import org.joda.time.DateTime; @@ -20,8 +21,7 @@ import org.junit.Test; import org.opensearch.action.search.SearchResponse; import org.opensearch.common.xcontent.LoggingDeprecationHandler; -import org.opensearch.common.xcontent.XContentFactory; -import org.opensearch.common.xcontent.XContentType; +import org.opensearch.common.xcontent.json.JsonXContentParser; import org.opensearch.core.xcontent.NamedXContentRegistry; import org.opensearch.core.xcontent.XContentParser; import org.opensearch.search.SearchHit; @@ -288,10 +288,10 @@ private SearchHit[] query(String select, String... statements) throws IOExceptio private SearchHit[] execute(String sqlRequest) throws IOException { final JSONObject jsonObject = executeRequest(makeRequest(sqlRequest)); - final XContentParser parser = XContentFactory.xContent(XContentType.JSON).createParser( + final XContentParser parser = new JsonXContentParser( NamedXContentRegistry.EMPTY, LoggingDeprecationHandler.INSTANCE, - jsonObject.toString()); + new JsonFactory().createParser(jsonObject.toString())); return SearchResponse.fromXContent(parser).getHits().getHits(); } diff --git a/integ-test/src/test/java/org/opensearch/sql/legacy/JSONRequestIT.java b/integ-test/src/test/java/org/opensearch/sql/legacy/JSONRequestIT.java index ec5972be78..dcc90a9acf 100644 --- a/integ-test/src/test/java/org/opensearch/sql/legacy/JSONRequestIT.java +++ b/integ-test/src/test/java/org/opensearch/sql/legacy/JSONRequestIT.java @@ -11,16 +11,16 @@ import static org.hamcrest.Matchers.greaterThan; import static org.hamcrest.Matchers.lessThan; +import com.fasterxml.jackson.core.JsonFactory; import java.io.IOException; import java.util.Map; import org.json.JSONObject; import org.junit.Test; import org.opensearch.action.search.SearchResponse; import org.opensearch.common.xcontent.LoggingDeprecationHandler; -import org.opensearch.common.xcontent.XContentFactory; +import org.opensearch.common.xcontent.json.JsonXContentParser; import org.opensearch.core.xcontent.NamedXContentRegistry; import org.opensearch.core.xcontent.XContentParser; -import org.opensearch.common.xcontent.XContentType; import org.opensearch.search.SearchHit; import org.opensearch.search.SearchHits; @@ -184,10 +184,10 @@ public void searchWithNestedFilter() throws IOException { private SearchHits query(String request) throws IOException { final JSONObject jsonObject = executeRequest(request); - final XContentParser parser = XContentFactory.xContent(XContentType.JSON).createParser( + final XContentParser parser = new JsonXContentParser( NamedXContentRegistry.EMPTY, LoggingDeprecationHandler.INSTANCE, - jsonObject.toString()); + new JsonFactory().createParser(jsonObject.toString())); return SearchResponse.fromXContent(parser).getHits(); } } diff --git a/integ-test/src/test/java/org/opensearch/sql/legacy/MathFunctionsIT.java b/integ-test/src/test/java/org/opensearch/sql/legacy/MathFunctionsIT.java index 3a3094010d..b42819bdf7 100644 --- a/integ-test/src/test/java/org/opensearch/sql/legacy/MathFunctionsIT.java +++ b/integ-test/src/test/java/org/opensearch/sql/legacy/MathFunctionsIT.java @@ -11,12 +11,12 @@ import static org.hamcrest.Matchers.equalTo; import static org.hamcrest.Matchers.greaterThanOrEqualTo; +import com.fasterxml.jackson.core.JsonFactory; import java.io.IOException; import org.junit.Test; import org.opensearch.action.search.SearchResponse; import org.opensearch.common.xcontent.LoggingDeprecationHandler; -import org.opensearch.common.xcontent.XContentFactory; -import org.opensearch.common.xcontent.XContentType; +import org.opensearch.common.xcontent.json.JsonXContentParser; import org.opensearch.core.xcontent.NamedXContentRegistry; import org.opensearch.core.xcontent.XContentParser; import org.opensearch.search.SearchHit; @@ -238,10 +238,10 @@ private SearchHit[] query(String select, String... statements) throws IOExceptio final String response = executeQueryWithStringOutput(select + " " + FROM + " " + String.join(" ", statements)); - final XContentParser parser = XContentFactory.xContent(XContentType.JSON).createParser( + final XContentParser parser = new JsonXContentParser( NamedXContentRegistry.EMPTY, LoggingDeprecationHandler.INSTANCE, - response); + new JsonFactory().createParser(response)); return SearchResponse.fromXContent(parser).getHits().getHits(); } diff --git a/integ-test/src/test/java/org/opensearch/sql/legacy/NestedFieldQueryIT.java b/integ-test/src/test/java/org/opensearch/sql/legacy/NestedFieldQueryIT.java index 85b5aab4fe..e568be0ae6 100644 --- a/integ-test/src/test/java/org/opensearch/sql/legacy/NestedFieldQueryIT.java +++ b/integ-test/src/test/java/org/opensearch/sql/legacy/NestedFieldQueryIT.java @@ -15,6 +15,7 @@ import static org.opensearch.sql.util.MatcherUtils.hitAll; import static org.opensearch.sql.util.MatcherUtils.kvString; +import com.fasterxml.jackson.core.JsonFactory; import java.io.IOException; import java.math.BigDecimal; import java.util.ArrayList; @@ -32,8 +33,7 @@ import org.opensearch.action.search.SearchResponse; import org.opensearch.client.ResponseException; import org.opensearch.common.xcontent.LoggingDeprecationHandler; -import org.opensearch.common.xcontent.XContentFactory; -import org.opensearch.common.xcontent.XContentType; +import org.opensearch.common.xcontent.json.JsonXContentParser; import org.opensearch.core.xcontent.NamedXContentRegistry; import org.opensearch.core.xcontent.XContentParser; import org.opensearch.core.rest.RestStatus; @@ -889,10 +889,10 @@ private SearchResponse query(String select, String... statements) throws IOExcep private SearchResponse execute(String sql) throws IOException { final JSONObject jsonObject = executeQuery(sql); - final XContentParser parser = XContentFactory.xContent(XContentType.JSON).createParser( + final XContentParser parser = new JsonXContentParser( NamedXContentRegistry.EMPTY, LoggingDeprecationHandler.INSTANCE, - jsonObject.toString()); + new JsonFactory().createParser(jsonObject.toString())); return SearchResponse.fromXContent(parser); } diff --git a/integ-test/src/test/java/org/opensearch/sql/legacy/QueryFunctionsIT.java b/integ-test/src/test/java/org/opensearch/sql/legacy/QueryFunctionsIT.java index c59974a622..c538db830f 100644 --- a/integ-test/src/test/java/org/opensearch/sql/legacy/QueryFunctionsIT.java +++ b/integ-test/src/test/java/org/opensearch/sql/legacy/QueryFunctionsIT.java @@ -14,6 +14,7 @@ import static org.opensearch.sql.legacy.TestsConstants.TEST_INDEX_NESTED_TYPE; import static org.opensearch.sql.legacy.TestsConstants.TEST_INDEX_PHRASE; +import com.fasterxml.jackson.core.JsonFactory; import java.io.IOException; import java.util.Arrays; import java.util.HashMap; @@ -29,8 +30,7 @@ import org.junit.Test; import org.opensearch.action.search.SearchResponse; import org.opensearch.common.xcontent.LoggingDeprecationHandler; -import org.opensearch.common.xcontent.XContentFactory; -import org.opensearch.common.xcontent.XContentType; +import org.opensearch.common.xcontent.json.JsonXContentParser; import org.opensearch.core.xcontent.NamedXContentRegistry; import org.opensearch.core.xcontent.XContentParser; import org.opensearch.search.SearchHit; @@ -286,10 +286,10 @@ private SearchResponse query(String select, String from, String... statements) private SearchResponse execute(String sql) throws IOException { final JSONObject jsonObject = executeQuery(sql); - final XContentParser parser = XContentFactory.xContent(XContentType.JSON).createParser( + final XContentParser parser = new JsonXContentParser( NamedXContentRegistry.EMPTY, LoggingDeprecationHandler.INSTANCE, - jsonObject.toString()); + new JsonFactory().createParser(jsonObject.toString())); return SearchResponse.fromXContent(parser); } } diff --git a/integ-test/src/test/java/org/opensearch/sql/legacy/SQLFunctionsIT.java b/integ-test/src/test/java/org/opensearch/sql/legacy/SQLFunctionsIT.java index dd7e5ae64c..c1c1a26f4a 100644 --- a/integ-test/src/test/java/org/opensearch/sql/legacy/SQLFunctionsIT.java +++ b/integ-test/src/test/java/org/opensearch/sql/legacy/SQLFunctionsIT.java @@ -28,19 +28,18 @@ import static org.opensearch.sql.util.MatcherUtils.verifyDataRows; import static org.opensearch.sql.util.MatcherUtils.verifySchema; +import com.fasterxml.jackson.core.JsonFactory; import java.io.IOException; import java.util.Date; import java.util.stream.IntStream; import org.hamcrest.collection.IsMapContaining; import org.json.JSONObject; import org.junit.Assert; -import org.junit.Assume; import org.junit.Ignore; import org.junit.Test; import org.opensearch.action.search.SearchResponse; import org.opensearch.common.xcontent.LoggingDeprecationHandler; -import org.opensearch.common.xcontent.XContentFactory; -import org.opensearch.common.xcontent.XContentType; +import org.opensearch.common.xcontent.json.JsonXContentParser; import org.opensearch.core.xcontent.NamedXContentRegistry; import org.opensearch.core.xcontent.XContentParser; import org.opensearch.search.SearchHit; @@ -864,10 +863,10 @@ public void literalMultiField() throws Exception { private SearchHits query(String query) throws IOException { final String rsp = executeQueryWithStringOutput(query); - final XContentParser parser = XContentFactory.xContent(XContentType.JSON).createParser( + final XContentParser parser = new JsonXContentParser( NamedXContentRegistry.EMPTY, LoggingDeprecationHandler.INSTANCE, - rsp); + new JsonFactory().createParser(rsp)); return SearchResponse.fromXContent(parser).getHits(); } diff --git a/integ-test/src/test/java/org/opensearch/sql/legacy/SourceFieldIT.java b/integ-test/src/test/java/org/opensearch/sql/legacy/SourceFieldIT.java index 756cbcd064..a6a1a1cfe9 100644 --- a/integ-test/src/test/java/org/opensearch/sql/legacy/SourceFieldIT.java +++ b/integ-test/src/test/java/org/opensearch/sql/legacy/SourceFieldIT.java @@ -8,6 +8,7 @@ import static org.opensearch.sql.legacy.TestsConstants.TEST_INDEX_ACCOUNT; +import com.fasterxml.jackson.core.JsonFactory; import java.io.IOException; import java.util.Set; import org.json.JSONObject; @@ -15,10 +16,9 @@ import org.junit.Test; import org.opensearch.action.search.SearchResponse; import org.opensearch.common.xcontent.LoggingDeprecationHandler; -import org.opensearch.common.xcontent.XContentFactory; +import org.opensearch.common.xcontent.json.JsonXContentParser; import org.opensearch.core.xcontent.NamedXContentRegistry; import org.opensearch.core.xcontent.XContentParser; -import org.opensearch.common.xcontent.XContentType; import org.opensearch.search.SearchHit; import org.opensearch.search.SearchHits; @@ -81,10 +81,10 @@ public void allTest() throws IOException { private SearchHits query(String query) throws IOException { final JSONObject jsonObject = executeQuery(query); - final XContentParser parser = XContentFactory.xContent(XContentType.JSON).createParser( + final XContentParser parser = new JsonXContentParser( NamedXContentRegistry.EMPTY, LoggingDeprecationHandler.INSTANCE, - jsonObject.toString()); + new JsonFactory().createParser(jsonObject.toString())); return SearchResponse.fromXContent(parser).getHits(); } diff --git a/integ-test/src/test/java/org/opensearch/sql/sql/ConditionalIT.java b/integ-test/src/test/java/org/opensearch/sql/sql/ConditionalIT.java index 9a833e0aa1..ab0900784d 100644 --- a/integ-test/src/test/java/org/opensearch/sql/sql/ConditionalIT.java +++ b/integ-test/src/test/java/org/opensearch/sql/sql/ConditionalIT.java @@ -19,13 +19,13 @@ import static org.opensearch.sql.util.MatcherUtils.verifyDataRows; import static org.opensearch.sql.util.MatcherUtils.verifySchema; +import com.fasterxml.jackson.core.JsonFactory; import java.io.IOException; import org.json.JSONObject; import org.junit.Test; import org.opensearch.action.search.SearchResponse; import org.opensearch.common.xcontent.LoggingDeprecationHandler; -import org.opensearch.common.xcontent.XContentFactory; -import org.opensearch.common.xcontent.XContentType; +import org.opensearch.common.xcontent.json.JsonXContentParser; import org.opensearch.core.xcontent.NamedXContentRegistry; import org.opensearch.core.xcontent.XContentParser; import org.opensearch.search.SearchHits; @@ -212,10 +212,10 @@ public void ifWithTrueAndFalseCondition() throws IOException { private SearchHits query(String query) throws IOException { final String rsp = executeQueryWithStringOutput(query); - final XContentParser parser = XContentFactory.xContent(XContentType.JSON).createParser( + final XContentParser parser = new JsonXContentParser( NamedXContentRegistry.EMPTY, LoggingDeprecationHandler.INSTANCE, - rsp); + new JsonFactory().createParser(rsp)); return SearchResponse.fromXContent(parser).getHits(); } } diff --git a/legacy/src/main/java/org/opensearch/sql/legacy/executor/join/ElasticUtils.java b/legacy/src/main/java/org/opensearch/sql/legacy/executor/join/ElasticUtils.java index 6e42687fa5..aa6ea05389 100644 --- a/legacy/src/main/java/org/opensearch/sql/legacy/executor/join/ElasticUtils.java +++ b/legacy/src/main/java/org/opensearch/sql/legacy/executor/join/ElasticUtils.java @@ -21,7 +21,6 @@ import org.opensearch.common.io.stream.BytesStreamOutput; import org.opensearch.common.unit.TimeValue; import org.opensearch.common.xcontent.XContentFactory; -import org.opensearch.common.xcontent.XContentType; import org.opensearch.core.xcontent.ToXContent.Params; import org.opensearch.core.xcontent.XContentBuilder; import org.opensearch.search.SearchHit; @@ -78,7 +77,7 @@ public static String hitsAsStringResult(SearchHits results, MetaSearchResult met )); hits.put("max_score", results.getMaxScore()); hits.put("hits", searchHits); - XContentBuilder builder = XContentFactory.contentBuilder(XContentType.JSON).prettyPrint(); + XContentBuilder builder = XContentFactory.jsonBuilder().prettyPrint(); builder.startObject(); builder.field("took", metaResults.getTookImMilli()); builder.field("timed_out", metaResults.isTimedOut()); @@ -97,7 +96,7 @@ public static XContentBuilder hitsAsStringResultZeroCopy(List results ElasticJoinExecutor executor) throws IOException { BytesStreamOutput outputStream = new BytesStreamOutput(); - XContentBuilder builder = XContentFactory.contentBuilder(XContentType.JSON, outputStream).prettyPrint(); + XContentBuilder builder = XContentFactory.jsonBuilder(outputStream).prettyPrint(); builder.startObject(); builder.field("took", metaResults.getTookImMilli()); builder.field("timed_out", metaResults.isTimedOut()); diff --git a/legacy/src/main/java/org/opensearch/sql/legacy/query/join/JoinRequestBuilder.java b/legacy/src/main/java/org/opensearch/sql/legacy/query/join/JoinRequestBuilder.java index 622bd5a75b..c7b28d8a0a 100644 --- a/legacy/src/main/java/org/opensearch/sql/legacy/query/join/JoinRequestBuilder.java +++ b/legacy/src/main/java/org/opensearch/sql/legacy/query/join/JoinRequestBuilder.java @@ -14,7 +14,6 @@ import org.opensearch.action.search.MultiSearchRequest; import org.opensearch.core.common.bytes.BytesReference; import org.opensearch.common.xcontent.XContentFactory; -import org.opensearch.common.xcontent.XContentType; import org.opensearch.core.xcontent.ToXContent; import org.opensearch.core.xcontent.XContentBuilder; import org.opensearch.sql.legacy.query.SqlElasticRequestBuilder; @@ -54,10 +53,10 @@ private void buildMulti() { @Override public String explain() { try { - XContentBuilder firstBuilder = XContentFactory.contentBuilder(XContentType.JSON).prettyPrint(); + XContentBuilder firstBuilder = XContentFactory.jsonBuilder().prettyPrint(); firstTable.getRequestBuilder().request().source().toXContent(firstBuilder, ToXContent.EMPTY_PARAMS); - XContentBuilder secondBuilder = XContentFactory.contentBuilder(XContentType.JSON).prettyPrint(); + XContentBuilder secondBuilder = XContentFactory.jsonBuilder().prettyPrint(); secondTable.getRequestBuilder().request().source().toXContent(secondBuilder, ToXContent.EMPTY_PARAMS); return String.format(" first query:\n%s\n second query:\n%s", BytesReference.bytes(firstBuilder).utf8ToString(), diff --git a/legacy/src/main/java/org/opensearch/sql/legacy/query/join/NestedLoopsElasticRequestBuilder.java b/legacy/src/main/java/org/opensearch/sql/legacy/query/join/NestedLoopsElasticRequestBuilder.java index f89a7eb8e1..899e0f5e1d 100644 --- a/legacy/src/main/java/org/opensearch/sql/legacy/query/join/NestedLoopsElasticRequestBuilder.java +++ b/legacy/src/main/java/org/opensearch/sql/legacy/query/join/NestedLoopsElasticRequestBuilder.java @@ -12,7 +12,6 @@ import org.json.JSONStringer; import org.opensearch.core.common.bytes.BytesReference; import org.opensearch.common.xcontent.XContentFactory; -import org.opensearch.common.xcontent.XContentType; import org.opensearch.core.xcontent.ToXContent; import org.opensearch.core.xcontent.XContentBuilder; import org.opensearch.sql.legacy.domain.Condition; @@ -95,7 +94,7 @@ private String[] explainNL() { private String explainQuery(TableInJoinRequestBuilder requestBuilder) { try { - XContentBuilder xContentBuilder = XContentFactory.contentBuilder(XContentType.JSON).prettyPrint(); + XContentBuilder xContentBuilder = XContentFactory.jsonBuilder().prettyPrint(); requestBuilder.getRequestBuilder().request().source().toXContent(xContentBuilder, ToXContent.EMPTY_PARAMS); return BytesReference.bytes(xContentBuilder).utf8ToString(); } catch (IOException e) { diff --git a/legacy/src/main/java/org/opensearch/sql/legacy/query/multi/MultiQueryRequestBuilder.java b/legacy/src/main/java/org/opensearch/sql/legacy/query/multi/MultiQueryRequestBuilder.java index c9c53acf1f..b356377d5d 100644 --- a/legacy/src/main/java/org/opensearch/sql/legacy/query/multi/MultiQueryRequestBuilder.java +++ b/legacy/src/main/java/org/opensearch/sql/legacy/query/multi/MultiQueryRequestBuilder.java @@ -54,10 +54,10 @@ public ActionRequest request() { public String explain() { try { - XContentBuilder firstBuilder = XContentFactory.contentBuilder(XContentType.JSON).prettyPrint(); + XContentBuilder firstBuilder = XContentFactory.jsonBuilder().prettyPrint(); this.firstSearchRequest.request().source().toXContent(firstBuilder, ToXContent.EMPTY_PARAMS); - XContentBuilder secondBuilder = XContentFactory.contentBuilder(XContentType.JSON).prettyPrint(); + XContentBuilder secondBuilder = XContentFactory.jsonBuilder().prettyPrint(); this.secondSearchRequest.request().source().toXContent(secondBuilder, ToXContent.EMPTY_PARAMS); return String.format("performing %s on :\n left query:\n%s\n right query:\n%s", this.relation.name, BytesReference.bytes(firstBuilder).utf8ToString(), diff --git a/legacy/src/main/java/org/opensearch/sql/legacy/request/SqlRequest.java b/legacy/src/main/java/org/opensearch/sql/legacy/request/SqlRequest.java index 605ef3c958..8ac66e4b70 100644 --- a/legacy/src/main/java/org/opensearch/sql/legacy/request/SqlRequest.java +++ b/legacy/src/main/java/org/opensearch/sql/legacy/request/SqlRequest.java @@ -6,14 +6,14 @@ package org.opensearch.sql.legacy.request; +import com.fasterxml.jackson.core.JsonFactory; import java.io.IOException; import java.util.Collections; import org.json.JSONException; import org.json.JSONObject; import org.opensearch.common.settings.Settings; import org.opensearch.common.xcontent.LoggingDeprecationHandler; -import org.opensearch.common.xcontent.XContentFactory; -import org.opensearch.common.xcontent.XContentType; +import org.opensearch.common.xcontent.json.JsonXContentParser; import org.opensearch.core.xcontent.NamedXContentRegistry; import org.opensearch.core.xcontent.XContentParser; import org.opensearch.index.query.BoolQueryBuilder; @@ -90,10 +90,10 @@ private void addFilterFromJson(BoolQueryBuilder boolQuery) throws SqlParseExcept try { String filter = getFilterObjectAsString(jsonContent); SearchModule searchModule = new SearchModule(Settings.EMPTY, Collections.emptyList()); - XContentParser parser = XContentFactory.xContent(XContentType.JSON). - createParser(new NamedXContentRegistry(searchModule.getNamedXContents()), - LoggingDeprecationHandler.INSTANCE, - filter); + XContentParser parser = new JsonXContentParser( + new NamedXContentRegistry(searchModule.getNamedXContents()), + LoggingDeprecationHandler.INSTANCE, + new JsonFactory().createParser(filter)); // nextToken is called before passing the parser to fromXContent since the fieldName will be null if the // first token it parses is START_OBJECT resulting in an exception diff --git a/legacy/src/main/java/org/opensearch/sql/legacy/utils/JsonPrettyFormatter.java b/legacy/src/main/java/org/opensearch/sql/legacy/utils/JsonPrettyFormatter.java index 24cc47b0c0..827f968bde 100644 --- a/legacy/src/main/java/org/opensearch/sql/legacy/utils/JsonPrettyFormatter.java +++ b/legacy/src/main/java/org/opensearch/sql/legacy/utils/JsonPrettyFormatter.java @@ -6,11 +6,12 @@ package org.opensearch.sql.legacy.utils; +import com.fasterxml.jackson.core.JsonFactory; import java.io.IOException; import org.opensearch.common.Strings; import org.opensearch.common.xcontent.LoggingDeprecationHandler; import org.opensearch.common.xcontent.XContentFactory; -import org.opensearch.common.xcontent.XContentType; +import org.opensearch.common.xcontent.json.JsonXContentParser; import org.opensearch.core.xcontent.NamedXContentRegistry; import org.opensearch.core.xcontent.XContentBuilder; import org.opensearch.core.xcontent.XContentParser; @@ -29,8 +30,10 @@ public static String format(String jsonString) throws IOException { //turn _explain response into pretty formatted Json XContentBuilder contentBuilder = XContentFactory.jsonBuilder().prettyPrint(); try ( - XContentParser contentParser = XContentFactory.xContent(XContentType.JSON) - .createParser(NamedXContentRegistry.EMPTY, LoggingDeprecationHandler.INSTANCE, jsonString) + XContentParser contentParser = new JsonXContentParser( + NamedXContentRegistry.EMPTY, + LoggingDeprecationHandler.INSTANCE, + new JsonFactory().createParser(jsonString)) ){ contentBuilder.copyCurrentStructure(contentParser); } diff --git a/legacy/src/test/java/org/opensearch/sql/legacy/util/AggregationUtils.java b/legacy/src/test/java/org/opensearch/sql/legacy/util/AggregationUtils.java index 13a833120c..58fa8793ff 100644 --- a/legacy/src/test/java/org/opensearch/sql/legacy/util/AggregationUtils.java +++ b/legacy/src/test/java/org/opensearch/sql/legacy/util/AggregationUtils.java @@ -6,17 +6,16 @@ package org.opensearch.sql.legacy.util; +import com.fasterxml.jackson.core.JsonFactory; import com.google.common.collect.ImmutableMap; import java.io.IOException; import java.util.List; import java.util.stream.Collectors; import org.opensearch.common.xcontent.LoggingDeprecationHandler; -import org.opensearch.common.xcontent.XContentFactory; -import org.opensearch.common.xcontent.XContentType; +import org.opensearch.common.xcontent.json.JsonXContentParser; import org.opensearch.core.ParseField; import org.opensearch.core.xcontent.ContextParser; import org.opensearch.core.xcontent.NamedXContentRegistry; -import org.opensearch.core.xcontent.XContent; import org.opensearch.core.xcontent.XContentParser; import org.opensearch.search.aggregations.Aggregation; import org.opensearch.search.aggregations.Aggregations; @@ -62,7 +61,6 @@ public class AggregationUtils { entry.getValue())) .collect(Collectors.toList()); private final static NamedXContentRegistry namedXContentRegistry = new NamedXContentRegistry(entryList); - private final static XContent xContent = XContentFactory.xContent(XContentType.JSON); /** * Populate {@link Aggregations} from JSON string. @@ -71,8 +69,10 @@ public class AggregationUtils { */ public static Aggregations fromJson(String json) { try { - XContentParser xContentParser = - xContent.createParser(namedXContentRegistry, LoggingDeprecationHandler.INSTANCE, json); + XContentParser xContentParser = new JsonXContentParser( + namedXContentRegistry, + LoggingDeprecationHandler.INSTANCE, + new JsonFactory().createParser(json)); xContentParser.nextToken(); return Aggregations.fromXContent(xContentParser); } catch (IOException e) { 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 7b6c07a474..7f968733c1 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 @@ -19,7 +19,6 @@ import static org.mockito.Mockito.never; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; -import static org.opensearch.core.xcontent.MediaTypeRegistry.setDefaultMediaType; import static org.opensearch.sql.opensearch.client.OpenSearchClient.META_CLUSTER_NAME; import static org.opensearch.sql.opensearch.data.type.OpenSearchDataType.MappingType; @@ -35,7 +34,6 @@ import lombok.SneakyThrows; import org.apache.commons.lang3.reflect.FieldUtils; import org.apache.lucene.search.TotalHits; -import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.DisplayNameGeneration; import org.junit.jupiter.api.DisplayNameGenerator; @@ -103,11 +101,6 @@ void setUp() { client = new OpenSearchRestClient(restClient); } - @BeforeAll - static void setUpJSON() { - setDefaultMediaType(XContentType.JSON); - } - @Test void is_index_exist() throws IOException { when(restClient.indices() diff --git a/opensearch/src/test/java/org/opensearch/sql/opensearch/response/AggregationResponseUtils.java b/opensearch/src/test/java/org/opensearch/sql/opensearch/response/AggregationResponseUtils.java index 57a4f44469..bbc462e980 100644 --- a/opensearch/src/test/java/org/opensearch/sql/opensearch/response/AggregationResponseUtils.java +++ b/opensearch/src/test/java/org/opensearch/sql/opensearch/response/AggregationResponseUtils.java @@ -6,17 +6,16 @@ package org.opensearch.sql.opensearch.response; +import com.fasterxml.jackson.core.JsonFactory; import com.google.common.collect.ImmutableMap; import java.io.IOException; import java.util.List; import java.util.stream.Collectors; import org.opensearch.common.xcontent.LoggingDeprecationHandler; -import org.opensearch.common.xcontent.XContentFactory; -import org.opensearch.common.xcontent.XContentType; +import org.opensearch.common.xcontent.json.JsonXContentParser; import org.opensearch.core.ParseField; import org.opensearch.core.xcontent.ContextParser; import org.opensearch.core.xcontent.NamedXContentRegistry; -import org.opensearch.core.xcontent.XContent; import org.opensearch.core.xcontent.XContentParser; import org.opensearch.search.aggregations.Aggregation; import org.opensearch.search.aggregations.Aggregations; @@ -86,7 +85,6 @@ public class AggregationResponseUtils { .collect(Collectors.toList()); private static final NamedXContentRegistry namedXContentRegistry = new NamedXContentRegistry(entryList); - private static final XContent xContent = XContentFactory.xContent(XContentType.JSON); /** * Populate {@link Aggregations} from JSON string. @@ -96,8 +94,10 @@ public class AggregationResponseUtils { */ public static Aggregations fromJson(String json) { try { - XContentParser contentParser = - xContent.createParser(namedXContentRegistry, LoggingDeprecationHandler.INSTANCE, json); + XContentParser contentParser = new JsonXContentParser( + namedXContentRegistry, + LoggingDeprecationHandler.INSTANCE, + new JsonFactory().createParser(json)); contentParser.nextToken(); return Aggregations.fromXContent(contentParser); } catch (IOException e) { diff --git a/opensearch/src/test/java/org/opensearch/sql/opensearch/storage/script/aggregation/dsl/BucketAggregationBuilderTest.java b/opensearch/src/test/java/org/opensearch/sql/opensearch/storage/script/aggregation/dsl/BucketAggregationBuilderTest.java index 521f93f2e7..208904d9c3 100644 --- a/opensearch/src/test/java/org/opensearch/sql/opensearch/storage/script/aggregation/dsl/BucketAggregationBuilderTest.java +++ b/opensearch/src/test/java/org/opensearch/sql/opensearch/storage/script/aggregation/dsl/BucketAggregationBuilderTest.java @@ -9,12 +9,8 @@ import static org.junit.jupiter.api.Assertions.assertEquals; import static org.mockito.Mockito.when; import static org.opensearch.core.xcontent.ToXContent.EMPTY_PARAMS; -import static org.opensearch.sql.data.type.ExprCoreType.DATE; -import static org.opensearch.sql.data.type.ExprCoreType.DATETIME; import static org.opensearch.sql.data.type.ExprCoreType.INTEGER; import static org.opensearch.sql.data.type.ExprCoreType.STRING; -import static org.opensearch.sql.data.type.ExprCoreType.TIME; -import static org.opensearch.sql.data.type.ExprCoreType.TIMESTAMP; import static org.opensearch.sql.expression.DSL.literal; import static org.opensearch.sql.expression.DSL.named; import static org.opensearch.sql.expression.DSL.ref; @@ -31,11 +27,9 @@ import org.junit.jupiter.api.extension.ExtendWith; import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.EnumSource; -import org.junit.jupiter.params.provider.ValueSource; import org.mockito.Mock; import org.mockito.junit.jupiter.MockitoExtension; import org.opensearch.common.xcontent.XContentFactory; -import org.opensearch.common.xcontent.XContentType; import org.opensearch.core.common.bytes.BytesReference; import org.opensearch.core.xcontent.XContentBuilder; import org.opensearch.search.aggregations.bucket.composite.CompositeValuesSourceBuilder; @@ -161,7 +155,7 @@ void terms_bucket_for_datetime_types_uses_long(ExprType dataType) { @SneakyThrows private String buildQuery( List> groupByExpressions) { - XContentBuilder builder = XContentFactory.contentBuilder(XContentType.JSON).prettyPrint(); + XContentBuilder builder = XContentFactory.jsonBuilder().prettyPrint(); builder.startObject(); CompositeValuesSourceBuilder sourceBuilder = aggregationBuilder.build(groupByExpressions).get(0); diff --git a/plugin/src/main/java/org/opensearch/sql/plugin/rest/RestQuerySettingsAction.java b/plugin/src/main/java/org/opensearch/sql/plugin/rest/RestQuerySettingsAction.java index 9022817106..7b51b47503 100644 --- a/plugin/src/main/java/org/opensearch/sql/plugin/rest/RestQuerySettingsAction.java +++ b/plugin/src/main/java/org/opensearch/sql/plugin/rest/RestQuerySettingsAction.java @@ -20,7 +20,6 @@ import org.opensearch.common.Strings; import org.opensearch.common.settings.Settings; import org.opensearch.common.xcontent.XContentFactory; -import org.opensearch.common.xcontent.XContentType; import org.opensearch.core.xcontent.XContentBuilder; import org.opensearch.core.xcontent.XContentParser; import org.opensearch.rest.BaseRestHandler; @@ -107,7 +106,7 @@ protected RestChannelConsumer prepareRequest(RestRequest request, NodeClient cli private Settings getAndFilterSettings(Map source) { try { - XContentBuilder builder = XContentFactory.contentBuilder(XContentType.JSON); + XContentBuilder builder = XContentFactory.jsonBuilder(); builder.map(source); Settings.Builder settingsBuilder = Settings.builder() .loadFromSource(Strings.toString(builder), builder.contentType());