Skip to content

Commit

Permalink
Fix breaking changes.
Browse files Browse the repository at this point in the history
Signed-off-by: Yury-Fridlyand <[email protected]>
  • Loading branch information
Yury-Fridlyand committed Jul 29, 2023
1 parent 02185c8 commit 5e05d10
Show file tree
Hide file tree
Showing 20 changed files with 76 additions and 88 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,17 @@

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;
import org.junit.Assert;
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;

Expand Down Expand Up @@ -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();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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());
Expand All @@ -97,7 +96,7 @@ public static XContentBuilder hitsAsStringResultZeroCopy(List<SearchHit> 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());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);
}
Expand Down
Loading

0 comments on commit 5e05d10

Please sign in to comment.