-
Notifications
You must be signed in to change notification settings - Fork 25.6k
SQL: move requests' parameters to requests JSON body #36149
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 4 commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
bda5654
Move SQL request parameters from http url params to JSON body
astefan 6c69d77
Removed leftover commented code
astefan 375caf4
Adressing review comments
astefan b32f545
Merge branch 'master' of https://github.com/elastic/elasticsearch int…
astefan 5720e44
Addressed reviews
astefan 9e0b05d
Merge branch 'master' of https://github.com/elastic/elasticsearch int…
astefan e8298c5
Further polishing
astefan 697f836
Merge branch 'master' of https://github.com/elastic/elasticsearch int…
astefan 5fc74eb
Merge branch 'master' of https://github.com/elastic/elasticsearch int…
astefan 358a944
Merge branch 'master' of https://github.com/elastic/elasticsearch int…
astefan 945bab2
Cosmetic changes
astefan 51dee0d
Merge branch 'master' of https://github.com/elastic/elasticsearch int…
astefan 5a1bc38
Revert back Strings class usage
astefan 1a1f84b
Handle request body in `source` parameter as well
astefan 1dc2a64
Merge branch 'master' of https://github.com/elastic/elasticsearch int…
astefan File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -97,10 +97,10 @@ public void testNextPage() throws IOException { | |
| for (int i = 0; i < 20; i += 2) { | ||
| Map<String, Object> response; | ||
| if (i == 0) { | ||
| response = runSql(mode, new StringEntity(sqlRequest, ContentType.APPLICATION_JSON)); | ||
| response = runSql(new StringEntity(sqlRequest, ContentType.APPLICATION_JSON), ""); | ||
| } else { | ||
| response = runSql(mode, new StringEntity("{\"cursor\":\"" + cursor + "\"}", | ||
| ContentType.APPLICATION_JSON)); | ||
| response = runSql(new StringEntity("{\"cursor\":\"" + cursor + "\"" + mode(mode) + "}", | ||
| ContentType.APPLICATION_JSON), ""); | ||
| } | ||
|
|
||
| Map<String, Object> expected = new HashMap<>(); | ||
|
|
@@ -120,8 +120,8 @@ public void testNextPage() throws IOException { | |
| } | ||
| Map<String, Object> expected = new HashMap<>(); | ||
| expected.put("rows", emptyList()); | ||
| assertResponse(expected, runSql(mode, new StringEntity("{ \"cursor\":\"" + cursor + "\"}", | ||
| ContentType.APPLICATION_JSON))); | ||
| assertResponse(expected, runSql(new StringEntity("{ \"cursor\":\"" + cursor + "\"" + mode(mode) + "}", | ||
| ContentType.APPLICATION_JSON), "")); | ||
| } | ||
|
|
||
| @AwaitsFix(bugUrl = "Unclear status, https://github.com/elastic/x-pack-elasticsearch/issues/2074") | ||
|
|
@@ -136,8 +136,7 @@ public void testTimeZone() throws IOException { | |
| expected.put("size", 2); | ||
|
|
||
| // Default TimeZone is UTC | ||
| assertResponse(expected, runSql(mode, new StringEntity("{\"query\":\"SELECT DAY_OF_YEAR(test), COUNT(*) FROM test\"}", | ||
| ContentType.APPLICATION_JSON))); | ||
| assertResponse(expected, runSql(mode, "SELECT DAY_OF_YEAR(test), COUNT(*) FROM test")); | ||
| } | ||
|
|
||
| public void testScoreWithFieldNamedScore() throws IOException { | ||
|
|
@@ -306,31 +305,25 @@ private Map<String, Object> runSql(String mode, String sql) throws IOException { | |
| } | ||
|
|
||
| private Map<String, Object> runSql(String mode, String sql, String suffix) throws IOException { | ||
| return runSql(mode, new StringEntity("{\"query\":\"" + sql + "\"}", ContentType.APPLICATION_JSON), suffix); | ||
| return runSql(new StringEntity("{\"query\":\"" + sql + "\"" + mode(mode) + "}", ContentType.APPLICATION_JSON), suffix); | ||
| } | ||
|
|
||
| private Map<String, Object> runSql(String mode, HttpEntity sql) throws IOException { | ||
| return runSql(mode, sql, ""); | ||
| } | ||
|
|
||
| private Map<String, Object> runSql(String mode, HttpEntity sql, String suffix) throws IOException { | ||
| private Map<String, Object> runSql(HttpEntity sql, String suffix) throws IOException { | ||
| Request request = new Request("POST", "/_sql" + suffix); | ||
| request.addParameter("error_trace", "true"); // Helps with debugging in case something crazy happens on the server. | ||
| request.addParameter("pretty", "true"); // Improves error reporting readability | ||
| if (randomBoolean()) { | ||
| // We default to JSON but we force it randomly for extra coverage | ||
| request.addParameter("format", "json"); | ||
| } | ||
| if (false == mode.isEmpty()) { | ||
| request.addParameter("mode", mode); // JDBC or PLAIN mode | ||
| } | ||
| if (randomBoolean()) { | ||
| // JSON is the default but randomly set it sometime for extra coverage | ||
| RequestOptions.Builder options = request.getOptions().toBuilder(); | ||
| options.addHeader("Accept", randomFrom("*/*", "application/json")); | ||
| request.setOptions(options); | ||
| } | ||
| request.setEntity(sql); | ||
|
|
||
| Response response = client().performRequest(request); | ||
| try (InputStream content = response.getEntity().getContent()) { | ||
| return XContentHelper.convertToMap(JsonXContent.jsonXContent, content, false); | ||
|
|
@@ -357,9 +350,9 @@ public void testBasicQueryWithFilter() throws IOException { | |
| Map<String, Object> expected = new HashMap<>(); | ||
| expected.put("columns", singletonList(columnInfo(mode, "test", "text", JDBCType.VARCHAR, 0))); | ||
| expected.put("rows", singletonList(singletonList("foo"))); | ||
| assertResponse(expected, runSql(mode, new StringEntity("{\"query\":\"SELECT * FROM test\", " + | ||
| "\"filter\":{\"match\": {\"test\": \"foo\"}}}", | ||
| ContentType.APPLICATION_JSON))); | ||
| assertResponse(expected, runSql(new StringEntity("{\"query\":\"SELECT * FROM test\", " + | ||
| "\"filter\":{\"match\": {\"test\": \"foo\"}}" + mode(mode) + "}", | ||
| ContentType.APPLICATION_JSON), "")); | ||
| } | ||
|
|
||
| public void testBasicQueryWithParameters() throws IOException { | ||
|
|
@@ -373,16 +366,16 @@ public void testBasicQueryWithParameters() throws IOException { | |
| columnInfo(mode, "param", "integer", JDBCType.INTEGER, 11) | ||
| )); | ||
| expected.put("rows", singletonList(Arrays.asList("foo", 10))); | ||
| assertResponse(expected, runSql(mode, new StringEntity("{\"query\":\"SELECT test, ? param FROM test WHERE test = ?\", " + | ||
| "\"params\":[{\"type\": \"integer\", \"value\": 10}, {\"type\": \"keyword\", \"value\": \"foo\"}]}", | ||
| ContentType.APPLICATION_JSON))); | ||
| assertResponse(expected, runSql(new StringEntity("{\"query\":\"SELECT test, ? param FROM test WHERE test = ?\", " + | ||
| "\"params\":[{\"type\": \"integer\", \"value\": 10}, {\"type\": \"keyword\", \"value\": \"foo\"}]" | ||
| + mode(mode) + "}", ContentType.APPLICATION_JSON), "")); | ||
| } | ||
|
|
||
| public void testBasicTranslateQueryWithFilter() throws IOException { | ||
| index("{\"test\":\"foo\"}", | ||
| "{\"test\":\"bar\"}"); | ||
|
|
||
| Map<String, Object> response = runSql("", | ||
| Map<String, Object> response = runSql( | ||
| new StringEntity("{\"query\":\"SELECT * FROM test\", \"filter\":{\"match\": {\"test\": \"foo\"}}}", | ||
| ContentType.APPLICATION_JSON), "/translate/" | ||
| ); | ||
|
|
@@ -424,7 +417,7 @@ public void testTranslateQueryWithGroupByAndHaving() throws IOException { | |
| index("{\"salary\":100}", | ||
| "{\"age\":20}"); | ||
|
|
||
| Map<String, Object> response = runSql("", | ||
| Map<String, Object> response = runSql( | ||
| new StringEntity("{\"query\":\"SELECT avg(salary) FROM test GROUP BY abs(age) HAVING avg(salary) > 50 LIMIT 10\"}", | ||
| ContentType.APPLICATION_JSON), "/translate/" | ||
| ); | ||
|
|
@@ -570,9 +563,9 @@ public void testNextPageText() throws IOException { | |
| } | ||
| Map<String, Object> expected = new HashMap<>(); | ||
| expected.put("rows", emptyList()); | ||
| assertResponse(expected, runSql("", new StringEntity("{\"cursor\":\"" + cursor + "\"}", ContentType.APPLICATION_JSON))); | ||
| assertResponse(expected, runSql(new StringEntity("{\"cursor\":\"" + cursor + "\"}", ContentType.APPLICATION_JSON), "")); | ||
|
|
||
| Map<String, Object> response = runSql("", new StringEntity("{\"cursor\":\"" + cursor + "\"}", ContentType.APPLICATION_JSON), | ||
| Map<String, Object> response = runSql(new StringEntity("{\"cursor\":\"" + cursor + "\"}", ContentType.APPLICATION_JSON), | ||
| "/close"); | ||
| assertEquals(true, response.get("succeeded")); | ||
|
|
||
|
|
@@ -718,6 +711,10 @@ private static Map<String, Object> searchStats() throws IOException { | |
| public static String randomMode() { | ||
| return randomFrom("", "jdbc", "plain"); | ||
| } | ||
|
|
||
| public static String mode(String mode) { | ||
| return mode.isEmpty() ? "" : ",\"mode\":\"" + mode + "\""; | ||
|
||
| } | ||
|
|
||
| private void index(String... docs) throws IOException { | ||
| Request request = new Request("POST", "/test/test/_bulk"); | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"" could be
StringUtils/Strings.EMPTYThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've added an EMPTY constant to
org.elasticsearch.xpack.sql.proto.StringUtils. It seems there is no other class visible toqathat has this constant defined.