use of org.voltdb.plannodes.AggregatePlanNode in project voltdb by VoltDB.
the class TestPlansJoin method testUsingColumns.
public void testUsingColumns() {
String query;
AbstractPlanNode pn;
OrderByPlanNode orderBy;
NestLoopPlanNode nlj;
AggregatePlanNode aggr;
List<SchemaColumn> selectColumns;
SchemaColumn col;
AbstractExpression colExp;
AbstractExpression predicate;
// Test USING column
query = "SELECT MAX(R1.A), C FROM R1 FULL JOIN R2 USING (C) " + "WHERE C > 0 GROUP BY C ORDER BY C";
pn = compileToTopDownTree(query, 2, PlanNodeType.SEND, PlanNodeType.ORDERBY, PlanNodeType.NESTLOOP, PlanNodeType.SEQSCAN, PlanNodeType.SEQSCAN);
// ORDER BY column
orderBy = (OrderByPlanNode) pn.getChild(0);
List<AbstractExpression> s = orderBy.getSortExpressions();
assertEquals(1, s.size());
assertEquals(ExpressionType.VALUE_TUPLE, s.get(0).getExpressionType());
// WHERE
nlj = (NestLoopPlanNode) orderBy.getChild(0);
assertNull(nlj.getPreJoinPredicate());
predicate = nlj.getJoinPredicate();
assertExprTopDownTree(predicate, ExpressionType.COMPARE_EQUAL, ExpressionType.VALUE_TUPLE, ExpressionType.VALUE_TUPLE);
predicate = nlj.getWherePredicate();
assertExprTopDownTree(predicate, ExpressionType.COMPARE_GREATERTHAN, ExpressionType.OPERATOR_CASE_WHEN, ExpressionType.OPERATOR_IS_NULL, ExpressionType.VALUE_TUPLE, ExpressionType.OPERATOR_ALTERNATIVE, ExpressionType.VALUE_TUPLE, ExpressionType.VALUE_TUPLE, ExpressionType.VALUE_CONSTANT);
// GROUP BY
aggr = (AggregatePlanNode) nlj.getInlinePlanNode(PlanNodeType.HASHAGGREGATE);
assertNotNull(aggr);
List<AbstractExpression> g = aggr.getGroupByExpressions();
assertEquals(1, g.size());
assertExprTopDownTree(g.get(0), ExpressionType.OPERATOR_CASE_WHEN, ExpressionType.OPERATOR_IS_NULL, ExpressionType.VALUE_TUPLE, ExpressionType.OPERATOR_ALTERNATIVE, ExpressionType.VALUE_TUPLE, ExpressionType.VALUE_TUPLE);
// Test three table full join
query = "SELECT C FROM R1 FULL JOIN R2 USING (C) FULL JOIN R3 USING (C)";
pn = compileToTopDownTree(query, 1, PlanNodeType.SEND, PlanNodeType.PROJECTION, PlanNodeType.NESTLOOP, PlanNodeType.NESTLOOP, PlanNodeType.SEQSCAN, PlanNodeType.SEQSCAN, PlanNodeType.SEQSCAN);
selectColumns = pn.getOutputSchema().getColumns();
col = selectColumns.get(0);
assertEquals("C", col.getColumnAlias());
colExp = col.getExpression();
assertEquals(ExpressionType.VALUE_TUPLE, colExp.getExpressionType());
// Test three table INNER join. USING C column should be resolved
query = "SELECT C FROM R1 JOIN R2 USING (C) JOIN R3 USING (C)";
pn = compileToTopDownTree(query, 1, PlanNodeType.SEND, PlanNodeType.PROJECTION, PlanNodeType.NESTLOOP, PlanNodeType.NESTLOOP, PlanNodeType.SEQSCAN, PlanNodeType.SEQSCAN, PlanNodeType.SEQSCAN);
selectColumns = pn.getOutputSchema().getColumns();
assertEquals(1, selectColumns.size());
col = selectColumns.get(0);
assertEquals("C", col.getColumnAlias());
colExp = col.getExpression();
assertEquals(ExpressionType.VALUE_TUPLE, colExp.getExpressionType());
// Test two table LEFT join. USING C column should be resolved
query = "SELECT C FROM R1 LEFT JOIN R2 USING (C)";
pn = compileToTopDownTree(query, 1, PlanNodeType.SEND, PlanNodeType.PROJECTION, PlanNodeType.NESTLOOP, PlanNodeType.SEQSCAN, PlanNodeType.SEQSCAN);
selectColumns = pn.getOutputSchema().getColumns();
assertEquals(1, selectColumns.size());
col = selectColumns.get(0);
assertEquals("C", col.getColumnAlias());
colExp = col.getExpression();
assertEquals(ExpressionType.VALUE_TUPLE, colExp.getExpressionType());
// Test two table RIGHT join. USING C column should be resolved
query = "SELECT C FROM R1 RIGHT JOIN R2 USING (C)";
pn = compileToTopDownTree(query, 1, PlanNodeType.SEND, PlanNodeType.PROJECTION, PlanNodeType.NESTLOOP, PlanNodeType.SEQSCAN, PlanNodeType.SEQSCAN);
selectColumns = pn.getOutputSchema().getColumns();
assertEquals(1, selectColumns.size());
col = selectColumns.get(0);
assertEquals("C", col.getColumnAlias());
colExp = col.getExpression();
assertEquals(ExpressionType.VALUE_TUPLE, colExp.getExpressionType());
}
use of org.voltdb.plannodes.AggregatePlanNode in project voltdb by VoltDB.
the class TestPlansGroupBy method checkOptimizedAgg.
private void checkOptimizedAgg(List<AbstractPlanNode> pns, boolean optimized) {
AbstractPlanNode p = pns.get(0).getChild(0);
if (optimized) {
assertTrue(p instanceof ProjectionPlanNode);
assertTrue(p.getChild(0) instanceof AggregatePlanNode);
p = pns.get(1).getChild(0);
// push down for optimization
assertTrue(p instanceof AbstractScanPlanNode);
assertTrue(p.getInlinePlanNode(PlanNodeType.AGGREGATE) != null || p.getInlinePlanNode(PlanNodeType.HASHAGGREGATE) != null);
} else {
assertEquals(1, pns.size());
assertTrue(p instanceof AbstractScanPlanNode);
assertTrue(p.getInlinePlanNode(PlanNodeType.AGGREGATE) != null || p.getInlinePlanNode(PlanNodeType.HASHAGGREGATE) != null);
}
}
use of org.voltdb.plannodes.AggregatePlanNode in project voltdb by VoltDB.
the class TestPlansGroupBy method testComplexAggwithLimitDistinct.
public void testComplexAggwithLimitDistinct() {
List<AbstractPlanNode> pns;
pns = compileToFragments("SELECT A1, sum(A1), sum(distinct A1)+11 FROM P1 GROUP BY A1 ORDER BY A1 LIMIT 2");
checkHasComplexAgg(pns);
// Test no limit push down
AbstractPlanNode p = pns.get(0).getChild(0);
assertTrue(p instanceof OrderByPlanNode);
assertNotNull(p.getInlinePlanNode(PlanNodeType.LIMIT));
assertTrue(p.getChild(0) instanceof ProjectionPlanNode);
assertTrue(p.getChild(0).getChild(0) instanceof AggregatePlanNode);
p = pns.get(1).getChild(0);
assertTrue(p instanceof AbstractScanPlanNode);
}
use of org.voltdb.plannodes.AggregatePlanNode in project voltdb by VoltDB.
the class TestPlansGroupBy method checkSimpleTableInlineAgg.
private void checkSimpleTableInlineAgg(String sql) {
AbstractPlanNode p;
List<AbstractPlanNode> pns;
pns = compileToFragments(sql);
p = pns.get(0).getChild(0);
assertTrue(p instanceof AggregatePlanNode);
assertTrue(p.getChild(0) instanceof ReceivePlanNode);
p = pns.get(1).getChild(0);
assertTrue(p instanceof AbstractScanPlanNode);
assertNotNull(p.getInlinePlanNode(PlanNodeType.PROJECTION));
assertNotNull(p.getInlinePlanNode(PlanNodeType.AGGREGATE));
}
use of org.voltdb.plannodes.AggregatePlanNode in project voltdb by VoltDB.
the class TestPlansGroupBy method checkMVReaggregateFeatureMergeReceive.
// topNode, reAggNode
private void checkMVReaggregateFeatureMergeReceive(List<AbstractPlanNode> pns, boolean needFix, int numGroupByOfReaggNode, int numAggsOfReaggNode, boolean aggPushdown, boolean aggInline, SortDirectionType sortDirection) {
assertEquals(2, pns.size());
AbstractPlanNode p = pns.get(0);
assertTrue(p instanceof SendPlanNode);
p = p.getChild(0);
if (p instanceof ProjectionPlanNode) {
p = p.getChild(0);
}
AbstractPlanNode receiveNode = p;
assertNotNull(receiveNode);
AggregatePlanNode reAggNode = AggregatePlanNode.getInlineAggregationNode(receiveNode);
if (needFix) {
assertNotNull(reAggNode);
assertEquals(numGroupByOfReaggNode, reAggNode.getGroupByExpressionsSize());
assertEquals(numAggsOfReaggNode, reAggNode.getAggregateTypesSize());
} else {
assertNull(reAggNode);
}
p = pns.get(1);
assertTrue(p instanceof SendPlanNode);
p = p.getChild(0);
assertTrue(p instanceof IndexScanPlanNode);
assertEquals(sortDirection, ((IndexScanPlanNode) p).getSortDirection());
}
Aggregations