diff --git a/docs/user/interfaces/protocol.rst b/docs/user/interfaces/protocol.rst index 52674b99244..625eed0f544 100644 --- a/docs/user/interfaces/protocol.rst +++ b/docs/user/interfaces/protocol.rst @@ -208,73 +208,6 @@ Result set:: "status" : 400 } -OpenSearch DSL -============== - -Description ------------ - -The plugin returns original response from OpenSearch in JSON. Because this is the native response from OpenSearch, extra efforts are needed to parse and interpret it. - -Example -------- - -SQL query:: - - >> curl -H 'Content-Type: application/json' -X POST localhost:9200/_plugins/_sql?format=json -d '{ - "query" : "SELECT firstname, lastname, age FROM accounts ORDER BY age LIMIT 2" - }' - -Result set:: - - { - "_shards" : { - "total" : 5, - "failed" : 0, - "successful" : 5, - "skipped" : 0 - }, - "hits" : { - "hits" : [ - { - "_index" : "accounts", - "_type" : "_doc", - "_source" : { - "firstname" : "Nanette", - "age" : 28, - "lastname" : "Bates" - }, - "_id" : "13", - "sort" : [ - 28 - ], - "_score" : null - }, - { - "_index" : "accounts", - "_type" : "_doc", - "_source" : { - "firstname" : "Amber", - "age" : 32, - "lastname" : "Duke" - }, - "_id" : "1", - "sort" : [ - 32 - ], - "_score" : null - } - ], - "total" : { - "value" : 4, - "relation" : "eq" - }, - "max_score" : null - }, - "took" : 100, - "timed_out" : false - } - CSV Format ========== diff --git a/integ-test/src/test/java/org/opensearch/sql/legacy/AggregationIT.java b/integ-test/src/test/java/org/opensearch/sql/legacy/AggregationIT.java index 490e9eb5102..a5f47ad1d17 100644 --- a/integ-test/src/test/java/org/opensearch/sql/legacy/AggregationIT.java +++ b/integ-test/src/test/java/org/opensearch/sql/legacy/AggregationIT.java @@ -38,6 +38,9 @@ import org.junit.Ignore; import org.junit.Test; +@Ignore( + "OpenSearch DSL format is deprecated in 3.0.0. Ignore legacy IT that relies on json format" + + " response for now. Need to decide what to do with these test cases.") public class AggregationIT extends SQLIntegTestCase { @Override diff --git a/integ-test/src/test/java/org/opensearch/sql/legacy/DateFormatIT.java b/integ-test/src/test/java/org/opensearch/sql/legacy/DateFormatIT.java index 388d9009249..863adccbd18 100644 --- a/integ-test/src/test/java/org/opensearch/sql/legacy/DateFormatIT.java +++ b/integ-test/src/test/java/org/opensearch/sql/legacy/DateFormatIT.java @@ -29,6 +29,9 @@ import org.junit.Test; import org.opensearch.sql.legacy.exception.SqlParseException; +@Ignore( + "OpenSearch DSL format is deprecated in 3.0.0. Ignore legacy IT that relies on json format" + + " response for now. Need to decide what to do with these test cases.") public class DateFormatIT extends SQLIntegTestCase { private static final String SELECT_FROM = 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 d9a6849fc80..56c60eb91e6 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 @@ -17,6 +17,7 @@ import org.joda.time.format.DateTimeFormat; import org.joda.time.format.DateTimeFormatter; import org.json.JSONObject; +import org.junit.Ignore; import org.junit.Test; import org.opensearch.action.search.SearchResponse; import org.opensearch.common.xcontent.LoggingDeprecationHandler; @@ -25,6 +26,9 @@ import org.opensearch.core.xcontent.XContentParser; import org.opensearch.search.SearchHit; +@Ignore( + "OpenSearch DSL format is deprecated in 3.0.0. Ignore legacy IT that relies on json format" + + " response for now. Need to decide what to do with these test cases.") public class DateFunctionsIT extends SQLIntegTestCase { private static final String FROM = "FROM " + TestsConstants.TEST_INDEX_ONLINE; diff --git a/integ-test/src/test/java/org/opensearch/sql/legacy/GetEndpointQueryIT.java b/integ-test/src/test/java/org/opensearch/sql/legacy/GetEndpointQueryIT.java index 6cc4aba8118..6831dcfcc68 100644 --- a/integ-test/src/test/java/org/opensearch/sql/legacy/GetEndpointQueryIT.java +++ b/integ-test/src/test/java/org/opensearch/sql/legacy/GetEndpointQueryIT.java @@ -13,7 +13,6 @@ import org.junit.rules.ExpectedException; import org.opensearch.client.ResponseException; -/** Tests to cover requests with "?format=csv" parameter */ public class GetEndpointQueryIT extends SQLIntegTestCase { @Rule public final ExpectedException rule = ExpectedException.none(); diff --git a/integ-test/src/test/java/org/opensearch/sql/legacy/HashJoinIT.java b/integ-test/src/test/java/org/opensearch/sql/legacy/HashJoinIT.java index 02c55d8eb8f..c83cbfc063d 100644 --- a/integ-test/src/test/java/org/opensearch/sql/legacy/HashJoinIT.java +++ b/integ-test/src/test/java/org/opensearch/sql/legacy/HashJoinIT.java @@ -19,9 +19,13 @@ import org.json.JSONArray; import org.json.JSONObject; import org.junit.Assert; +import org.junit.Ignore; import org.junit.Test; /** Test new hash join algorithm by comparison with old implementation. */ +@Ignore( + "OpenSearch DSL format is deprecated in 3.0.0. Ignore legacy IT that relies on json format" + + " response for now. Need to decide what to do with these test cases.") public class HashJoinIT extends SQLIntegTestCase { /** Hint to use old join algorithm */ diff --git a/integ-test/src/test/java/org/opensearch/sql/legacy/HavingIT.java b/integ-test/src/test/java/org/opensearch/sql/legacy/HavingIT.java index 3bd2195a89e..b7c998dfc9f 100644 --- a/integ-test/src/test/java/org/opensearch/sql/legacy/HavingIT.java +++ b/integ-test/src/test/java/org/opensearch/sql/legacy/HavingIT.java @@ -20,8 +20,12 @@ import org.hamcrest.Matcher; import org.json.JSONArray; import org.json.JSONObject; +import org.junit.Ignore; import org.junit.Test; +@Ignore( + "OpenSearch DSL format is deprecated in 3.0.0. Ignore legacy IT that relies on json format" + + " response for now. Need to decide what to do with these test cases.") public class HavingIT extends SQLIntegTestCase { private static final String SELECT_FROM_WHERE_GROUP_BY = 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 b6c0942ba4d..aa182144852 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 @@ -14,6 +14,7 @@ import java.io.IOException; import java.util.Map; import org.json.JSONObject; +import org.junit.Ignore; import org.junit.Test; import org.opensearch.action.search.SearchResponse; import org.opensearch.common.xcontent.LoggingDeprecationHandler; @@ -23,6 +24,9 @@ import org.opensearch.search.SearchHit; import org.opensearch.search.SearchHits; +@Ignore( + "OpenSearch DSL format is deprecated in 3.0.0. Ignore legacy IT that relies on json format" + + " response for now. Need to decide what to do with these test cases.") public class JSONRequestIT extends SQLIntegTestCase { @Override diff --git a/integ-test/src/test/java/org/opensearch/sql/legacy/JoinIT.java b/integ-test/src/test/java/org/opensearch/sql/legacy/JoinIT.java index 8c2ea96474d..e06a1a2126d 100644 --- a/integ-test/src/test/java/org/opensearch/sql/legacy/JoinIT.java +++ b/integ-test/src/test/java/org/opensearch/sql/legacy/JoinIT.java @@ -31,6 +31,9 @@ import org.junit.Ignore; import org.junit.Test; +@Ignore( + "OpenSearch DSL format is deprecated in 3.0.0. Ignore legacy IT that relies on json format" + + " response for now. Need to decide what to do with these test cases.") public class JoinIT extends SQLIntegTestCase { private static final String USE_NL_HINT = " /*! USE_NL*/"; 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 fcf1edf3e09..5f2dee6c0b8 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 @@ -12,6 +12,7 @@ import com.fasterxml.jackson.core.JsonFactory; import java.io.IOException; +import org.junit.Ignore; import org.junit.Test; import org.opensearch.action.search.SearchResponse; import org.opensearch.common.xcontent.LoggingDeprecationHandler; @@ -20,6 +21,9 @@ import org.opensearch.core.xcontent.XContentParser; import org.opensearch.search.SearchHit; +@Ignore( + "OpenSearch DSL format is deprecated in 3.0.0. Ignore legacy IT that relies on json format" + + " response for now. Need to decide what to do with these test cases.") public class MathFunctionsIT extends SQLIntegTestCase { private static final String FROM = "FROM " + TestsConstants.TEST_INDEX_ACCOUNT; diff --git a/integ-test/src/test/java/org/opensearch/sql/legacy/MultiQueryIT.java b/integ-test/src/test/java/org/opensearch/sql/legacy/MultiQueryIT.java index bee85ac3145..11432490adf 100644 --- a/integ-test/src/test/java/org/opensearch/sql/legacy/MultiQueryIT.java +++ b/integ-test/src/test/java/org/opensearch/sql/legacy/MultiQueryIT.java @@ -14,8 +14,12 @@ import org.json.JSONArray; import org.json.JSONObject; import org.junit.Assert; +import org.junit.Ignore; import org.junit.Test; +@Ignore( + "OpenSearch DSL format is deprecated in 3.0.0. Ignore legacy IT that relies on json format" + + " response for now. Need to decide what to do with these test cases.") public class MultiQueryIT extends SQLIntegTestCase { private static final String MINUS_SCROLL_DEFAULT_HINT = 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 2108bf6867f..82d94ca1163 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 @@ -60,6 +60,9 @@ * 6) Verification for conditions mixed with regular and nested fields * */ +@Ignore( + "OpenSearch DSL format is deprecated in 3.0.0. Ignore legacy IT that relies on json format" + + " response for now. Need to decide what to do with these test cases.") public class NestedFieldQueryIT extends SQLIntegTestCase { private static final String FROM = diff --git a/integ-test/src/test/java/org/opensearch/sql/legacy/OrderIT.java b/integ-test/src/test/java/org/opensearch/sql/legacy/OrderIT.java index 20bed5d2edb..f91ae132c65 100644 --- a/integ-test/src/test/java/org/opensearch/sql/legacy/OrderIT.java +++ b/integ-test/src/test/java/org/opensearch/sql/legacy/OrderIT.java @@ -10,8 +10,12 @@ import java.io.IOException; import org.json.JSONArray; import org.json.JSONObject; +import org.junit.Ignore; import org.junit.Test; +@Ignore( + "OpenSearch DSL format is deprecated in 3.0.0. Ignore legacy IT that relies on json format" + + " response for now. Need to decide what to do with these test cases.") public class OrderIT extends SQLIntegTestCase { @Override diff --git a/integ-test/src/test/java/org/opensearch/sql/legacy/PluginIT.java b/integ-test/src/test/java/org/opensearch/sql/legacy/PluginIT.java index 9305b1655cc..49cc61dc054 100644 --- a/integ-test/src/test/java/org/opensearch/sql/legacy/PluginIT.java +++ b/integ-test/src/test/java/org/opensearch/sql/legacy/PluginIT.java @@ -12,6 +12,7 @@ import java.io.IOException; import java.util.Locale; import org.json.JSONObject; +import org.junit.Ignore; import org.junit.Test; import org.opensearch.client.Request; import org.opensearch.client.RequestOptions; @@ -26,6 +27,9 @@ protected void init() throws Exception { wipeAllClusterSettings(); } + @Ignore( + "OpenSearch DSL format is deprecated in 3.0.0. Ignore legacy IT that relies on json format" + + " response for now. Need to decide what to do with these test cases.") @Test public void sqlEnableSettingsTest() throws IOException { loadIndex(Index.ACCOUNT); diff --git a/integ-test/src/test/java/org/opensearch/sql/legacy/PreparedStatementIT.java b/integ-test/src/test/java/org/opensearch/sql/legacy/PreparedStatementIT.java index dd177ec1f14..ca7fccda187 100644 --- a/integ-test/src/test/java/org/opensearch/sql/legacy/PreparedStatementIT.java +++ b/integ-test/src/test/java/org/opensearch/sql/legacy/PreparedStatementIT.java @@ -9,10 +9,14 @@ import org.json.JSONArray; import org.json.JSONObject; import org.junit.Assert; +import org.junit.Ignore; import org.junit.Test; // Refer to https://www.elastic.co/guide/en/elasticsearch/reference/6.5/integration-tests.html // for detailed OpenSearchIntegTestCase usages doc. +@Ignore( + "OpenSearch DSL format is deprecated in 3.0.0. Ignore legacy IT that relies on json format" + + " response for now. Need to decide what to do with these test cases.") public class PreparedStatementIT extends SQLIntegTestCase { @Override 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 3cf45f7419e..4090f03ed8f 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 @@ -26,6 +26,7 @@ import org.hamcrest.FeatureMatcher; import org.hamcrest.Matcher; import org.json.JSONObject; +import org.junit.Ignore; import org.junit.Test; import org.opensearch.action.search.SearchResponse; import org.opensearch.common.xcontent.LoggingDeprecationHandler; @@ -35,6 +36,9 @@ import org.opensearch.search.SearchHit; import org.opensearch.sql.legacy.utils.StringUtils; +@Ignore( + "OpenSearch DSL format is deprecated in 3.0.0. Ignore legacy IT that relies on json format" + + " response for now. Need to decide what to do with these test cases.") public class QueryFunctionsIT extends SQLIntegTestCase { private static final String SELECT_ALL = "SELECT *"; diff --git a/integ-test/src/test/java/org/opensearch/sql/legacy/QueryIT.java b/integ-test/src/test/java/org/opensearch/sql/legacy/QueryIT.java index 3fe8b50eefa..f27e2030927 100644 --- a/integ-test/src/test/java/org/opensearch/sql/legacy/QueryIT.java +++ b/integ-test/src/test/java/org/opensearch/sql/legacy/QueryIT.java @@ -40,6 +40,9 @@ import org.opensearch.core.rest.RestStatus; import org.opensearch.sql.legacy.utils.StringUtils; +@Ignore( + "OpenSearch DSL format is deprecated in 3.0.0. Ignore legacy IT that relies on json format" + + " response for now. Need to decide what to do with these test cases.") public class QueryIT extends SQLIntegTestCase { /** 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 356b910d5fc..f3a6d03bc77 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 @@ -44,6 +44,9 @@ import org.opensearch.search.SearchHit; import org.opensearch.search.SearchHits; +@Ignore( + "OpenSearch DSL format is deprecated in 3.0.0. Ignore legacy IT that relies on json format" + + " response for now. Need to decide what to do with these test cases.") /** Created by allwefantasy on 8/25/16. */ public class SQLFunctionsIT extends SQLIntegTestCase { diff --git a/integ-test/src/test/java/org/opensearch/sql/legacy/SQLIntegTestCase.java b/integ-test/src/test/java/org/opensearch/sql/legacy/SQLIntegTestCase.java index f59fe82fa0c..a9179a7b820 100644 --- a/integ-test/src/test/java/org/opensearch/sql/legacy/SQLIntegTestCase.java +++ b/integ-test/src/test/java/org/opensearch/sql/legacy/SQLIntegTestCase.java @@ -229,7 +229,7 @@ protected synchronized void loadIndex(Index index) throws IOException { } protected Request getSqlRequest(String request, boolean explain) { - return getSqlRequest(request, explain, "json"); + return getSqlRequest(request, explain, "jdbc"); } protected Request getSqlRequest(String request, boolean explain, String requestType) { @@ -344,7 +344,7 @@ protected Request buildGetEndpointRequest(final String sqlQuery) { final String requestUrl = String.format( - Locale.ROOT, "%s?sql=%s&format=%s", QUERY_API_ENDPOINT, urlEncodedQuery, "json"); + Locale.ROOT, "%s?sql=%s&format=%s", QUERY_API_ENDPOINT, urlEncodedQuery, "jdbc"); return new Request("GET", requestUrl); } diff --git a/integ-test/src/test/java/org/opensearch/sql/legacy/ShowIT.java b/integ-test/src/test/java/org/opensearch/sql/legacy/ShowIT.java index fa86bbbc221..018140c0395 100644 --- a/integ-test/src/test/java/org/opensearch/sql/legacy/ShowIT.java +++ b/integ-test/src/test/java/org/opensearch/sql/legacy/ShowIT.java @@ -13,8 +13,12 @@ import java.io.IOException; import org.json.JSONObject; import org.junit.Assert; +import org.junit.Ignore; import org.junit.Test; +@Ignore( + "OpenSearch DSL format is deprecated in 3.0.0. Ignore legacy IT that relies on json format" + + " response for now. Need to decide what to do with these test cases.") public class ShowIT extends SQLIntegTestCase { @Override 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 bf288262b6f..a7d8acb3a7d 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 @@ -12,6 +12,7 @@ import java.util.Set; import org.json.JSONObject; import org.junit.Assert; +import org.junit.Ignore; import org.junit.Test; import org.opensearch.action.search.SearchResponse; import org.opensearch.common.xcontent.LoggingDeprecationHandler; @@ -21,6 +22,9 @@ import org.opensearch.search.SearchHit; import org.opensearch.search.SearchHits; +@Ignore( + "OpenSearch DSL format is deprecated in 3.0.0. Ignore legacy IT that relies on json format" + + " response for now. Need to decide what to do with these test cases.") public class SourceFieldIT extends SQLIntegTestCase { @Override diff --git a/integ-test/src/test/java/org/opensearch/sql/legacy/SubqueryIT.java b/integ-test/src/test/java/org/opensearch/sql/legacy/SubqueryIT.java index 39abad92df9..16814ca33fb 100644 --- a/integ-test/src/test/java/org/opensearch/sql/legacy/SubqueryIT.java +++ b/integ-test/src/test/java/org/opensearch/sql/legacy/SubqueryIT.java @@ -35,6 +35,9 @@ import org.opensearch.client.ResponseException; import org.opensearch.sql.legacy.utils.StringUtils; +@Ignore( + "OpenSearch DSL format is deprecated in 3.0.0. Ignore legacy IT that relies on json format" + + " response for now. Need to decide what to do with these test cases.") public class SubqueryIT extends SQLIntegTestCase { @Rule public final ExpectedException exceptionRule = ExpectedException.none(); 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 9cf4fa2e8a5..72faeec2afe 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 @@ -24,6 +24,7 @@ import java.util.List; import org.json.JSONArray; import org.json.JSONObject; +import org.junit.Ignore; import org.junit.Test; import org.opensearch.action.search.SearchResponse; import org.opensearch.common.xcontent.LoggingDeprecationHandler; @@ -157,6 +158,9 @@ public void isnullShouldPassJDBC() throws IOException { assertEquals("boolean", response.query("/schema/0/type")); } + @Ignore( + "OpenSearch DSL format is deprecated in 3.0.0. Ignore legacy IT that relies on json format" + + " response for now. Need to decide what to do with these test cases.") @Test public void isnullWithNotNullInputTest() throws IOException { assertThat( @@ -188,6 +192,9 @@ public void isnullWithNullInputTest() { rows(LITERAL_TRUE.value(), LITERAL_FALSE.value())); } + @Ignore( + "OpenSearch DSL format is deprecated in 3.0.0. Ignore legacy IT that relies on json format" + + " response for now. Need to decide what to do with these test cases.") @Test public void isnullWithMathExpr() throws IOException { assertThat( diff --git a/legacy/src/main/java/org/opensearch/sql/legacy/executor/ActionRequestRestExecutorFactory.java b/legacy/src/main/java/org/opensearch/sql/legacy/executor/ActionRequestRestExecutorFactory.java index c58bba9e26a..068c1b433c4 100644 --- a/legacy/src/main/java/org/opensearch/sql/legacy/executor/ActionRequestRestExecutorFactory.java +++ b/legacy/src/main/java/org/opensearch/sql/legacy/executor/ActionRequestRestExecutorFactory.java @@ -7,9 +7,6 @@ import org.opensearch.sql.legacy.executor.csv.CSVResultRestExecutor; import org.opensearch.sql.legacy.executor.format.PrettyFormatRestExecutor; -import org.opensearch.sql.legacy.query.QueryAction; -import org.opensearch.sql.legacy.query.join.OpenSearchJoinQueryAction; -import org.opensearch.sql.legacy.query.multi.MultiQueryAction; /** Created by Eliran on 26/12/2015. */ public class ActionRequestRestExecutorFactory { @@ -18,17 +15,12 @@ public class ActionRequestRestExecutorFactory { * call if necessary. * * @param format format of response - * @param queryAction query action * @return executor */ - public static RestExecutor createExecutor(Format format, QueryAction queryAction) { + public static RestExecutor createExecutor(Format format) { switch (format) { case CSV: return new AsyncRestExecutor(new CSVResultRestExecutor()); - case JSON: - return new AsyncRestExecutor( - new ElasticDefaultRestExecutor(queryAction), - action -> isJoin(action) || isUnionMinus(action)); case JDBC: case RAW: case TABLE: @@ -36,12 +28,4 @@ public static RestExecutor createExecutor(Format format, QueryAction queryAction return new AsyncRestExecutor(new PrettyFormatRestExecutor(format.getFormatName())); } } - - private static boolean isJoin(QueryAction queryAction) { - return queryAction instanceof OpenSearchJoinQueryAction; - } - - private static boolean isUnionMinus(QueryAction queryAction) { - return queryAction instanceof MultiQueryAction; - } } diff --git a/legacy/src/main/java/org/opensearch/sql/legacy/executor/ElasticDefaultRestExecutor.java b/legacy/src/main/java/org/opensearch/sql/legacy/executor/ElasticDefaultRestExecutor.java deleted file mode 100644 index 5b18defbdc0..00000000000 --- a/legacy/src/main/java/org/opensearch/sql/legacy/executor/ElasticDefaultRestExecutor.java +++ /dev/null @@ -1,127 +0,0 @@ -/* - * Copyright OpenSearch Contributors - * SPDX-License-Identifier: Apache-2.0 - */ - -package org.opensearch.sql.legacy.executor; - -import com.google.common.collect.Maps; -import java.io.IOException; -import java.util.Map; -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; -import org.opensearch.action.ActionRequest; -import org.opensearch.action.admin.indices.get.GetIndexRequest; -import org.opensearch.action.search.SearchRequest; -import org.opensearch.action.search.SearchResponse; -import org.opensearch.action.search.SearchScrollRequest; -import org.opensearch.common.action.ActionFuture; -import org.opensearch.core.rest.RestStatus; -import org.opensearch.index.reindex.BulkIndexByScrollResponseContentListener; -import org.opensearch.index.reindex.DeleteByQueryRequest; -import org.opensearch.rest.BytesRestResponse; -import org.opensearch.rest.RestChannel; -import org.opensearch.rest.action.RestStatusToXContentListener; -import org.opensearch.search.SearchHits; -import org.opensearch.sql.legacy.exception.SqlParseException; -import org.opensearch.sql.legacy.executor.join.ElasticJoinExecutor; -import org.opensearch.sql.legacy.executor.join.ElasticUtils; -import org.opensearch.sql.legacy.executor.join.MetaSearchResult; -import org.opensearch.sql.legacy.executor.multi.MultiRequestExecutorFactory; -import org.opensearch.sql.legacy.query.QueryAction; -import org.opensearch.sql.legacy.query.SqlElasticRequestBuilder; -import org.opensearch.sql.legacy.query.join.JoinRequestBuilder; -import org.opensearch.sql.legacy.query.multi.MultiQueryRequestBuilder; -import org.opensearch.transport.client.Client; - -public class ElasticDefaultRestExecutor implements RestExecutor { - - /** Request builder to generate OpenSearch DSL */ - private final SqlElasticRequestBuilder requestBuilder; - - private static final Logger LOG = LogManager.getLogger(ElasticDefaultRestExecutor.class); - - public ElasticDefaultRestExecutor(QueryAction queryAction) { - // Put explain() here to make it run in NIO thread - try { - this.requestBuilder = queryAction.explain(); - } catch (SqlParseException e) { - throw new IllegalStateException("Failed to explain query action", e); - } - } - - /** Execute the ActionRequest and returns the REST response using the channel. */ - @Override - public void execute( - Client client, Map params, QueryAction queryAction, RestChannel channel) - throws Exception { - ActionRequest request = requestBuilder.request(); - - if (requestBuilder instanceof JoinRequestBuilder) { - ElasticJoinExecutor executor = ElasticJoinExecutor.createJoinExecutor(client, requestBuilder); - executor.run(); - executor.sendResponse(channel); - } else if (requestBuilder instanceof MultiQueryRequestBuilder) { - ElasticHitsExecutor executor = - MultiRequestExecutorFactory.createExecutor( - client, (MultiQueryRequestBuilder) requestBuilder); - executor.run(); - sendDefaultResponse(executor.getHits(), channel); - } else if (request instanceof SearchRequest) { - client.search((SearchRequest) request, new RestStatusToXContentListener<>(channel)); - } else if (request instanceof DeleteByQueryRequest) { - requestBuilder - .getBuilder() - .execute(new BulkIndexByScrollResponseContentListener(channel, Maps.newHashMap())); - } else if (request instanceof GetIndexRequest) { - requestBuilder - .getBuilder() - .execute(new GetIndexRequestRestListener(channel, (GetIndexRequest) request)); - } else if (request instanceof SearchScrollRequest) { - client.searchScroll( - (SearchScrollRequest) request, new RestStatusToXContentListener<>(channel)); - } else { - throw new Exception( - String.format("Unsupported ActionRequest provided: %s", request.getClass().getName())); - } - } - - @Override - public String execute(Client client, Map params, QueryAction queryAction) - throws Exception { - ActionRequest request = requestBuilder.request(); - - if (requestBuilder instanceof JoinRequestBuilder) { - ElasticJoinExecutor executor = ElasticJoinExecutor.createJoinExecutor(client, requestBuilder); - executor.run(); - return ElasticUtils.hitsAsStringResult(executor.getHits(), new MetaSearchResult()); - } else if (requestBuilder instanceof MultiQueryRequestBuilder) { - ElasticHitsExecutor executor = - MultiRequestExecutorFactory.createExecutor( - client, (MultiQueryRequestBuilder) requestBuilder); - executor.run(); - return ElasticUtils.hitsAsStringResult(executor.getHits(), new MetaSearchResult()); - } else if (request instanceof SearchRequest) { - ActionFuture future = client.search((SearchRequest) request); - SearchResponse response = future.actionGet(); - return response.toString(); - } else if (request instanceof DeleteByQueryRequest) { - return requestBuilder.get().toString(); - } else if (request instanceof GetIndexRequest) { - return requestBuilder.getBuilder().execute().actionGet().toString(); - } else { - throw new Exception( - String.format("Unsupported ActionRequest provided: %s", request.getClass().getName())); - } - } - - private void sendDefaultResponse(SearchHits hits, RestChannel channel) { - try { - String json = ElasticUtils.hitsAsStringResult(hits, new MetaSearchResult()); - BytesRestResponse bytesRestResponse = new BytesRestResponse(RestStatus.OK, json); - channel.sendResponse(bytesRestResponse); - } catch (IOException e) { - e.printStackTrace(); - } - } -} diff --git a/legacy/src/main/java/org/opensearch/sql/legacy/executor/Format.java b/legacy/src/main/java/org/opensearch/sql/legacy/executor/Format.java index c47092f10b5..b3060275452 100644 --- a/legacy/src/main/java/org/opensearch/sql/legacy/executor/Format.java +++ b/legacy/src/main/java/org/opensearch/sql/legacy/executor/Format.java @@ -14,7 +14,6 @@ @RequiredArgsConstructor public enum Format { JDBC("jdbc"), - JSON("json"), CSV("csv"), RAW("raw"), TABLE("table"); diff --git a/legacy/src/main/java/org/opensearch/sql/legacy/plugin/RestSqlAction.java b/legacy/src/main/java/org/opensearch/sql/legacy/plugin/RestSqlAction.java index a0e68ff54be..9be2367dcaa 100644 --- a/legacy/src/main/java/org/opensearch/sql/legacy/plugin/RestSqlAction.java +++ b/legacy/src/main/java/org/opensearch/sql/legacy/plugin/RestSqlAction.java @@ -251,8 +251,7 @@ private void executeSqlRequest( channel.sendResponse(new BytesRestResponse(OK, "application/json; charset=UTF-8", result)); } else { RestExecutor restExecutor = - ActionRequestRestExecutorFactory.createExecutor( - SqlRequestParam.getFormat(params), queryAction); + ActionRequestRestExecutorFactory.createExecutor(SqlRequestParam.getFormat(params)); // doing this hack because OpenSearch throws exception for un-consumed props Map additionalParams = new HashMap<>(); for (String paramName : responseParams()) { diff --git a/legacy/src/main/java/org/opensearch/sql/legacy/query/OpenSearchActionFactory.java b/legacy/src/main/java/org/opensearch/sql/legacy/query/OpenSearchActionFactory.java index 49aa38ae581..93e721e52d4 100644 --- a/legacy/src/main/java/org/opensearch/sql/legacy/query/OpenSearchActionFactory.java +++ b/legacy/src/main/java/org/opensearch/sql/legacy/query/OpenSearchActionFactory.java @@ -63,7 +63,7 @@ public class OpenSearchActionFactory { public static QueryAction create(Client client, String sql) throws SqlParseException, SQLFeatureNotSupportedException, SQLFeatureDisabledException { - return create(client, new QueryActionRequest(sql, new ColumnTypeProvider(), Format.JSON)); + return create(client, new QueryActionRequest(sql, new ColumnTypeProvider(), Format.JDBC)); } /** @@ -116,7 +116,7 @@ public static QueryAction create(Client client, QueryActionRequest request) } else { sqlExpr.accept(new TermFieldRewriter()); // migrate aggregation to query planner framework. - if (shouldMigrateToQueryPlan(sqlExpr, request.getFormat())) { + if (shouldMigrateToQueryPlan(sqlExpr)) { return new QueryPlanQueryAction( new QueryPlanRequestBuilder( new BindingTupleQueryPlanner(client, sqlExpr, request.getTypeProvider()))); @@ -191,12 +191,7 @@ private static boolean isJoin(SQLQueryExpr sqlExpr, String sql) { } @VisibleForTesting - public static boolean shouldMigrateToQueryPlan(SQLQueryExpr expr, Format format) { - // The JSON format will return the OpenSearch aggregation result, which is not supported by the - // QueryPlanner. - if (format == Format.JSON) { - return false; - } + public static boolean shouldMigrateToQueryPlan(SQLQueryExpr expr) { QueryPlannerScopeDecider decider = new QueryPlannerScopeDecider(); return decider.isInScope(expr); } diff --git a/legacy/src/test/java/org/opensearch/sql/legacy/unittest/SqlRequestParamTest.java b/legacy/src/test/java/org/opensearch/sql/legacy/unittest/SqlRequestParamTest.java index 0d29b55106f..ee2f3ac74a7 100644 --- a/legacy/src/test/java/org/opensearch/sql/legacy/unittest/SqlRequestParamTest.java +++ b/legacy/src/test/java/org/opensearch/sql/legacy/unittest/SqlRequestParamTest.java @@ -41,12 +41,6 @@ public void shouldReturnFalseIfPrettyParamsIsUnknownValue() { assertFalse(SqlRequestParam.isPrettyFormat(ImmutableMap.of(QUERY_PARAMS_PRETTY, "unknown"))); } - @Test - public void shouldReturnJSONIfFormatParamsIsJSON() { - assertEquals( - Format.JSON, SqlRequestParam.getFormat(ImmutableMap.of(QUERY_PARAMS_FORMAT, "json"))); - } - @Test public void shouldReturnDefaultFormatIfNoFormatParams() { assertEquals(Format.JDBC, SqlRequestParam.getFormat(ImmutableMap.of())); diff --git a/legacy/src/test/java/org/opensearch/sql/legacy/unittest/StringOperatorsTest.java b/legacy/src/test/java/org/opensearch/sql/legacy/unittest/StringOperatorsTest.java index 27b8e7f2c6e..264e74ed136 100644 --- a/legacy/src/test/java/org/opensearch/sql/legacy/unittest/StringOperatorsTest.java +++ b/legacy/src/test/java/org/opensearch/sql/legacy/unittest/StringOperatorsTest.java @@ -26,8 +26,7 @@ public static void init() { @Test public void substringTest() { String query = - "SELECT substring(lastname, 2, 1) FROM accounts WHERE substring(lastname, 2, 1) = 'a' " - + "GROUP BY substring(lastname, 2, 1) ORDER BY substring(lastname, 2, 1)"; + "SELECT substring(lastname, 2, 1) FROM accounts WHERE substring(lastname, 2, 1) = 'a'"; ScriptField scriptField = CheckScriptContents.getScriptFieldFromQuery(query); assertTrue( @@ -51,9 +50,7 @@ public void substringIndexOutOfBoundTest() { @Test public void lengthTest() { - String query = - "SELECT length(lastname) FROM accounts WHERE length(lastname) = 5 " - + "GROUP BY length(lastname) ORDER BY length(lastname)"; + String query = "SELECT length(lastname) FROM accounts WHERE length(lastname) = 5"; ScriptField scriptField = CheckScriptContents.getScriptFieldFromQuery(query); assertTrue( @@ -67,8 +64,8 @@ public void lengthTest() { @Test public void replaceTest() { String query = - "SELECT replace(lastname, 'a', 'A') FROM accounts WHERE replace(lastname, 'a', 'A') = 'aba'" - + " GROUP BY replace(lastname, 'a', 'A') ORDER BY replace(lastname, 'a', 'A')"; + "SELECT replace(lastname, 'a', 'A') FROM accounts WHERE replace(lastname, 'a', 'A') =" + + " 'aba'"; ScriptField scriptField = CheckScriptContents.getScriptFieldFromQuery(query); assertTrue( @@ -84,8 +81,7 @@ public void replaceTest() { @Test public void locateTest() { String query = - "SELECT locate('a', lastname, 1) FROM accounts WHERE locate('a', lastname, 1) = 4 " - + "GROUP BY locate('a', lastname, 1) ORDER BY locate('a', lastname, 1)"; + "SELECT locate('a', lastname, 1) FROM accounts WHERE locate('a', lastname, 1) = 4"; ScriptField scriptField = CheckScriptContents.getScriptFieldFromQuery(query); assertTrue( @@ -100,9 +96,7 @@ public void locateTest() { @Test public void ltrimTest() { - String query = - "SELECT ltrim(lastname) FROM accounts WHERE ltrim(lastname) = 'abc' " - + "GROUP BY ltrim(lastname) ORDER BY ltrim(lastname)"; + String query = "SELECT ltrim(lastname) FROM accounts WHERE ltrim(lastname) = 'abc'"; ScriptField scriptField = CheckScriptContents.getScriptFieldFromQuery(query); assertTrue( @@ -117,9 +111,7 @@ public void ltrimTest() { @Test public void rtrimTest() { - String query = - "SELECT rtrim(lastname) FROM accounts WHERE rtrim(lastname) = 'cba' " - + "GROUP BY rtrim(lastname) ORDER BY rtrim(lastname)"; + String query = "SELECT rtrim(lastname) FROM accounts WHERE rtrim(lastname) = 'cba'"; ScriptField scriptField = CheckScriptContents.getScriptFieldFromQuery(query); assertTrue( @@ -134,9 +126,7 @@ public void rtrimTest() { @Test public void asciiTest() { - String query = - "SELECT ascii(lastname) FROM accounts WHERE ascii(lastname) = 108 " - + "GROUP BY ascii(lastname) ORDER BY ascii(lastname)"; + String query = "SELECT ascii(lastname) FROM accounts WHERE ascii(lastname) = 108"; ScriptField scriptField = CheckScriptContents.getScriptFieldFromQuery(query); assertTrue( diff --git a/legacy/src/test/java/org/opensearch/sql/legacy/unittest/planner/OpenSearchActionFactoryTest.java b/legacy/src/test/java/org/opensearch/sql/legacy/unittest/planner/OpenSearchActionFactoryTest.java index 3443c2decd9..008b0d618df 100644 --- a/legacy/src/test/java/org/opensearch/sql/legacy/unittest/planner/OpenSearchActionFactoryTest.java +++ b/legacy/src/test/java/org/opensearch/sql/legacy/unittest/planner/OpenSearchActionFactoryTest.java @@ -9,56 +9,42 @@ import static org.junit.Assert.assertTrue; import org.junit.Test; -import org.opensearch.sql.legacy.executor.Format; import org.opensearch.sql.legacy.query.OpenSearchActionFactory; import org.opensearch.sql.legacy.util.SqlParserUtils; public class OpenSearchActionFactoryTest { - @Test - public void josnOutputRequestShouldNotMigrateToQueryPlan() { - String sql = "SELECT age, MAX(balance) FROM account GROUP BY age"; - - assertFalse( - OpenSearchActionFactory.shouldMigrateToQueryPlan(SqlParserUtils.parse(sql), Format.JSON)); - } - @Test public void nestQueryShouldNotMigrateToQueryPlan() { String sql = "SELECT age, nested(balance) FROM account GROUP BY age"; - assertFalse( - OpenSearchActionFactory.shouldMigrateToQueryPlan(SqlParserUtils.parse(sql), Format.JDBC)); + assertFalse(OpenSearchActionFactory.shouldMigrateToQueryPlan(SqlParserUtils.parse(sql))); } @Test public void nonAggregationQueryShouldNotMigrateToQueryPlan() { String sql = "SELECT age FROM account "; - assertFalse( - OpenSearchActionFactory.shouldMigrateToQueryPlan(SqlParserUtils.parse(sql), Format.JDBC)); + assertFalse(OpenSearchActionFactory.shouldMigrateToQueryPlan(SqlParserUtils.parse(sql))); } @Test public void aggregationQueryWithoutGroupByShouldMigrateToQueryPlan() { String sql = "SELECT age, COUNT(balance) FROM account "; - assertTrue( - OpenSearchActionFactory.shouldMigrateToQueryPlan(SqlParserUtils.parse(sql), Format.JDBC)); + assertTrue(OpenSearchActionFactory.shouldMigrateToQueryPlan(SqlParserUtils.parse(sql))); } @Test public void aggregationQueryWithExpressionByShouldMigrateToQueryPlan() { String sql = "SELECT age, MAX(balance) - MIN(balance) FROM account "; - assertTrue( - OpenSearchActionFactory.shouldMigrateToQueryPlan(SqlParserUtils.parse(sql), Format.JDBC)); + assertTrue(OpenSearchActionFactory.shouldMigrateToQueryPlan(SqlParserUtils.parse(sql))); } @Test public void queryOnlyHasGroupByShouldMigrateToQueryPlan() { String sql = "SELECT CAST(age AS DOUBLE) as alias FROM account GROUP BY alias"; - assertTrue( - OpenSearchActionFactory.shouldMigrateToQueryPlan(SqlParserUtils.parse(sql), Format.JDBC)); + assertTrue(OpenSearchActionFactory.shouldMigrateToQueryPlan(SqlParserUtils.parse(sql))); } } diff --git a/legacy/src/test/java/org/opensearch/sql/legacy/unittest/query/DefaultQueryActionTest.java b/legacy/src/test/java/org/opensearch/sql/legacy/unittest/query/DefaultQueryActionTest.java index d290e4dd5b0..4c6061ff5e7 100644 --- a/legacy/src/test/java/org/opensearch/sql/legacy/unittest/query/DefaultQueryActionTest.java +++ b/legacy/src/test/java/org/opensearch/sql/legacy/unittest/query/DefaultQueryActionTest.java @@ -130,13 +130,13 @@ public void testIfScrollShouldBeOpenWithDifferentFormats() { doReturn(settingFetchSize).when(mockSqlRequest).fetchSize(); queryAction.setSqlRequest(mockSqlRequest); - Format[] formats = new Format[] {Format.CSV, Format.RAW, Format.JSON, Format.TABLE}; + Format[] formats = new Format[] {Format.CSV, Format.RAW, Format.TABLE}; for (Format format : formats) { queryAction.setFormat(format); queryAction.checkAndSetScroll(); } - Mockito.verify(mockRequestBuilder, times(4)).setSize(limit); + Mockito.verify(mockRequestBuilder, times(3)).setSize(limit); Mockito.verify(mockRequestBuilder, never()).setScroll(any(TimeValue.class)); queryAction.setFormat(Format.JDBC);