This is an automated email from the ASF dual-hosted git repository.
mayanks pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/pinot.git
The following commit(s) were added to refs/heads/master by this push:
new dcddb9ff02 Adding dropResults parameter in queryOptions to drop the
resultTable field from the response (#10419)
dcddb9ff02 is described below
commit dcddb9ff02c8aca4ee1d5276032d54e0b8c05248
Author: soumitra-st <[email protected]>
AuthorDate: Thu Mar 16 13:41:44 2023 -0700
Adding dropResults parameter in queryOptions to drop the resultTable field
from the response (#10419)
* Adding dropResults parameter in queryOptions to drop the resultTable
field from the response.
* Incorporated review feedbacks
* Incorporated review feedbacks
---
.../broker/requesthandler/BaseBrokerRequestHandler.java | 13 ++++++++++++-
.../common/response/broker/BrokerResponseNative.java | 5 ++++-
.../pinot/common/utils/config/QueryOptionsUtils.java | 5 +++++
.../org/apache/pinot/integration/tests/ClusterTest.java | 10 ++++++++++
.../integration/tests/HybridClusterIntegrationTest.java | 15 +++++++++++++++
.../java/org/apache/pinot/spi/utils/CommonConstants.java | 2 ++
6 files changed, 48 insertions(+), 2 deletions(-)
diff --git
a/pinot-broker/src/main/java/org/apache/pinot/broker/requesthandler/BaseBrokerRequestHandler.java
b/pinot-broker/src/main/java/org/apache/pinot/broker/requesthandler/BaseBrokerRequestHandler.java
index 703de7cc38..5eaa87a2f9 100644
---
a/pinot-broker/src/main/java/org/apache/pinot/broker/requesthandler/BaseBrokerRequestHandler.java
+++
b/pinot-broker/src/main/java/org/apache/pinot/broker/requesthandler/BaseBrokerRequestHandler.java
@@ -250,7 +250,18 @@ public abstract class BaseBrokerRequestHandler implements
BrokerRequestHandler {
}
String query = sql.asText();
requestContext.setQuery(query);
- return handleRequest(requestId, query, sqlNodeAndOptions, request,
requesterIdentity, requestContext);
+ BrokerResponse brokerResponse = handleRequest(requestId, query,
sqlNodeAndOptions, request,
+ requesterIdentity, requestContext);
+
+ if (request.has(Broker.Request.QUERY_OPTIONS)) {
+ String queryOptions = request.get(Broker.Request.QUERY_OPTIONS).asText();
+ Map<String, String> optionsFromString =
RequestUtils.getOptionsFromString(queryOptions);
+ if (QueryOptionsUtils.shouldDropResults(optionsFromString)) {
+ brokerResponse.setResultTable(null);
+ }
+ }
+
+ return brokerResponse;
}
private BrokerResponseNative handleRequest(long requestId, String query,
diff --git
a/pinot-common/src/main/java/org/apache/pinot/common/response/broker/BrokerResponseNative.java
b/pinot-common/src/main/java/org/apache/pinot/common/response/broker/BrokerResponseNative.java
index 9c06d54b76..76ed75a466 100644
---
a/pinot-common/src/main/java/org/apache/pinot/common/response/broker/BrokerResponseNative.java
+++
b/pinot-common/src/main/java/org/apache/pinot/common/response/broker/BrokerResponseNative.java
@@ -321,7 +321,10 @@ public class BrokerResponseNative implements
BrokerResponse {
@Override
public void setResultTable(ResultTable resultTable) {
_resultTable = resultTable;
- _numRowsResultSet = resultTable.getRows().size();
+ // If query level parameter is set to not return the results, then
resultTable will be null.
+ if (resultTable != null) {
+ _numRowsResultSet = resultTable.getRows().size();
+ }
}
@JsonProperty("exceptions")
diff --git
a/pinot-common/src/main/java/org/apache/pinot/common/utils/config/QueryOptionsUtils.java
b/pinot-common/src/main/java/org/apache/pinot/common/utils/config/QueryOptionsUtils.java
index 420924af0a..2682eb927a 100644
---
a/pinot-common/src/main/java/org/apache/pinot/common/utils/config/QueryOptionsUtils.java
+++
b/pinot-common/src/main/java/org/apache/pinot/common/utils/config/QueryOptionsUtils.java
@@ -25,6 +25,7 @@ import java.lang.reflect.Modifier;
import java.util.HashMap;
import java.util.Map;
import javax.annotation.Nullable;
+import org.apache.pinot.spi.utils.CommonConstants;
import
org.apache.pinot.spi.utils.CommonConstants.Broker.Request.QueryOptionKey;
import
org.apache.pinot.spi.utils.CommonConstants.Broker.Request.QueryOptionValue;
@@ -190,4 +191,8 @@ public class QueryOptionsUtils {
String groupByTrimThreshold =
queryOptions.get(QueryOptionKey.GROUP_TRIM_THRESHOLD);
return groupByTrimThreshold != null ?
Integer.parseInt(groupByTrimThreshold) : null;
}
+
+ public static boolean shouldDropResults(Map<String, String> queryOptions) {
+ return
Boolean.parseBoolean(queryOptions.get(CommonConstants.Broker.Request.QueryOptionKey.DROP_RESULTS));
+ }
}
diff --git
a/pinot-integration-test-base/src/test/java/org/apache/pinot/integration/tests/ClusterTest.java
b/pinot-integration-test-base/src/test/java/org/apache/pinot/integration/tests/ClusterTest.java
index 2e80dbf1ec..f8030eac78 100644
---
a/pinot-integration-test-base/src/test/java/org/apache/pinot/integration/tests/ClusterTest.java
+++
b/pinot-integration-test-base/src/test/java/org/apache/pinot/integration/tests/ClusterTest.java
@@ -465,6 +465,16 @@ public abstract class ClusterTest extends ControllerTest {
return JsonUtils.stringToJsonNode(sendPostRequest(brokerBaseApiUrl +
"/query/sql", payload.toString(), headers));
}
+ /**
+ * Queries the broker's sql query endpoint (/query/sql) using query and
queryOptions strings
+ */
+ protected JsonNode postQueryWithOptions(String query, String queryOptions)
throws Exception {
+ ObjectNode payload = JsonUtils.newObjectNode();
+ payload.put("sql", query);
+ payload.put("queryOptions", queryOptions);
+ return JsonUtils.stringToJsonNode(sendPostRequest(_brokerBaseApiUrl +
"/query/sql", payload.toString(), null));
+ }
+
/**
* Queries the controller's sql query endpoint (/query/sql)
*/
diff --git
a/pinot-integration-tests/src/test/java/org/apache/pinot/integration/tests/HybridClusterIntegrationTest.java
b/pinot-integration-tests/src/test/java/org/apache/pinot/integration/tests/HybridClusterIntegrationTest.java
index 422672c9d9..dca17e1089 100644
---
a/pinot-integration-tests/src/test/java/org/apache/pinot/integration/tests/HybridClusterIntegrationTest.java
+++
b/pinot-integration-tests/src/test/java/org/apache/pinot/integration/tests/HybridClusterIntegrationTest.java
@@ -210,6 +210,21 @@ public class HybridClusterIntegrationTest extends
BaseClusterIntegrationTestSet
Assert.assertTrue(traceInfo.has("localhost_R"));
}
+ @Test
+ public void testDropResults() throws Exception {
+ final String query = String.format("SELECT * FROM %s limit 10",
getTableName());
+ final String resultTag = "resultTable";
+
+ // dropResults=true - resultTable must not be in the response
+ Assert.assertFalse(postQueryWithOptions(query,
"dropResults=true").has(resultTag));
+
+ // dropResults=TrUE (case insensitive match) - resultTable must not be in
the response
+ Assert.assertFalse(postQueryWithOptions(query,
"dropResults=TrUE").has(resultTag));
+
+ // dropResults=truee - (anything other than true, is taken as false) -
resultTable must be in the response
+ Assert.assertTrue(postQueryWithOptions(query,
"dropResults=truee").has(resultTag));
+ }
+
@Test
@Override
public void testHardcodedQueries()
diff --git
a/pinot-spi/src/main/java/org/apache/pinot/spi/utils/CommonConstants.java
b/pinot-spi/src/main/java/org/apache/pinot/spi/utils/CommonConstants.java
index 484da1409d..46b0474d26 100644
--- a/pinot-spi/src/main/java/org/apache/pinot/spi/utils/CommonConstants.java
+++ b/pinot-spi/src/main/java/org/apache/pinot/spi/utils/CommonConstants.java
@@ -317,6 +317,8 @@ public class CommonConstants {
// Handle IN predicate evaluation for big IN lists
public static final String IN_PREDICATE_SORT_THRESHOLD =
"inPredicateSortThreshold";
+ public static final String DROP_RESULTS = "dropResults";
+
// TODO: Remove these keys (only apply to PQL) after releasing 0.11.0
@Deprecated
public static final String PRESERVE_TYPE = "preserveType";
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]