luocooong commented on a change in pull request #2474:
URL: https://github.com/apache/drill/pull/2474#discussion_r818409982
##########
File path:
contrib/storage-http/src/main/java/org/apache/drill/exec/store/http/util/SimpleHttp.java
##########
@@ -88,8 +92,9 @@
private final CustomErrorContext errorContext;
private final Paginator paginator;
private final HttpUrl url;
- private final StoragePluginRegistry registry;
private final PersistentTokenTable tokenTable;
+ private final Map<String,String> filters;
Review comment:
```suggestion
private final Map<String, String> filters;
```
##########
File path:
contrib/storage-http/src/main/java/org/apache/drill/exec/store/http/HttpBatchReader.java
##########
@@ -218,6 +219,14 @@ protected HttpUrl buildUrl() {
protected void addFilters(Builder urlBuilder, List<String> params,
Map<String, String> filters) {
+ // If the request is a POST query and the user selected to push the
filters to either JSON body
+ // or the post body, do not add to the query string.
+ if (subScan.tableSpec().connectionConfig().getMethodType() ==
HttpApiConfig.HttpMethod.POST &&
+
(subScan.tableSpec().connectionConfig().getPostParameterLocation().equalsIgnoreCase(HttpApiConfig.POST_BODY_POST_LOCATION)
||
Review comment:
```suggestion
(subScan.tableSpec().connectionConfig().getPostLocation() ==
PostLocation.POST_BODY) ||
```
##########
File path:
contrib/storage-http/src/main/java/org/apache/drill/exec/store/http/HttpBatchReader.java
##########
@@ -218,6 +219,14 @@ protected HttpUrl buildUrl() {
protected void addFilters(Builder urlBuilder, List<String> params,
Map<String, String> filters) {
+ // If the request is a POST query and the user selected to push the
filters to either JSON body
+ // or the post body, do not add to the query string.
+ if (subScan.tableSpec().connectionConfig().getMethodType() ==
HttpApiConfig.HttpMethod.POST &&
+
(subScan.tableSpec().connectionConfig().getPostParameterLocation().equalsIgnoreCase(HttpApiConfig.POST_BODY_POST_LOCATION)
||
+
subScan.tableSpec().connectionConfig().getPostParameterLocation().equalsIgnoreCase(HttpApiConfig.JSON_BODY_POST_LOCATION))
Review comment:
```suggestion
subScan.tableSpec().connectionConfig().getPostLocation() ==
PostLocation.JSON_BODY
```
##########
File path: contrib/storage-http/README.md
##########
@@ -137,6 +137,11 @@ postBody: "key1=value1
key2=value2"
```
+`postBodyLocation`: If the API uses the `POST` method, you can send
parameters in several different ways:
Review comment:
Thanks for the updating the docs.
##########
File path:
contrib/storage-http/src/test/java/org/apache/drill/exec/store/http/TestHttpPlugin.java
##########
@@ -1218,6 +1260,211 @@ public void testHeaders() throws Exception {
}
}
+ @Test
+ public void testJsonPostWithMockServer() throws Exception {
+ try (MockWebServer server = startServer()) {
+ server.enqueue(
+ new MockResponse()
+ .setResponseCode(200)
+ .setBody(TEST_JSON_RESPONSE)
+ );
+
+ String sql = "SELECT * FROM local.mockJsonPost";
+ RowSet results = client.queryBuilder().sql(sql).rowSet();
+
+ TupleMetadata expectedSchema = new SchemaBuilder()
+ .addMap("results")
+ .add("sunrise", TypeProtos.MinorType.VARCHAR,
TypeProtos.DataMode.OPTIONAL)
+ .add("sunset", TypeProtos.MinorType.VARCHAR,
TypeProtos.DataMode.OPTIONAL)
+ .add("solar_noon", TypeProtos.MinorType.VARCHAR,
TypeProtos.DataMode.OPTIONAL)
+ .add("day_length", TypeProtos.MinorType.VARCHAR,
TypeProtos.DataMode.OPTIONAL)
+ .add("civil_twilight_begin", TypeProtos.MinorType.VARCHAR,
TypeProtos.DataMode.OPTIONAL)
+ .add("civil_twilight_end", TypeProtos.MinorType.VARCHAR,
TypeProtos.DataMode.OPTIONAL)
+ .add("nautical_twilight_begin", TypeProtos.MinorType.VARCHAR,
TypeProtos.DataMode.OPTIONAL)
+ .add("nautical_twilight_end", TypeProtos.MinorType.VARCHAR,
TypeProtos.DataMode.OPTIONAL)
+ .add("astronomical_twilight_begin", TypeProtos.MinorType.VARCHAR,
TypeProtos.DataMode.OPTIONAL)
+ .add("astronomical_twilight_end", TypeProtos.MinorType.VARCHAR,
TypeProtos.DataMode.OPTIONAL)
+ .resumeSchema()
+ .add("status", TypeProtos.MinorType.VARCHAR,
TypeProtos.DataMode.OPTIONAL)
+ .build();
+
+ RowSet expected = new RowSetBuilder(client.allocator(), expectedSchema)
+ .addRow(mapValue("6:13:58 AM", "5:59:55 PM", "12:06:56 PM",
"11:45:57", "5:48:14 AM", "6:25:38 PM", "5:18:16 AM", "6:55:36 PM", "4:48:07
AM", "7:25:45 PM"), "OK")
+ .build();
+
+ RowSetUtilities.verify(expected, results);
+
+ RecordedRequest recordedRequest = server.takeRequest();
+ assertEquals("POST", recordedRequest.getMethod());
+ String resultJsonString = recordedRequest.getBody().toString();
+ assertEquals("[text={\"key1\":\"value1\",\"key2\":\"value2\"}]",
resultJsonString);
+ }
+ }
+
+ @Test
+ public void testJsonPostWithFiltersAndMockServer() throws Exception {
+ try (MockWebServer server = startServer()) {
+ server.enqueue(
+ new MockResponse()
+ .setResponseCode(200)
+ .setBody(TEST_JSON_RESPONSE)
+ );
+
+ String sql = "SELECT * FROM local.mockJsonPost WHERE lat=36.7201600 AND
lng=-4.4203400";
+ RowSet results = client.queryBuilder().sql(sql).rowSet();
+
+ TupleMetadata expectedSchema = new SchemaBuilder()
+ .addMap("results")
+ .add("sunrise", TypeProtos.MinorType.VARCHAR,
TypeProtos.DataMode.OPTIONAL)
+ .add("sunset", TypeProtos.MinorType.VARCHAR,
TypeProtos.DataMode.OPTIONAL)
+ .add("solar_noon", TypeProtos.MinorType.VARCHAR,
TypeProtos.DataMode.OPTIONAL)
+ .add("day_length", TypeProtos.MinorType.VARCHAR,
TypeProtos.DataMode.OPTIONAL)
+ .add("civil_twilight_begin", TypeProtos.MinorType.VARCHAR,
TypeProtos.DataMode.OPTIONAL)
+ .add("civil_twilight_end", TypeProtos.MinorType.VARCHAR,
TypeProtos.DataMode.OPTIONAL)
+ .add("nautical_twilight_begin", TypeProtos.MinorType.VARCHAR,
TypeProtos.DataMode.OPTIONAL)
+ .add("nautical_twilight_end", TypeProtos.MinorType.VARCHAR,
TypeProtos.DataMode.OPTIONAL)
+ .add("astronomical_twilight_begin", TypeProtos.MinorType.VARCHAR,
TypeProtos.DataMode.OPTIONAL)
+ .add("astronomical_twilight_end", TypeProtos.MinorType.VARCHAR,
TypeProtos.DataMode.OPTIONAL)
+ .resumeSchema()
+ .add("status", TypeProtos.MinorType.VARCHAR,
TypeProtos.DataMode.OPTIONAL)
+ .build();
+
+ RowSet expected = new RowSetBuilder(client.allocator(), expectedSchema)
+ .addRow(mapValue("6:13:58 AM", "5:59:55 PM", "12:06:56 PM",
"11:45:57", "5:48:14 AM", "6:25:38 PM", "5:18:16 AM", "6:55:36 PM", "4:48:07
AM", "7:25:45 PM"), "OK")
+ .build();
+
+ RowSetUtilities.verify(expected, results);
+
+ RecordedRequest recordedRequest = server.takeRequest();
+ assertEquals("POST", recordedRequest.getMethod());
+ String resultJsonString = recordedRequest.getBody().toString();
+ assertEquals("[size=71
text={\"key1\":\"value1\",\"key2\":\"value2\",\"lng\":\"-4.4203400\",\"lat\":\"36.72…]",
resultJsonString);
+ }
+ }
+
+ @Test
+ public void testJsonPostWithFiltersAndNullPostBodyMockServer() throws
Exception {
+ try (MockWebServer server = startServer()) {
+ server.enqueue(
+ new MockResponse()
+ .setResponseCode(200)
+ .setBody(TEST_JSON_RESPONSE)
+ );
+
+ String sql = "SELECT * FROM local.mockJsonNullBodyPost WHERE
lat=36.7201600 AND lng=-4.4203400";
+ RowSet results = client.queryBuilder().sql(sql).rowSet();
+
+ TupleMetadata expectedSchema = new SchemaBuilder()
+ .addMap("results")
+ .add("sunrise", TypeProtos.MinorType.VARCHAR,
TypeProtos.DataMode.OPTIONAL)
+ .add("sunset", TypeProtos.MinorType.VARCHAR,
TypeProtos.DataMode.OPTIONAL)
+ .add("solar_noon", TypeProtos.MinorType.VARCHAR,
TypeProtos.DataMode.OPTIONAL)
+ .add("day_length", TypeProtos.MinorType.VARCHAR,
TypeProtos.DataMode.OPTIONAL)
+ .add("civil_twilight_begin", TypeProtos.MinorType.VARCHAR,
TypeProtos.DataMode.OPTIONAL)
+ .add("civil_twilight_end", TypeProtos.MinorType.VARCHAR,
TypeProtos.DataMode.OPTIONAL)
+ .add("nautical_twilight_begin", TypeProtos.MinorType.VARCHAR,
TypeProtos.DataMode.OPTIONAL)
+ .add("nautical_twilight_end", TypeProtos.MinorType.VARCHAR,
TypeProtos.DataMode.OPTIONAL)
+ .add("astronomical_twilight_begin", TypeProtos.MinorType.VARCHAR,
TypeProtos.DataMode.OPTIONAL)
+ .add("astronomical_twilight_end", TypeProtos.MinorType.VARCHAR,
TypeProtos.DataMode.OPTIONAL)
+ .resumeSchema()
+ .add("status", TypeProtos.MinorType.VARCHAR,
TypeProtos.DataMode.OPTIONAL)
+ .build();
+
+ RowSet expected = new RowSetBuilder(client.allocator(), expectedSchema)
+ .addRow(mapValue("6:13:58 AM", "5:59:55 PM", "12:06:56 PM",
"11:45:57", "5:48:14 AM", "6:25:38 PM", "5:18:16 AM", "6:55:36 PM", "4:48:07
AM", "7:25:45 PM"), "OK")
+ .build();
+
+ RowSetUtilities.verify(expected, results);
+
+ RecordedRequest recordedRequest = server.takeRequest();
+ assertEquals("POST", recordedRequest.getMethod());
+ String resultJsonString = recordedRequest.getBody().toString();
+ assertEquals("[text={\"lng\":\"-4.4203400\",\"lat\":\"36.7201600\"}]",
resultJsonString);
+ }
+ }
+
+ @Test
+ public void testParamsInPostBody() throws Exception {
+ try (MockWebServer server = startServer()) {
+ server.enqueue(
+ new MockResponse()
+ .setResponseCode(200)
+ .setBody(TEST_JSON_RESPONSE)
+ );
+
+ String sql = "SELECT * FROM local.mockPostPushdown WHERE lat=36.7201600
AND lng=-4.4203400";
+ RowSet results = client.queryBuilder().sql(sql).rowSet();
+
+ TupleMetadata expectedSchema = new SchemaBuilder()
+ .addMap("results")
+ .add("sunrise", TypeProtos.MinorType.VARCHAR,
TypeProtos.DataMode.OPTIONAL)
+ .add("sunset", TypeProtos.MinorType.VARCHAR,
TypeProtos.DataMode.OPTIONAL)
+ .add("solar_noon", TypeProtos.MinorType.VARCHAR,
TypeProtos.DataMode.OPTIONAL)
+ .add("day_length", TypeProtos.MinorType.VARCHAR,
TypeProtos.DataMode.OPTIONAL)
+ .add("civil_twilight_begin", TypeProtos.MinorType.VARCHAR,
TypeProtos.DataMode.OPTIONAL)
+ .add("civil_twilight_end", TypeProtos.MinorType.VARCHAR,
TypeProtos.DataMode.OPTIONAL)
+ .add("nautical_twilight_begin", TypeProtos.MinorType.VARCHAR,
TypeProtos.DataMode.OPTIONAL)
+ .add("nautical_twilight_end", TypeProtos.MinorType.VARCHAR,
TypeProtos.DataMode.OPTIONAL)
+ .add("astronomical_twilight_begin", TypeProtos.MinorType.VARCHAR,
TypeProtos.DataMode.OPTIONAL)
+ .add("astronomical_twilight_end", TypeProtos.MinorType.VARCHAR,
TypeProtos.DataMode.OPTIONAL)
+ .resumeSchema()
+ .add("status", TypeProtos.MinorType.VARCHAR,
TypeProtos.DataMode.OPTIONAL)
+ .build();
+
+ RowSet expected = new RowSetBuilder(client.allocator(), expectedSchema)
+ .addRow(mapValue("6:13:58 AM", "5:59:55 PM", "12:06:56 PM",
"11:45:57", "5:48:14 AM", "6:25:38 PM", "5:18:16 AM", "6:55:36 PM", "4:48:07
AM", "7:25:45 PM"), "OK")
+ .build();
+
+ RowSetUtilities.verify(expected, results);
+
+ RecordedRequest recordedRequest = server.takeRequest();
+ assertEquals("POST", recordedRequest.getMethod());
+ String resultJsonString = recordedRequest.getBody().toString();
+ assertEquals("[text=lng=-4.4203400&lat=36.7201600]", resultJsonString);
+ }
+ }
+
+ @Test
+ public void testParamsInPostBodyAndStaticParams() throws Exception {
Review comment:
Thanks for adding these great unit tests.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]