Search in sources :

Example 56 with BrokerRequest

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;
}
Also used : BrokerRequest(com.linkedin.pinot.common.request.BrokerRequest) Nonnull(javax.annotation.Nonnull)

Example 57 with BrokerRequest

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;
}
Also used : BrokerRequest(com.linkedin.pinot.common.request.BrokerRequest) Nonnull(javax.annotation.Nonnull)

Example 58 with BrokerRequest

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;
}
Also used : Pql2Compiler(com.linkedin.pinot.pql.parsers.Pql2Compiler) BrokerRequest(com.linkedin.pinot.common.request.BrokerRequest) BrokerRequestHandler(com.linkedin.pinot.broker.requesthandler.BrokerRequestHandler)

Example 59 with BrokerRequest

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);
}
Also used : FilterQueryTree(com.linkedin.pinot.common.utils.request.FilterQueryTree) Pql2Compiler(com.linkedin.pinot.pql.parsers.Pql2Compiler) BrokerRequest(com.linkedin.pinot.common.request.BrokerRequest) Test(org.testng.annotations.Test)

Example 60 with BrokerRequest

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);
}
Also used : FilterQueryTree(com.linkedin.pinot.common.utils.request.FilterQueryTree) Pql2Compiler(com.linkedin.pinot.pql.parsers.Pql2Compiler) BrokerRequest(com.linkedin.pinot.common.request.BrokerRequest) Test(org.testng.annotations.Test)

Aggregations

BrokerRequest (com.linkedin.pinot.common.request.BrokerRequest)77 Test (org.testng.annotations.Test)38 InstanceRequest (com.linkedin.pinot.common.request.InstanceRequest)33 DataTable (com.linkedin.pinot.common.utils.DataTable)33 QueryRequest (com.linkedin.pinot.common.query.QueryRequest)31 HashMap (java.util.HashMap)24 ServerInstance (com.linkedin.pinot.common.response.ServerInstance)23 AggregationInfo (com.linkedin.pinot.common.request.AggregationInfo)22 BrokerResponseNative (com.linkedin.pinot.common.response.broker.BrokerResponseNative)22 ArrayList (java.util.ArrayList)22 QuerySource (com.linkedin.pinot.common.request.QuerySource)18 IndexSegment (com.linkedin.pinot.core.indexsegment.IndexSegment)13 Pql2Compiler (com.linkedin.pinot.pql.parsers.Pql2Compiler)10 FilterQuery (com.linkedin.pinot.common.request.FilterQuery)9 FilterQueryTree (com.linkedin.pinot.common.utils.request.FilterQueryTree)7 AggregationResult (com.linkedin.pinot.common.response.broker.AggregationResult)6 GroupBy (com.linkedin.pinot.common.request.GroupBy)4 Nonnull (javax.annotation.Nonnull)4 AfterTest (org.testng.annotations.AfterTest)4 BeforeTest (org.testng.annotations.BeforeTest)4