Skip to content

Commit 809e656

Browse files
Fix breaking changes. Disable some flaky tests in legacy.
Signed-off-by: Yury-Fridlyand <[email protected]>
1 parent 02185c8 commit 809e656

File tree

19 files changed

+65
-80
lines changed

19 files changed

+65
-80
lines changed

integ-test/src/test/java/org/opensearch/sql/legacy/DateFunctionsIT.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
import static org.hamcrest.Matchers.lessThan;
1212
import static org.hamcrest.Matchers.matchesPattern;
1313

14+
import com.fasterxml.jackson.core.JsonFactory;
1415
import java.io.IOException;
1516
import java.time.Month;
1617
import org.joda.time.DateTime;
@@ -20,8 +21,7 @@
2021
import org.junit.Test;
2122
import org.opensearch.action.search.SearchResponse;
2223
import org.opensearch.common.xcontent.LoggingDeprecationHandler;
23-
import org.opensearch.common.xcontent.XContentFactory;
24-
import org.opensearch.common.xcontent.XContentType;
24+
import org.opensearch.common.xcontent.json.JsonXContentParser;
2525
import org.opensearch.core.xcontent.NamedXContentRegistry;
2626
import org.opensearch.core.xcontent.XContentParser;
2727
import org.opensearch.search.SearchHit;
@@ -288,10 +288,10 @@ private SearchHit[] query(String select, String... statements) throws IOExceptio
288288
private SearchHit[] execute(String sqlRequest) throws IOException {
289289
final JSONObject jsonObject = executeRequest(makeRequest(sqlRequest));
290290

291-
final XContentParser parser = XContentFactory.xContent(XContentType.JSON).createParser(
291+
final XContentParser parser = new JsonXContentParser(
292292
NamedXContentRegistry.EMPTY,
293293
LoggingDeprecationHandler.INSTANCE,
294-
jsonObject.toString());
294+
new JsonFactory().createParser(jsonObject.toString()));
295295
return SearchResponse.fromXContent(parser).getHits().getHits();
296296
}
297297

integ-test/src/test/java/org/opensearch/sql/legacy/JSONRequestIT.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,16 @@
1111
import static org.hamcrest.Matchers.greaterThan;
1212
import static org.hamcrest.Matchers.lessThan;
1313

14+
import com.fasterxml.jackson.core.JsonFactory;
1415
import java.io.IOException;
1516
import java.util.Map;
1617
import org.json.JSONObject;
1718
import org.junit.Test;
1819
import org.opensearch.action.search.SearchResponse;
1920
import org.opensearch.common.xcontent.LoggingDeprecationHandler;
20-
import org.opensearch.common.xcontent.XContentFactory;
21+
import org.opensearch.common.xcontent.json.JsonXContentParser;
2122
import org.opensearch.core.xcontent.NamedXContentRegistry;
2223
import org.opensearch.core.xcontent.XContentParser;
23-
import org.opensearch.common.xcontent.XContentType;
2424
import org.opensearch.search.SearchHit;
2525
import org.opensearch.search.SearchHits;
2626

@@ -184,10 +184,10 @@ public void searchWithNestedFilter() throws IOException {
184184
private SearchHits query(String request) throws IOException {
185185
final JSONObject jsonObject = executeRequest(request);
186186

187-
final XContentParser parser = XContentFactory.xContent(XContentType.JSON).createParser(
187+
final XContentParser parser = new JsonXContentParser(
188188
NamedXContentRegistry.EMPTY,
189189
LoggingDeprecationHandler.INSTANCE,
190-
jsonObject.toString());
190+
new JsonFactory().createParser(jsonObject.toString()));
191191
return SearchResponse.fromXContent(parser).getHits();
192192
}
193193
}

integ-test/src/test/java/org/opensearch/sql/legacy/MathFunctionsIT.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,12 @@
1111
import static org.hamcrest.Matchers.equalTo;
1212
import static org.hamcrest.Matchers.greaterThanOrEqualTo;
1313

14+
import com.fasterxml.jackson.core.JsonFactory;
1415
import java.io.IOException;
1516
import org.junit.Test;
1617
import org.opensearch.action.search.SearchResponse;
1718
import org.opensearch.common.xcontent.LoggingDeprecationHandler;
18-
import org.opensearch.common.xcontent.XContentFactory;
19-
import org.opensearch.common.xcontent.XContentType;
19+
import org.opensearch.common.xcontent.json.JsonXContentParser;
2020
import org.opensearch.core.xcontent.NamedXContentRegistry;
2121
import org.opensearch.core.xcontent.XContentParser;
2222
import org.opensearch.search.SearchHit;
@@ -238,10 +238,10 @@ private SearchHit[] query(String select, String... statements) throws IOExceptio
238238
final String response =
239239
executeQueryWithStringOutput(select + " " + FROM + " " + String.join(" ", statements));
240240

