Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,18 @@ public BrokerResponse handleRequest(JsonNode request, @Nullable SqlNodeAndOption
}
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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,10 @@ public ResultTable getResultTable() {
@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")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
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;

Expand Down Expand Up @@ -190,4 +191,8 @@ public static Integer getGroupTrimThreshold(Map<String, String> queryOptions) {
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));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -465,6 +465,16 @@ public static JsonNode postQuery(String query, String brokerBaseApiUrl, Map<Stri
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)
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,21 @@ public void testQueryTracing()
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()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,8 @@ public static class QueryOptionKey {
// 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";
Expand Down