use of com.linkedin.pinot.common.request.BrokerRequest in project pinot by linkedin.
the class BrokerRequestHandler method getRealtimeBrokerRequest.
/**
* Given a broker request, use it to create a realtime broker request.
*
* @param brokerRequest original broker request.
* @return realtime broker request.
*/
@Nonnull
private BrokerRequest getRealtimeBrokerRequest(@Nonnull BrokerRequest brokerRequest) {
BrokerRequest realtimeRequest = brokerRequest.deepCopy();
String hybridTableName = brokerRequest.getQuerySource().getTableName();
String realtimeTableName = TableNameBuilder.REALTIME_TABLE_NAME_BUILDER.forTable(hybridTableName);
realtimeRequest.getQuerySource().setTableName(realtimeTableName);
attachTimeBoundary(hybridTableName, realtimeRequest, false);
return realtimeRequest;
}
use of com.linkedin.pinot.common.request.BrokerRequest in project pinot by linkedin.
the class BrokerRequestHandler method getOfflineBrokerRequest.
/**
* Given a broker request, use it to create an offline broker request.
*
* @param brokerRequest original broker request.
* @return offline broker request.
*/
@Nonnull
private BrokerRequest getOfflineBrokerRequest(@Nonnull BrokerRequest brokerRequest) {
BrokerRequest offlineRequest = brokerRequest.deepCopy();
String hybridTableName = brokerRequest.getQuerySource().getTableName();
String offlineTableName = TableNameBuilder.OFFLINE_TABLE_NAME_BUILDER.forTable(hybridTableName);
offlineRequest.getQuerySource().setTableName(offlineTableName);
attachTimeBoundary(hybridTableName, offlineRequest, true);
return offlineRequest;
}
use of com.linkedin.pinot.common.request.BrokerRequest in project pinot by linkedin.
the class BrokerRequestValidationTest method runQuery.
/**
* Helper method to run the query.
*
* @param query
* @return Returns exception string if any, null otherwise.
* @throws Exception
*/
private String runQuery(String query) throws Exception {
BrokerRequestHandler brokerRequestHandler = brokerBuilder.getBrokerRequestHandler();
Pql2Compiler compiler = new Pql2Compiler();
BrokerRequest brokerRequest = compiler.compileToBrokerRequest(query);
String exceptionMessage = null;
try {
brokerRequestHandler.validateRequest(brokerRequest);
} catch (Exception e) {
exceptionMessage = e.getMessage();
}
return exceptionMessage;
}
use of com.linkedin.pinot.common.request.BrokerRequest in project pinot by linkedin.
the class FilterOptimizerTest method testPositive.
// Testing positive cases of flattening the query tree.
@Test
public void testPositive() throws Exception {
Pql2Compiler pql2Compiler = new Pql2Compiler();
BrokerRequest req;
String timeColumn = null;
FilterQueryTree tree;
int numLeaves;
int numOps;
req = pql2Compiler.compileToBrokerRequest("SELECT * FROM T WHERE (A = 4 AND B = 5) AND (C=7)");
tree = RequestUtils.generateFilterQueryTree(_optimizer.optimize(req, timeColumn));
Assert.assertEquals(tree.getChildren().size(), 3);
Assert.assertEquals(tree.getOperator(), FilterOperator.AND);
for (FilterQueryTree node : tree.getChildren()) {
Assert.assertNull(node.getChildren());
Assert.assertEquals(node.getOperator(), FilterOperator.EQUALITY);
}
req = pql2Compiler.compileToBrokerRequest("SELECT * FROM T WHERE ((A = 4 AND B = 5) AND (C=7)) AND D=8");
tree = RequestUtils.generateFilterQueryTree(_optimizer.optimize(req, timeColumn));
Assert.assertEquals(tree.getChildren().size(), 4);
Assert.assertEquals(tree.getOperator(), FilterOperator.AND);
for (FilterQueryTree node : tree.getChildren()) {
Assert.assertNull(node.getChildren());
Assert.assertEquals(node.getOperator(), FilterOperator.EQUALITY);
}
req = pql2Compiler.compileToBrokerRequest("SELECT * FROM T WHERE (A = 4 OR B = 5) OR (C=7)");
tree = RequestUtils.generateFilterQueryTree(_optimizer.optimize(req, timeColumn));
Assert.assertEquals(tree.getChildren().size(), 3);
Assert.assertEquals(tree.getOperator(), FilterOperator.OR);
for (FilterQueryTree node : tree.getChildren()) {
Assert.assertNull(node.getChildren());
Assert.assertEquals(node.getOperator(), FilterOperator.EQUALITY);
}
req = pql2Compiler.compileToBrokerRequest("SELECT * FROM T WHERE ((A = 4 OR B = 5) OR (C=7)) OR D=8");
tree = RequestUtils.generateFilterQueryTree(_optimizer.optimize(req, timeColumn));
Assert.assertEquals(tree.getChildren().size(), 4);
Assert.assertEquals(tree.getOperator(), FilterOperator.OR);
for (FilterQueryTree node : tree.getChildren()) {
Assert.assertNull(node.getChildren());
Assert.assertEquals(node.getOperator(), FilterOperator.EQUALITY);
}
// 3-level test case
req = pql2Compiler.compileToBrokerRequest("SELECT * FROM T WHERE ((A = 4 OR (B = 5 OR D = 9)) OR (C=7)) OR E=8");
tree = RequestUtils.generateFilterQueryTree(_optimizer.optimize(req, timeColumn));
Assert.assertEquals(tree.getChildren().size(), 5);
Assert.assertEquals(tree.getOperator(), FilterOperator.OR);
for (FilterQueryTree node : tree.getChildren()) {
Assert.assertNull(node.getChildren());
Assert.assertEquals(node.getOperator(), FilterOperator.EQUALITY);
}
// Mixed case.
req = pql2Compiler.compileToBrokerRequest("SELECT * FROM T WHERE ((A = 4 OR (B = 5 AND D = 9)) OR (C=7)) OR E=8");
tree = RequestUtils.generateFilterQueryTree(_optimizer.optimize(req, timeColumn));
Assert.assertEquals(tree.getChildren().size(), 4);
Assert.assertEquals(tree.getOperator(), FilterOperator.OR);
numLeaves = 0;
numOps = 0;
for (FilterQueryTree node : tree.getChildren()) {
if (node.getOperator().equals(FilterOperator.EQUALITY)) {
Assert.assertNull(node.getChildren());
numLeaves++;
} else {
Assert.assertNotNull(node.getChildren());
Assert.assertEquals(node.getOperator(), FilterOperator.AND);
numOps++;
}
}
Assert.assertEquals(1, numOps);
Assert.assertEquals(3, numLeaves);
final int maxNodesAtTopLevel = FlattenNestedPredicatesFilterQueryTreeOptimizer.MAX_OPTIMIZING_DEPTH;
String whereClause = constructWhereClause(FilterOperator.OR, maxNodesAtTopLevel + 50);
req = pql2Compiler.compileToBrokerRequest("SELECT * FROM T WHERE " + whereClause);
tree = RequestUtils.generateFilterQueryTree(_optimizer.optimize(req, timeColumn));
Assert.assertEquals(tree.getChildren().size(), maxNodesAtTopLevel + 1);
Assert.assertEquals(tree.getOperator(), FilterOperator.OR);
numLeaves = 0;
numOps = 0;
for (FilterQueryTree node : tree.getChildren()) {
if (node.getOperator().equals(FilterOperator.EQUALITY)) {
Assert.assertNull(node.getChildren());
numLeaves++;
} else {
Assert.assertNotNull(node.getChildren());
numOps++;
}
}
Assert.assertEquals(maxNodesAtTopLevel, numLeaves);
Assert.assertEquals(1, numOps);
}
use of com.linkedin.pinot.common.request.BrokerRequest in project pinot by linkedin.
the class FilterOptimizerTest method testNegative.
// Tests cases where we should not do any flattening.
@Test
public void testNegative() throws Exception {
Pql2Compiler pql2Compiler = new Pql2Compiler();
BrokerRequest req;
FilterQueryTree tree;
int numLeaves;
int numOps;
req = pql2Compiler.compileToBrokerRequest("SELECT * FROM T WHERE (A = 4 AND (B = 5 OR D = 9))");
tree = RequestUtils.generateFilterQueryTree(_optimizer.optimize(req, null));
Assert.assertEquals(tree.getChildren().size(), 2);
Assert.assertEquals(tree.getOperator(), FilterOperator.AND);
numOps = 0;
numLeaves = 0;
for (FilterQueryTree node : tree.getChildren()) {
if (node.getOperator().equals(FilterOperator.OR)) {
Assert.assertEquals(2, node.getChildren().size());
numOps++;
} else {
numLeaves++;
}
}
Assert.assertEquals(1, numOps);
Assert.assertEquals(1, numLeaves);
}
Aggregations