Search in sources :

Example 11 with AggregatePlanNode

use of org.voltdb.plannodes.AggregatePlanNode in project voltdb by VoltDB.

the class TestPlansGroupBy method testComplexGroupBy.

public void testComplexGroupBy() {
    List<AbstractPlanNode> pns;
    pns = compileToFragments("SELECT A1, ABS(A1), ABS(A1)+1, sum(B1) FROM P1 GROUP BY A1, ABS(A1)");
    checkHasComplexAgg(pns);
    // Check it can compile
    pns = compileToFragments("SELECT ABS(A1), sum(B1) FROM P1 GROUP BY ABS(A1)");
    AbstractPlanNode p = pns.get(0).getChild(0);
    assertTrue(p instanceof AggregatePlanNode);
    p = pns.get(1).getChild(0);
    // inline aggregate
    assertTrue(p instanceof AbstractScanPlanNode);
    assertNotNull(p.getInlinePlanNode(PlanNodeType.HASHAGGREGATE));
    pns = compileToFragments("SELECT A1+PKEY, avg(B1) as tag FROM P1 GROUP BY A1+PKEY ORDER BY ABS(tag), A1+PKEY");
    checkHasComplexAgg(pns);
}
Also used : AbstractPlanNode(org.voltdb.plannodes.AbstractPlanNode) AbstractScanPlanNode(org.voltdb.plannodes.AbstractScanPlanNode) HashAggregatePlanNode(org.voltdb.plannodes.HashAggregatePlanNode) AggregatePlanNode(org.voltdb.plannodes.AggregatePlanNode)

Example 12 with AggregatePlanNode

use of org.voltdb.plannodes.AggregatePlanNode in project voltdb by VoltDB.

the class TestPlansGroupBy method testGroupByA1.

public void testGroupByA1() {
    AbstractPlanNode p;
    AggregatePlanNode aggNode;
    List<AbstractPlanNode> pns;
    pns = compileToFragments("SELECT A1 from T1 group by A1");
    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);
    // No index, inline hash aggregate
    assertNotNull(p.getInlinePlanNode(PlanNodeType.HASHAGGREGATE));
    // Having
    pns = compileToFragments("SELECT A1, count(*) from T1 group by A1 Having count(*) > 3");
    p = pns.get(0).getChild(0);
    assertTrue(p instanceof AggregatePlanNode);
    aggNode = (AggregatePlanNode) p;
    assertNotNull(aggNode.getPostPredicate());
    assertTrue(p.getChild(0) instanceof ReceivePlanNode);
    p = pns.get(1).getChild(0);
    assertTrue(p instanceof AbstractScanPlanNode);
    // No index, inline hash aggregate
    assertNotNull(p.getInlinePlanNode(PlanNodeType.HASHAGGREGATE));
    aggNode = (AggregatePlanNode) p.getInlinePlanNode(PlanNodeType.HASHAGGREGATE);
    assertNull(aggNode.getPostPredicate());
}
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 13 with AggregatePlanNode

use of org.voltdb.plannodes.AggregatePlanNode in project voltdb by VoltDB.

the class TestPlansGroupBy method testGroupByAliasNegativeCases.

public void testGroupByAliasNegativeCases() {
    List<AbstractPlanNode> pns;
    // Group by aggregate expression
    try {
        pns = compileInvalidToFragments("SELECT abs(PKEY) as sp, count(*) as ct FROM P1 GROUP BY count(*)");
        fail("Did not expect invalid GROUP BY query to succeed.");
    } catch (Exception ex) {
        assertTrue(ex.getMessage().contains("invalid GROUP BY expression:  COUNT()"));
    }
    try {
        pns = compileInvalidToFragments("SELECT abs(PKEY) as sp, count(*) as ct FROM P1 GROUP BY ct");
        fail("Did not expect invalid GROUP BY alias query to succeed.");
    } catch (Exception ex) {
        assertTrue(ex.getMessage().contains("invalid GROUP BY expression:  COUNT()"));
    }
    try {
        pns = compileInvalidToFragments("SELECT abs(PKEY) as sp, (count(*) +1 ) as ct FROM P1 GROUP BY ct");
        fail("Did not expect invalid GROUP BY expression alias query to succeed.");
    } catch (Exception ex) {
        assertTrue(ex.getMessage().contains("invalid GROUP BY expression:  COUNT()"));
    }
    // Group by alias and expression
    try {
        pns = compileInvalidToFragments("SELECT abs(PKEY) as sp, count(*) as ct FROM P1 GROUP BY sp + 1");
        fail("Did not expect invalid GROUP BY alias expression query to succeed.");
    } catch (Exception ex) {
        assertTrue(ex.getMessage().contains("user lacks privilege or object not found: SP"));
    }
    // Having
    try {
        pns = compileInvalidToFragments("SELECT ABS(A1), count(*) as ct FROM P1 GROUP BY ABS(A1) having ct > 3");
        fail("Did not expect invalid HAVING condition on alias query to succeed.");
    } catch (Exception ex) {
        assertTrue(ex.getMessage().contains("user lacks privilege or object not found: CT"));
    }
    // Group by column.alias
    try {
        pns = compileInvalidToFragments("SELECT abs(PKEY) as sp, count(*) as ct FROM P1 GROUP BY P1.sp");
        fail("Did not expect invalid GROUP BY qualified alias query to succeed.");
    } catch (Exception ex) {
        assertTrue(ex.getMessage().contains("user lacks privilege or object not found: P1.SP"));
    }
    //
    // ambiguous group by query because of A1 is a column name and a select alias
    //
    pns = compileToFragments("SELECT ABS(A1) AS A1, count(*) as ct FROM P1 GROUP BY A1");
    //* enable to debug */ printExplainPlan(pns);
    AbstractPlanNode p = pns.get(1).getChild(0);
    assertTrue(p instanceof AbstractScanPlanNode);
    AggregatePlanNode agg = AggregatePlanNode.getInlineAggregationNode(p);
    assertNotNull(agg);
    // group by column, instead of the ABS(A1) expression
    assertEquals(agg.getGroupByExpressions().get(0).getExpressionType(), ExpressionType.VALUE_TUPLE);
}
Also used : AbstractPlanNode(org.voltdb.plannodes.AbstractPlanNode) AbstractScanPlanNode(org.voltdb.plannodes.AbstractScanPlanNode) HashAggregatePlanNode(org.voltdb.plannodes.HashAggregatePlanNode) AggregatePlanNode(org.voltdb.plannodes.AggregatePlanNode)