241-
final XContentParser parser = XContentFactory.xContent(XContentType.JSON).createParser(
241+
final XContentParser parser = new JsonXContentParser(
242242
NamedXContentRegistry.EMPTY,
243243
LoggingDeprecationHandler.INSTANCE,
244-
response);
244+
new JsonFactory().createParser(response));
245245
return SearchResponse.fromXContent(parser).getHits().getHits();
246246
}
247247

integ-test/src/test/java/org/opensearch/sql/legacy/NestedFieldQueryIT.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
import static org.opensearch.sql.util.MatcherUtils.hitAll;
1616
import static org.opensearch.sql.util.MatcherUtils.kvString;
1717

18+
import com.fasterxml.jackson.core.JsonFactory;
1819
import java.io.IOException;
1920
import java.math.BigDecimal;
2021
import java.util.ArrayList;
@@ -32,8 +33,7 @@
3233
import org.opensearch.action.search.SearchResponse;
3334
import org.opensearch.client.ResponseException;
3435
import org.opensearch.common.xcontent.LoggingDeprecationHandler;
35-
import org.opensearch.common.xcontent.XContentFactory;
36-
import org.opensearch.common.xcontent.XContentType;
36+
import org.opensearch.common.xcontent.json.JsonXContentParser;
3737
import org.opensearch.core.xcontent.NamedXContentRegistry;
3838
import org.opensearch.core.xcontent.XContentParser;
3939
import org.opensearch.core.rest.RestStatus;
@@ -889,10 +889,10 @@ private SearchResponse query(String select, String... statements) throws IOExcep
889889
private SearchResponse execute(String sql) throws IOException {
890890
final JSONObject jsonObject = executeQuery(sql);
891891

892-
final XContentParser parser = XContentFactory.xContent(XContentType.JSON).createParser(
892+
final XContentParser parser = new JsonXContentParser(
893893
NamedXContentRegistry.EMPTY,
894894
LoggingDeprecationHandler.INSTANCE,
895-
jsonObject.toString());
895+
new JsonFactory().createParser(jsonObject.toString()));
896896
return SearchResponse.fromXContent(parser);
897897
}
898898

integ-test/src/test/java/org/opensearch/sql/legacy/QueryFunctionsIT.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
import static org.opensearch.sql.legacy.TestsConstants.TEST_INDEX_NESTED_TYPE;
1515
import static org.opensearch.sql.legacy.TestsConstants.TEST_INDEX_PHRASE;
1616

17+
import com.fasterxml.jackson.core.JsonFactory;
1718
import java.io.IOException;
1819
import java.util.Arrays;
1920
import java.util.HashMap;
@@ -29,8 +30,7 @@
2930
import org.junit.Test;
3031
import org.opensearch.action.search.SearchResponse;
3132
import org.opensearch.common.xcontent.LoggingDeprecationHandler;
32-
import org.opensearch.common.xcontent.XContentFactory;
33-
import org.opensearch.common.xcontent.XContentType;
33+
import org.opensearch.common.xcontent.json.JsonXContentParser;
3434
import org.opensearch.core.xcontent.NamedXContentRegistry;
3535
import org.opensearch.core.xcontent.XContentParser;
3636
import org.opensearch.search.SearchHit;
@@ -286,10 +286,10 @@ private SearchResponse query(String select, String from, String... statements)
286286
private SearchResponse execute(String sql) throws IOException {
287287
final JSONObject jsonObject = executeQuery(sql);
288288

289-
final XContentParser parser = XContentFactory.xContent(XContentType.JSON).createParser(
289+
final XContentParser parser = new JsonXContentParser(
290290
NamedXContentRegistry.EMPTY,
291291
LoggingDeprecationHandler.INSTANCE,
292-
jsonObject.toString());
292+
new JsonFactory().createParser(jsonObject.toString()));
293293
return SearchResponse.fromXContent(parser);
294294
}
295295
}

integ-test/src/test/java/org/opensearch/sql/legacy/SQLFunctionsIT.java

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,19 +28,18 @@
2828
import static org.opensearch.sql.util.MatcherUtils.verifyDataRows;
2929
import static org.opensearch.sql.util.MatcherUtils.verifySchema;
3030

