Search in sources :

Example 16 with AggregatePlanNode

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());
}
Also used : AbstractPlanNode(org.voltdb.plannodes.AbstractPlanNode) AbstractExpression(org.voltdb.expressions.AbstractExpression) OrderByPlanNode(org.voltdb.plannodes.OrderByPlanNode) AggregatePlanNode(org.voltdb.plannodes.AggregatePlanNode) SchemaColumn(org.voltdb.plannodes.SchemaColumn) NestLoopPlanNode(org.voltdb.plannodes.NestLoopPlanNode)

Example 17 with AggregatePlanNode

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);
    }
}
Also used : AbstractPlanNode(org.voltdb.plannodes.AbstractPlanNode) AbstractScanPlanNode(org.voltdb.plannodes.AbstractScanPlanNode) HashAggregatePlanNode(org.voltdb.plannodes.HashAggregatePlanNode) AggregatePlanNode(org.voltdb.plannodes.AggregatePlanNode) ProjectionPlanNode(org.voltdb.plannodes.ProjectionPlanNode)

Example 18 with AggregatePlanNode

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);
}
Also used : AbstractPlanNode(org.voltdb.plannodes.AbstractPlanNode) AbstractScanPlanNode(org.voltdb.plannodes.AbstractScanPlanNode) OrderByPlanNode(org.voltdb.plannodes.OrderByPlanNode) HashAggregatePlanNode(org.voltdb.plannodes.HashAggregatePlanNode) AggregatePlanNode(org.voltdb.plannodes.AggregatePlanNode) ProjectionPlanNode(org.voltdb.plannodes.ProjectionPlanNode)

Example 19 with AggregatePlanNode

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));
}
Also used : AbstractPlanNode(org.voltdb.plannodes.AbstractPlanNode) AbstractScanPlanNode(org.voltdb.plannodes.AbstractScanPlanNode) HashAggregatePlanNode(org.voltdb.plannodes.HashAggregatePlanNode) AggregatePlanNode(org.voltdb.plannodes.AggregatePlanNode) ReceivePlanNode(org.voltdb.plannodes.ReceivePlanNode) AbstractReceivePlanNode(org.voltdb.plannodes.AbstractReceivePlanNode)

Example 20 with AggregatePlanNode

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());
}
Also used : AbstractPlanNode(org.voltdb.plannodes.AbstractPlanNode) HashAggregatePlanNode(org.voltdb.plannodes.HashAggregatePlanNode) AggregatePlanNode(org.voltdb.plannodes.AggregatePlanNode) SendPlanNode(org.voltdb.plannodes.SendPlanNode) IndexScanPlanNode(org.voltdb.plannodes.IndexScanPlanNode) ProjectionPlanNode(org.voltdb.plannodes.ProjectionPlanNode)

Aggregations

AggregatePlanNode (org.voltdb.plannodes.AggregatePlanNode)38 AbstractPlanNode (org.voltdb.plannodes.AbstractPlanNode)37 HashAggregatePlanNode (org.voltdb.plannodes.HashAggregatePlanNode)22 AbstractScanPlanNode (org.voltdb.plannodes.AbstractScanPlanNode)15 ProjectionPlanNode (org.voltdb.plannodes.ProjectionPlanNode)14 ReceivePlanNode (org.voltdb.plannodes.ReceivePlanNode)10 AbstractReceivePlanNode (org.voltdb.plannodes.AbstractReceivePlanNode)8 OrderByPlanNode (org.voltdb.plannodes.OrderByPlanNode)8 AbstractExpression (org.voltdb.expressions.AbstractExpression)7 IndexScanPlanNode (org.voltdb.plannodes.IndexScanPlanNode)7 LimitPlanNode (org.voltdb.plannodes.LimitPlanNode)7 SendPlanNode (org.voltdb.plannodes.SendPlanNode)6 SeqScanPlanNode (org.voltdb.plannodes.SeqScanPlanNode)6 MergeReceivePlanNode (org.voltdb.plannodes.MergeReceivePlanNode)5 PartialAggregatePlanNode (org.voltdb.plannodes.PartialAggregatePlanNode)5 TableCountPlanNode (org.voltdb.plannodes.TableCountPlanNode)5 AbstractSubqueryExpression (org.voltdb.expressions.AbstractSubqueryExpression)3 IndexCountPlanNode (org.voltdb.plannodes.IndexCountPlanNode)3 NestLoopPlanNode (org.voltdb.plannodes.NestLoopPlanNode)3 ArrayList (java.util.ArrayList)2