From 28c2b1e7750ad50c770881ad3266e9f292713ef9 Mon Sep 17 00:00:00 2001 From: chloe-zh Date: Mon, 6 Apr 2020 15:09:40 -0700 Subject: [PATCH 1/2] removed http GET method; added integTest --- .../sql/plugin/RestSqlAction.java | 2 -- .../sql/request/SqlRequestFactory.java | 2 -- .../sql/esintgtest/GetEndpointQueryIT.java | 28 ++++++++----------- 3 files changed, 11 insertions(+), 21 deletions(-) diff --git a/src/main/java/com/amazon/opendistroforelasticsearch/sql/plugin/RestSqlAction.java b/src/main/java/com/amazon/opendistroforelasticsearch/sql/plugin/RestSqlAction.java index 1c6fc4bad4..1dbfd9deac 100644 --- a/src/main/java/com/amazon/opendistroforelasticsearch/sql/plugin/RestSqlAction.java +++ b/src/main/java/com/amazon/opendistroforelasticsearch/sql/plugin/RestSqlAction.java @@ -87,9 +87,7 @@ public class RestSqlAction extends BaseRestHandler { super(); restController.registerHandler(RestRequest.Method.POST, QUERY_API_ENDPOINT, this); - restController.registerHandler(RestRequest.Method.GET, QUERY_API_ENDPOINT, this); restController.registerHandler(RestRequest.Method.POST, EXPLAIN_API_ENDPOINT, this); - restController.registerHandler(RestRequest.Method.GET, EXPLAIN_API_ENDPOINT, this); this.allowExplicitIndex = MULTI_ALLOW_EXPLICIT_INDEX.get(settings); } diff --git a/src/main/java/com/amazon/opendistroforelasticsearch/sql/request/SqlRequestFactory.java b/src/main/java/com/amazon/opendistroforelasticsearch/sql/request/SqlRequestFactory.java index 437b8bce99..cd348a244f 100644 --- a/src/main/java/com/amazon/opendistroforelasticsearch/sql/request/SqlRequestFactory.java +++ b/src/main/java/com/amazon/opendistroforelasticsearch/sql/request/SqlRequestFactory.java @@ -34,8 +34,6 @@ public class SqlRequestFactory { public static SqlRequest getSqlRequest(RestRequest request) { switch (request.method()) { - case GET: - return parseSqlRequestFromUrl(request); case POST: return parseSqlRequestFromPayload(request); default: diff --git a/src/test/java/com/amazon/opendistroforelasticsearch/sql/esintgtest/GetEndpointQueryIT.java b/src/test/java/com/amazon/opendistroforelasticsearch/sql/esintgtest/GetEndpointQueryIT.java index fc657aa24e..cb7b67f8cd 100644 --- a/src/test/java/com/amazon/opendistroforelasticsearch/sql/esintgtest/GetEndpointQueryIT.java +++ b/src/test/java/com/amazon/opendistroforelasticsearch/sql/esintgtest/GetEndpointQueryIT.java @@ -15,39 +15,33 @@ package com.amazon.opendistroforelasticsearch.sql.esintgtest; -import org.json.JSONArray; -import org.json.JSONObject; -import org.junit.Assert; +import org.elasticsearch.client.ResponseException; +import org.junit.Rule; import org.junit.Test; import java.io.IOException; -import java.util.Locale; +import org.junit.rules.ExpectedException; import static com.amazon.opendistroforelasticsearch.sql.esintgtest.TestsConstants.TEST_INDEX_ACCOUNT; -import static org.hamcrest.Matchers.equalTo; /** * Tests to cover requests with "?format=csv" parameter */ public class GetEndpointQueryIT extends SQLIntegTestCase { + @Rule + public ExpectedException rule = ExpectedException.none(); + @Override protected void init() throws Exception { loadIndex(Index.ACCOUNT); } @Test - public void unicodeTermInQuery() throws IOException { - - // NOTE: There are unicode characters in name, not just whitespace. - final String name = "盛虹"; - final String query = String.format(Locale.ROOT, "SELECT _id, firstname FROM %s " + - "WHERE firstname=matchQuery('%s') LIMIT 2", TEST_INDEX_ACCOUNT, name); - - final JSONObject result = executeQueryWithGetRequest(query); - final JSONArray hits = getHits(result); - Assert.assertThat(hits.length(), equalTo(1)); - Assert.assertThat(hits.query("/0/_id"), equalTo("919")); - Assert.assertThat(hits.query("/0/_source/firstname"), equalTo(name)); + public void getEndPointShouldBeInvalid() throws IOException { + rule.expect(ResponseException.class); + rule.expectMessage("Incorrect HTTP method"); + String query = "select name from " + TEST_INDEX_ACCOUNT; + executeQueryWithGetRequest(query); } } From 018841877752cee6296050bb0c02410cf1bd1d7a Mon Sep 17 00:00:00 2001 From: chloe-zh Date: Tue, 7 Apr 2020 16:22:15 -0700 Subject: [PATCH 2/2] Removed GET method in doc and doctest --- README.md | 3 --- docs/user/interfaces/endpoint.rst | 15 --------------- .../sql/doctest/interfaces/EndpointIT.java | 16 +--------------- 3 files changed, 1 insertion(+), 33 deletions(-) diff --git a/README.md b/README.md index a7286dce53..883d40ef0d 100644 --- a/README.md +++ b/README.md @@ -29,9 +29,6 @@ The package uses the [Gradle](https://docs.gradle.org/4.10.2/userguide/userguide To use the feature, send requests to the `_opendistro/_sql` URI. You can use a request parameter or the request body (recommended). * Simple query -``` -GET https://:/_opendistro/_sql?sql=select * from my-index limit 50 -``` ``` POST https://:/_opendistro/_sql diff --git a/docs/user/interfaces/endpoint.rst b/docs/user/interfaces/endpoint.rst index 58ace7e5fc..b8923289a5 100644 --- a/docs/user/interfaces/endpoint.rst +++ b/docs/user/interfaces/endpoint.rst @@ -16,21 +16,6 @@ Introduction To send query request to SQL plugin, you can either use a request parameter in HTTP GET or request body by HTTP POST request. POST request is recommended because it doesn't have length limitation and allows for other parameters passed to plugin for other functionality such as prepared statement. And also the explain endpoint is used very often for query translation and troubleshooting. -GET -=== - -Description ------------ - -You can send HTTP GET request with your query embedded in URL parameter. - -Example -------- - -SQL query:: - - >> curl -H 'Content-Type: application/json' -X GET localhost:9200/_opendistro/_sql?sql=SELECT * FROM accounts - POST ==== diff --git a/src/test/java/com/amazon/opendistroforelasticsearch/sql/doctest/interfaces/EndpointIT.java b/src/test/java/com/amazon/opendistroforelasticsearch/sql/doctest/interfaces/EndpointIT.java index b4b9a83ee4..1a8578a163 100644 --- a/src/test/java/com/amazon/opendistroforelasticsearch/sql/doctest/interfaces/EndpointIT.java +++ b/src/test/java/com/amazon/opendistroforelasticsearch/sql/doctest/interfaces/EndpointIT.java @@ -31,20 +31,6 @@ public class EndpointIT extends DocTest { @Section(1) - public void queryByGet() { - section( - title("GET"), - description("You can send HTTP GET request with your query embedded in URL parameter."), - example( - description(), - get("SELECT * FROM accounts"), - queryFormat(CURL_REQUEST, IGNORE_RESPONSE), - explainFormat(IGNORE_REQUEST, IGNORE_RESPONSE) - ) - ); - } - - @Section(2) public void queryByPost() { section( title("POST"), @@ -58,7 +44,7 @@ public void queryByPost() { ); } - @Section(3) + @Section(2) public void explainQuery() { section( title("Explain"),