Example 14 with AggregatePlanNode

use of org.voltdb.plannodes.AggregatePlanNode in project voltdb by VoltDB.

the class TestPlansGroupBy method testInlineSerialAgg_noGroupBy_special.

// AVG is optimized with SUM / COUNT, generating extra projection node
// In future, inline projection for aggregation.
public void testInlineSerialAgg_noGroupBy_special() {
    AbstractPlanNode p;
    List<AbstractPlanNode> pns;
    pns = compileToFragments("SELECT AVG(A1) from T1");
    //* enable to debug */ printExplainPlan(pns);
    p = pns.get(0).getChild(0);
    assertTrue(p instanceof ProjectionPlanNode);
    assertTrue(p.getChild(0) instanceof AggregatePlanNode);
    assertTrue(p.getChild(0).getChild(0) instanceof ReceivePlanNode);
    p = pns.get(1).getChild(0);
    assertTrue(p instanceof SeqScanPlanNode);
    assertNotNull(p.getInlinePlanNode(PlanNodeType.PROJECTION));
    assertNotNull(p.getInlinePlanNode(PlanNodeType.AGGREGATE));
}
Also used : AbstractPlanNode(org.voltdb.plannodes.AbstractPlanNode) SeqScanPlanNode(org.voltdb.plannodes.SeqScanPlanNode) HashAggregatePlanNode(org.voltdb.plannodes.HashAggregatePlanNode) AggregatePlanNode(org.voltdb.plannodes.AggregatePlanNode) ReceivePlanNode(org.voltdb.plannodes.ReceivePlanNode) AbstractReceivePlanNode(org.voltdb.plannodes.AbstractReceivePlanNode) ProjectionPlanNode(org.voltdb.plannodes.ProjectionPlanNode)

Example 15 with AggregatePlanNode

use of org.voltdb.plannodes.AggregatePlanNode in project voltdb by VoltDB.

the class TestPlansGroupBy method checkHavingClause.

private void checkHavingClause(String sql, boolean aggInline, Object aggPostFilters) {
    List<AbstractPlanNode> pns;
    pns = compileToFragments(sql);
    AbstractPlanNode p = pns.get(0);
    AggregatePlanNode aggNode;
    ArrayList<AbstractPlanNode> nodesList = p.findAllNodesOfType(PlanNodeType.AGGREGATE);
    assertEquals(1, nodesList.size());
    p = nodesList.get(0);
    boolean isInline = p.isInline();
    assertEquals(aggInline, isInline);
    assertTrue(p instanceof AggregatePlanNode);
    aggNode = (AggregatePlanNode) p;
    String aggNodeStr = aggNode.toExplainPlanString().toLowerCase();
    if (aggPostFilters != null) {
        String[] aggFilterStrings = null;
        if (aggPostFilters instanceof String) {
            aggFilterStrings = new String[] { (String) aggPostFilters };
        } else {
            aggFilterStrings = (String[]) aggPostFilters;
        }
        for (String aggFilter : aggFilterStrings) {
            assertTrue(aggNodeStr.contains(aggFilter.toLowerCase()));
        }
    } else {
        assertNull(aggNode.getPostPredicate());
    }
}
Also used : AbstractPlanNode(org.voltdb.plannodes.AbstractPlanNode) HashAggregatePlanNode(org.voltdb.plannodes.HashAggregatePlanNode) AggregatePlanNode(org.voltdb.plannodes.AggregatePlanNode)

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