@Test public void testMergeRangeFilter() { String query = "SELECT * FROM testTable WHERE (int > 10 AND int <= 100 AND int BETWEEN 10 AND 20) OR (float BETWEEN 5.5 AND 7.5 AND float = 6 AND float < 6.5 AND float BETWEEN 6 AND 8) OR (string > '123' AND string > '23') OR (mvInt > 5 AND mvInt < 0)"; BrokerRequest sqlBrokerRequest = SQL_COMPILER.compileToBrokerRequest(query); PinotQuery pinotQuery = sqlBrokerRequest.getPinotQuery(); BrokerRequest pqlBrokerRequest = PQL_COMPILER.compileToBrokerRequest(query); for (BrokerRequest brokerRequest : Arrays.asList(sqlBrokerRequest, pqlBrokerRequest)) { OPTIMIZER.optimize(brokerRequest, SCHEMA); FilterQueryTree filterQueryTree = RequestUtils.buildFilterQuery(brokerRequest.getFilterQuery().getId(), brokerRequest.getFilterSubQueryMap().getFilterQueryMap()); assertEquals(filterQueryTree.getOperator(), FilterOperator.OR); List<FilterQueryTree> children = filterQueryTree.getChildren(); assertEquals(children.size(), 4); assertEquals(children.get(0).toString(), "int RANGE [(10\t\t20]]"); assertEquals(children.get(2).toString(), "string RANGE [(23\t\t*)]"); FilterQueryTree secondChild = children.get(1); assertEquals(secondChild.getOperator(), FilterOperator.AND); assertEquals(secondChild.getChildren().size(), 2); assertEquals(secondChild.getChildren().get(0).toString(), "float EQUALITY [6]"); assertEquals(secondChild.getChildren().get(1).toString(), "float RANGE [[6.0\t\t6.5)]"); FilterQueryTree fourthChild = children.get(3); assertEquals(fourthChild.getOperator(), FilterOperator.AND); assertEquals(fourthChild.getChildren().size(), 2); assertEquals(fourthChild.getChildren().get(0).toString(), "mvInt RANGE [(5\t\t*)]"); assertEquals(fourthChild.getChildren().get(1).toString(), "mvInt RANGE [(*\t\t0)]"); } OPTIMIZER.optimize(pinotQuery, SCHEMA); Function filterFunction = pinotQuery.getFilterExpression().getFunctionCall(); assertEquals(filterFunction.getOperator(), FilterKind.OR.name()); List<Expression> operands = filterFunction.getOperands(); assertEquals(operands.size(), 4); assertEquals(operands.get(0), getRangeFilterExpression("int", "(10\t\t20]")); assertEquals(operands.get(2), getRangeFilterExpression("string", "(23\t\t*)")); Function secondChildFunction = operands.get(1).getFunctionCall(); assertEquals(secondChildFunction.getOperator(), FilterKind.AND.name()); List<Expression> secondChildChildren = secondChildFunction.getOperands(); assertEquals(secondChildChildren.size(), 2); assertEquals(secondChildChildren.get(0), getEqFilterExpression("float", 6)); assertEquals(secondChildChildren.get(1), getRangeFilterExpression("float", "[6.0\t\t6.5)")); Function fourthChildFunction = operands.get(3).getFunctionCall(); assertEquals(fourthChildFunction.getOperator(), FilterKind.AND.name()); List<Expression> fourthChildChildren = fourthChildFunction.getOperands(); assertEquals(fourthChildChildren.size(), 2); assertEquals(fourthChildChildren.get(0).getFunctionCall().getOperator(), FilterKind.GREATER_THAN.name()); assertEquals(fourthChildChildren.get(1).getFunctionCall().getOperator(), FilterKind.LESS_THAN.name()); }
public void optimize(BrokerRequest brokerRequest, @Nullable Schema schema) { FilterQuery filterQuery = brokerRequest.getFilterQuery(); if (filterQuery != null) { FilterQueryTree filterQueryTree = RequestUtils.buildFilterQuery(filterQuery.getId(), brokerRequest.getFilterSubQueryMap().getFilterQueryMap()); for (FilterOptimizer filterOptimizer : FILTER_OPTIMIZERS) { filterQueryTree = filterOptimizer.optimize(filterQueryTree, schema); } RequestUtils.generateFilterFromTree(filterQueryTree, brokerRequest); } }
QueryOptimizer { public void optimize(BrokerRequest brokerRequest, @Nullable Schema schema) { FilterQuery filterQuery = brokerRequest.getFilterQuery(); if (filterQuery != null) { FilterQueryTree filterQueryTree = RequestUtils.buildFilterQuery(filterQuery.getId(), brokerRequest.getFilterSubQueryMap().getFilterQueryMap()); for (FilterOptimizer filterOptimizer : FILTER_OPTIMIZERS) { filterQueryTree = filterOptimizer.optimize(filterQueryTree, schema); } RequestUtils.generateFilterFromTree(filterQueryTree, brokerRequest); } } }
QueryOptimizer { public void optimize(BrokerRequest brokerRequest, @Nullable Schema schema) { FilterQuery filterQuery = brokerRequest.getFilterQuery(); if (filterQuery != null) { FilterQueryTree filterQueryTree = RequestUtils.buildFilterQuery(filterQuery.getId(), brokerRequest.getFilterSubQueryMap().getFilterQueryMap()); for (FilterOptimizer filterOptimizer : FILTER_OPTIMIZERS) { filterQueryTree = filterOptimizer.optimize(filterQueryTree, schema); } RequestUtils.generateFilterFromTree(filterQueryTree, brokerRequest); } }  }
QueryOptimizer { public void optimize(BrokerRequest brokerRequest, @Nullable Schema schema) { FilterQuery filterQuery = brokerRequest.getFilterQuery(); if (filterQuery != null) { FilterQueryTree filterQueryTree = RequestUtils.buildFilterQuery(filterQuery.getId(), brokerRequest.getFilterSubQueryMap().getFilterQueryMap()); for (FilterOptimizer filterOptimizer : FILTER_OPTIMIZERS) { filterQueryTree = filterOptimizer.optimize(filterQueryTree, schema); } RequestUtils.generateFilterFromTree(filterQueryTree, brokerRequest); } }  void optimize(BrokerRequest brokerRequest, @Nullable Schema schema); void optimize(PinotQuery pinotQuery, @Nullable Schema schema); }
QueryOptimizer { public void optimize(BrokerRequest brokerRequest, @Nullable Schema schema) { FilterQuery filterQuery = brokerRequest.getFilterQuery(); if (filterQuery != null) { FilterQueryTree filterQueryTree = RequestUtils.buildFilterQuery(filterQuery.getId(), brokerRequest.getFilterSubQueryMap().getFilterQueryMap()); for (FilterOptimizer filterOptimizer : FILTER_OPTIMIZERS) { filterQueryTree = filterOptimizer.optimize(filterQueryTree, schema); } RequestUtils.generateFilterFromTree(filterQueryTree, brokerRequest); } }  void optimize(BrokerRequest brokerRequest, @Nullable Schema schema); void optimize(PinotQuery pinotQuery, @Nullable Schema schema);  }