use of org.voltdb.plannodes.AbstractScanPlanNode 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.AbstractScanPlanNode 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.AbstractScanPlanNode in project voltdb by VoltDB.
the class TestPlansGroupBy method checkMVReaggregateFeature.
// topNode, reAggNode
private void checkMVReaggregateFeature(List<AbstractPlanNode> pns, boolean needFix, int numGroupByOfTopAggNode, int numAggsOfTopAggNode, int numGroupByOfReaggNode, int numAggsOfReaggNode, boolean aggPushdown, boolean aggInline) {
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);
}
if (p instanceof LimitPlanNode) {
// No limit pushed down.
p = p.getChild(0);
}
if (p instanceof OrderByPlanNode) {
p = p.getChild(0);
}
HashAggregatePlanNode reAggNode = null;
List<AbstractPlanNode> nodes = p.findAllNodesOfClass(AbstractReceivePlanNode.class);
assertEquals(1, nodes.size());
AbstractPlanNode receiveNode = nodes.get(0);
// Indicates that there is no top aggregation node.
if (numGroupByOfTopAggNode == -1) {
if (needFix) {
p = receiveNode.getParent(0);
assertTrue(p instanceof HashAggregatePlanNode);
reAggNode = (HashAggregatePlanNode) p;
assertEquals(numGroupByOfReaggNode, reAggNode.getGroupByExpressionsSize());
assertEquals(numAggsOfReaggNode, reAggNode.getAggregateTypesSize());
p = p.getChild(0);
}
assertTrue(p instanceof ReceivePlanNode);
p = pns.get(1);
assertTrue(p instanceof SendPlanNode);
p = p.getChild(0);
assertTrue(p instanceof AbstractScanPlanNode);
return;
}
if (p instanceof ProjectionPlanNode) {
p = p.getChild(0);
}
//
// Hash top aggregate node
//
AggregatePlanNode topAggNode = null;
if (p instanceof AbstractJoinPlanNode) {
// Inline aggregation with join
topAggNode = AggregatePlanNode.getInlineAggregationNode(p);
} else {
assertTrue(p instanceof AggregatePlanNode);
topAggNode = (AggregatePlanNode) p;
p = p.getChild(0);
}
assertEquals(numGroupByOfTopAggNode, topAggNode.getGroupByExpressionsSize());
assertEquals(numAggsOfTopAggNode, topAggNode.getAggregateTypesSize());
if (needFix) {
p = receiveNode.getParent(0);
assertTrue(p instanceof HashAggregatePlanNode);
reAggNode = (HashAggregatePlanNode) p;
assertEquals(numGroupByOfReaggNode, reAggNode.getGroupByExpressionsSize());
assertEquals(numAggsOfReaggNode, reAggNode.getAggregateTypesSize());
p = p.getChild(0);
}
assertTrue(p instanceof ReceivePlanNode);
// Test the second part
p = pns.get(1);
assertTrue(p instanceof SendPlanNode);
p = p.getChild(0);
if (aggPushdown) {
assertTrue(!needFix);
if (aggInline) {
assertNotNull(AggregatePlanNode.getInlineAggregationNode(p));
} else {
assertTrue(p instanceof AggregatePlanNode);
p = p.getChild(0);
}
}
if (needFix) {
assertTrue(p instanceof AbstractScanPlanNode);
} else {
assertTrue(p instanceof AbstractScanPlanNode || p instanceof AbstractJoinPlanNode);
}
}
use of org.voltdb.plannodes.AbstractScanPlanNode 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.AbstractScanPlanNode 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);
}
Aggregations