|
31 | 31 |
|
32 | 32 | import static java.util.Arrays.asList;
|
33 | 33 | import static java.util.Collections.emptyList;
|
| 34 | +import static java.util.Collections.emptySet; |
34 | 35 | import static java.util.Collections.unmodifiableList;
|
35 | 36 | import static org.elasticsearch.rest.RestRequest.Method.GET;
|
36 | 37 | import static org.elasticsearch.rest.RestRequest.Method.POST;
|
|
39 | 40 |
|
40 | 41 | public class RestSqlQueryAction extends BaseRestHandler {
|
41 | 42 |
|
42 |
| - TextFormat textFormat; |
43 |
| - |
44 | 43 | @Override
|
45 | 44 | public List<Route> routes() {
|
46 | 45 | return emptyList();
|
@@ -106,13 +105,23 @@ protected RestChannelConsumer prepareRequest(RestRequest request, NodeClient cli
|
106 | 105 | * which we turn into a 400 error.
|
107 | 106 | */
|
108 | 107 | XContentType xContentType = accept == null ? XContentType.JSON : XContentType.fromMediaTypeOrFormat(accept);
|
109 |
| - textFormat = xContentType == null ? TextFormat.fromMediaTypeOrFormat(accept) : null; |
| 108 | + TextFormat textFormat = xContentType == null ? TextFormat.fromMediaTypeOrFormat(accept) : null; |
110 | 109 |
|
111 | 110 | if (xContentType == null && sqlRequest.columnar()) {
|
112 | 111 | throw new IllegalArgumentException("Invalid use of [columnar] argument: cannot be used in combination with "
|
113 | 112 | + "txt, csv or tsv formats");
|
114 | 113 | }
|
115 | 114 |
|
| 115 | + /* |
| 116 | + * Special handling for the "delimiter" parameter which should only be |
| 117 | + * checked for being present or not in the case of CSV format. We cannot |
| 118 | + * override {@link BaseRestHandler#responseParams()} because this |
| 119 | + * parameter should only be checked for CSV, not always. |
| 120 | + */ |
| 121 | + if ((textFormat == null || textFormat != TextFormat.CSV) && request.hasParam(URL_PARAM_DELIMITER)) { |
| 122 | + throw new IllegalArgumentException(unrecognized(request, Collections.singleton(URL_PARAM_DELIMITER), emptySet(), "parameter")); |
| 123 | + } |
| 124 | + |
116 | 125 | long startNanos = System.nanoTime();
|
117 | 126 | return channel -> client.execute(SqlQueryAction.INSTANCE, sqlRequest, new RestResponseListener<SqlQueryResponse>(channel) {
|
118 | 127 | @Override
|
@@ -145,7 +154,7 @@ public RestResponse buildResponse(SqlQueryResponse response) throws Exception {
|
145 | 154 |
|
146 | 155 | @Override
|
147 | 156 | protected Set<String> responseParams() {
|
148 |
| - return textFormat == TextFormat.CSV ? Collections.singleton(URL_PARAM_DELIMITER) : Collections.emptySet(); |
| 157 | + return Collections.singleton(URL_PARAM_DELIMITER); |
149 | 158 | }
|
150 | 159 |
|
151 | 160 | @Override
|
|
0 commit comments