31+
import com.fasterxml.jackson.core.JsonFactory;
3132
import java.io.IOException;
3233
import java.util.Date;
3334
import java.util.stream.IntStream;
3435
import org.hamcrest.collection.IsMapContaining;
3536
import org.json.JSONObject;
3637
import org.junit.Assert;
37-
import org.junit.Assume;
3838
import org.junit.Ignore;
3939
import org.junit.Test;
4040
import org.opensearch.action.search.SearchResponse;
4141
import org.opensearch.common.xcontent.LoggingDeprecationHandler;
42-
import org.opensearch.common.xcontent.XContentFactory;
43-
import org.opensearch.common.xcontent.XContentType;
42+
import org.opensearch.common.xcontent.json.JsonXContentParser;
4443
import org.opensearch.core.xcontent.NamedXContentRegistry;
4544
import org.opensearch.core.xcontent.XContentParser;
4645
import org.opensearch.search.SearchHit;
@@ -864,10 +863,10 @@ public void literalMultiField() throws Exception {
864863
private SearchHits query(String query) throws IOException {
865864
final String rsp = executeQueryWithStringOutput(query);
866865

867-
final XContentParser parser = XContentFactory.xContent(XContentType.JSON).createParser(
866+
final XContentParser parser = new JsonXContentParser(
868867
NamedXContentRegistry.EMPTY,
869868
LoggingDeprecationHandler.INSTANCE,
870-
rsp);
869+
new JsonFactory().createParser(rsp));
871870
return SearchResponse.fromXContent(parser).getHits();
872871
}
873872

integ-test/src/test/java/org/opensearch/sql/legacy/SourceFieldIT.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,17 @@
88

99
import static org.opensearch.sql.legacy.TestsConstants.TEST_INDEX_ACCOUNT;
1010

11+
import com.fasterxml.jackson.core.JsonFactory;
1112
import java.io.IOException;
1213
import java.util.Set;
1314
import org.json.JSONObject;
1415
import org.junit.Assert;
1516
import org.junit.Test;
1617
import org.opensearch.action.search.SearchResponse;
1718
import org.opensearch.common.xcontent.LoggingDeprecationHandler;
18-
import org.opensearch.common.xcontent.XContentFactory;
19+
import org.opensearch.common.xcontent.json.JsonXContentParser;
1920
import org.opensearch.core.xcontent.NamedXContentRegistry;
2021
import org.opensearch.core.xcontent.XContentParser;
21-
import org.opensearch.common.xcontent.XContentType;
2222
import org.opensearch.search.SearchHit;
2323
import org.opensearch.search.SearchHits;
2424

@@ -81,10 +81,10 @@ public void allTest() throws IOException {
8181
private SearchHits query(String query) throws IOException {
8282
final JSONObject jsonObject = executeQuery(query);
8383

84-
final XContentParser parser = XContentFactory.xContent(XContentType.JSON).createParser(
84+
final XContentParser parser = new JsonXContentParser(
8585
NamedXContentRegistry.EMPTY,
8686
LoggingDeprecationHandler.INSTANCE,
87-
jsonObject.toString());
87+
new JsonFactory().createParser(jsonObject.toString()));
8888
return SearchResponse.fromXContent(parser).getHits();
8989
}
9090

integ-test/src/test/java/org/opensearch/sql/sql/ConditionalIT.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,13 @@
1919
import static org.opensearch.sql.util.MatcherUtils.verifyDataRows;
2020
import static org.opensearch.sql.util.MatcherUtils.verifySchema;
2121

22+
import com.fasterxml.jackson.core.JsonFactory;
2223
import java.io.IOException;
2324
import org.json.JSONObject;
2425
import org.junit.Test;
2526
import org.opensearch.action.search.SearchResponse;
2627
import org.opensearch.common.xcontent.LoggingDeprecationHandler;
27-
import org.opensearch.common.xcontent.XContentFactory;
28-
import org.opensearch.common.xcontent.XContentType;
28+
import org.opensearch.common.xcontent.json.JsonXContentParser;
2929
import org.opensearch.core.xcontent.NamedXContentRegistry;
3030
import org.opensearch.core.xcontent.XContentParser;
3131
import org.opensearch.search.SearchHits;
@@ -212,10 +212,10 @@ public void ifWithTrueAndFalseCondition() throws IOException {
212212
private SearchHits query(String query) throws IOException {
213213
final String rsp = executeQueryWithStringOutput(query);
214214

215-
final XContentParser parser = XContentFactory.xContent(XContentType.JSON).createParser(
215+
final XContentParser parser = new JsonXContentParser(
216216
NamedXContentRegistry.EMPTY,
217217
LoggingDeprecationHandler.INSTANCE,
218-
rsp);
218+
new JsonFactory().createParser(rsp));
219219
return SearchResponse.fromXContent(parser).getHits();
220220
}
221221
}

legacy/src/main/java/org/opensearch/sql/legacy/executor/join/ElasticUtils.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
import org.opensearch.common.io.stream.BytesStreamOutput;
2222
import org.opensearch.common.unit.TimeValue;
2323
import org.opensearch.common.xcontent.XContentFactory;
24-
import org.opensearch.common.xcontent.XContentType;
2524
import org.opensearch.core.xcontent.ToXContent.Params;
2625
import org.opensearch.core.xcontent.XContentBuilder;
2726
import org.opensearch.search.SearchHit;
@@ -78,7 +77,7 @@ public static String hitsAsStringResult(SearchHits results, MetaSearchResult met
7877
));
7978
hits.put("max_score", results.getMaxScore());
8079
hits.put("hits", searchHits);
81-
XContentBuilder builder = XContentFactory.contentBuilder(XContentType.JSON).prettyPrint();
80+
XContentBuilder builder = XContentFactory.jsonBuilder().prettyPrint();
8281
builder.startObject();
8382
builder.field("took", metaResults.getTookImMilli());
8483
builder.field("timed_out", metaResults.isTimedOut());
@@ -97,7 +96,7 @@ public static XContentBuilder hitsAsStringResultZeroCopy(List<SearchHit> results
9796
ElasticJoinExecutor executor) throws IOException {
9897
BytesStreamOutput outputStream = new BytesStreamOutput();
9998

100-
XContentBuilder builder = XContentFactory.contentBuilder(XContentType.JSON, outputStream).prettyPrint();
99+
XContentBuilder builder = XContentFactory.jsonBuilder(outputStream).prettyPrint();
101100
builder.startObject();
102101
builder.field("took", metaResults.getTookImMilli());
103102
builder.field("timed_out", metaResults.isTimedOut());

legacy/src/main/java/org/opensearch/sql/legacy/query/join/JoinRequestBuilder.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
import org.opensearch.action.search.MultiSearchRequest;
1515
import org.opensearch.core.common.bytes.BytesReference;
1616
import org.opensearch.common.xcontent.XContentFactory;
17-
import org.opensearch.common.xcontent.XContentType;
1817
import org.opensearch.core.xcontent.ToXContent;
1918
import org.opensearch.core.xcontent.XContentBuilder;
2019
import org.opensearch.sql.legacy.query.SqlElasticRequestBuilder;
@@ -54,10 +53,10 @@ private void buildMulti() {
5453
@Override
5554
public String explain() {
5655
try {
57-
XContentBuilder firstBuilder = XContentFactory.contentBuilder(XContentType.JSON).prettyPrint();
56+
XContentBuilder firstBuilder = XContentFactory.jsonBuilder().prettyPrint();
5857
firstTable.getRequestBuilder().request().source().toXContent(firstBuilder, ToXContent.EMPTY_PARAMS);
5958

60-
XContentBuilder secondBuilder = XContentFactory.contentBuilder(XContentType.JSON).prettyPrint();
59+
XContentBuilder secondBuilder = XContentFactory.jsonBuilder().prettyPrint();
6160
secondTable.getRequestBuilder().request().source().toXContent(secondBuilder, ToXContent.EMPTY_PARAMS);
6261
return String.format(" first query:\n%s\n second query:\n%s",
6362
BytesReference.bytes(firstBuilder).utf8ToString(),

legacy/src/main/java/org/opensearch/sql/legacy/query/join/NestedLoopsElasticRequestBuilder.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
import org.json.JSONStringer;
1313
import org.opensearch.core.common.bytes.BytesReference;
1414
import org.opensearch.common.xcontent.XContentFactory;
15-
import org.opensearch.common.xcontent.XContentType;
1615
import org.opensearch.core.xcontent.ToXContent;
1716
import org.opensearch.core.xcontent.XContentBuilder;
1817
import org.opensearch.sql.legacy.domain.Condition;
@@ -95,7 +94,7 @@ private String[] explainNL() {
9594

9695
private String explainQuery(TableInJoinRequestBuilder requestBuilder) {
9796
try {
98-
XContentBuilder xContentBuilder = XContentFactory.contentBuilder(XContentType.JSON).prettyPrint();
97+
XContentBuilder xContentBuilder = XContentFactory.jsonBuilder().prettyPrint();
9998
requestBuilder.getRequestBuilder().request().source().toXContent(xContentBuilder, ToXContent.EMPTY_PARAMS);
10099
return BytesReference.bytes(xContentBuilder).utf8ToString();
101100
} catch (IOException e) {

legacy/src/main/java/org/opensearch/sql/legacy/query/multi/MultiQueryRequestBuilder.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,10 +54,10 @@ public ActionRequest request() {
5454
public String explain() {
5555

5656
try {
57-
XContentBuilder firstBuilder = XContentFactory.contentBuilder(XContentType.JSON).prettyPrint();
57+
XContentBuilder firstBuilder = XContentFactory.jsonBuilder().prettyPrint();
5858
this.firstSearchRequest.request().source().toXContent(firstBuilder, ToXContent.EMPTY_PARAMS);
5959

60-
XContentBuilder secondBuilder = XContentFactory.contentBuilder(XContentType.JSON).prettyPrint();
60+
XContentBuilder secondBuilder = XContentFactory.jsonBuilder().prettyPrint();
6161
this.secondSearchRequest.request().source().toXContent(secondBuilder, ToXContent.EMPTY_PARAMS);
6262
return String.format("performing %s on :\n left query:\n%s\n right query:\n%s",
6363
this.relation.name, BytesReference.bytes(firstBuilder).utf8ToString(),

legacy/src/main/java/org/opensearch/sql/legacy/request/SqlRequest.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,14 @@
66

77
package org.opensearch.sql.legacy.request;
88

9+
import com.fasterxml.jackson.core.JsonFactory;
910
import java.io.IOException;
1011
import java.util.Collections;
1112
import org.json.JSONException;
1213
import org.json.JSONObject;
1314
import org.opensearch.common.settings.Settings;
1415
import org.opensearch.common.xcontent.LoggingDeprecationHandler;
15-
import org.opensearch.common.xcontent.XContentFactory;
16-
import org.opensearch.common.xcontent.XContentType;
16+
import org.opensearch.common.xcontent.json.JsonXContentParser;
1717
import org.opensearch.core.xcontent.NamedXContentRegistry;
1818
import org.opensearch.core.xcontent.XContentParser;
1919
import org.opensearch.index.query.BoolQueryBuilder;
@@ -90,10 +90,10 @@ private void addFilterFromJson(BoolQueryBuilder boolQuery) throws SqlParseExcept
9090
try {
9191
String filter = getFilterObjectAsString(jsonContent);
9292
SearchModule searchModule = new SearchModule(Settings.EMPTY, Collections.emptyList());
93-
XContentParser parser = XContentFactory.xContent(XContentType.JSON).
94-
createParser(new NamedXContentRegistry(searchModule.getNamedXContents()),
95-
LoggingDeprecationHandler.INSTANCE,
96-
filter);
93+
XContentParser parser = new JsonXContentParser(
94+
new NamedXContentRegistry(searchModule.getNamedXContents()),
95+
LoggingDeprecationHandler.INSTANCE,
96+
new JsonFactory().createParser(filter));
9797

9898
// nextToken is called before passing the parser to fromXContent since the fieldName will be null if the
9999
// first token it parses is START_OBJECT resulting in an exception

legacy/src/main/java/org/opensearch/sql/legacy/utils/JsonPrettyFormatter.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,12 @@
66

77
package org.opensearch.sql.legacy.utils;
88

9+
import com.fasterxml.jackson.core.JsonFactory;
910
import java.io.IOException;
1011
import org.opensearch.common.Strings;
1112
import org.opensearch.common.xcontent.LoggingDeprecationHandler;
1213
import org.opensearch.common.xcontent.XContentFactory;
13-
import org.opensearch.common.xcontent.XContentType;
14+
import org.opensearch.common.xcontent.json.JsonXContentParser;
1415
import org.opensearch.core.xcontent.NamedXContentRegistry;
1516
import org.opensearch.core.xcontent.XContentBuilder;
1617
import org.opensearch.core.xcontent.XContentParser;
@@ -29,8 +30,10 @@ public static String format(String jsonString) throws IOException {
2930
//turn _explain response into pretty formatted Json
3031
XContentBuilder contentBuilder = XContentFactory.jsonBuilder().prettyPrint();
3132
try (
32-
XContentParser contentParser = XContentFactory.xContent(XContentType.JSON)
33-
.createParser(NamedXContentRegistry.EMPTY, LoggingDeprecationHandler.INSTANCE, jsonString)
33+
XContentParser contentParser = new JsonXContentParser(
34+
NamedXContentRegistry.EMPTY,
35+
LoggingDeprecationHandler.INSTANCE,
36+
new JsonFactory().createParser(jsonString))
3437
){
3538
contentBuilder.copyCurrentStructure(contentParser);
3639
}

0 commit comments

Comments
 (0)