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);
}
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());
}
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);
}
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));
}
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());
}
}
Aggregations