use of org.voltdb.plannodes.AbstractScanPlanNode in project voltdb by VoltDB.
the class TestPlansScalarSubQueries method testSelectCorrelatedScalarWithGroupby.
public void testSelectCorrelatedScalarWithGroupby() {
String sql = "select franchise_id, count(*) as stores_in_category_AdHoc, " + " (select category from store_types where type_id = stores.type_id) as store_category " + "from stores group by franchise_id, type_id;";
AbstractPlanNode pn = compile(sql);
pn = pn.getChild(0);
assertTrue(pn instanceof ProjectionPlanNode);
NodeSchema schema = pn.getOutputSchema();
assertEquals(3, schema.size());
SchemaColumn col = schema.getColumns().get(2);
assertTrue(col != null);
assertEquals("STORE_CATEGORY", col.getColumnName());
assertTrue(col.getExpression() instanceof ScalarValueExpression);
pn = pn.getChild(0);
assertTrue(pn instanceof AbstractScanPlanNode);
assertNotNull(pn.getInlinePlanNode(PlanNodeType.HASHAGGREGATE));
}
use of org.voltdb.plannodes.AbstractScanPlanNode in project voltdb by VoltDB.
the class TestPlansScalarSubQueries method testSelectCorrelatedScalarInGroupbyClause.
public void testSelectCorrelatedScalarInGroupbyClause() {
String sql = "select franchise_id, count(*) as stores_in_category_AdHoc " + " from stores group by franchise_id, (select category from store_types where type_id = stores.type_id);";
AbstractPlanNode pn = compile(sql);
pn = pn.getChild(0);
assertTrue(pn instanceof ProjectionPlanNode);
NodeSchema schema = pn.getOutputSchema();
assertEquals(2, schema.size());
pn = pn.getChild(0);
assertTrue(pn instanceof AbstractScanPlanNode);
assertNotNull(pn.getInlinePlanNode(PlanNodeType.HASHAGGREGATE));
HashAggregatePlanNode aggNode = (HashAggregatePlanNode) pn.getInlinePlanNode(PlanNodeType.HASHAGGREGATE);
assertEquals(2, aggNode.getGroupByExpressionsSize());
AbstractExpression tveExpr = aggNode.getGroupByExpressions().get(0);
assertTrue(tveExpr instanceof TupleValueExpression);
AbstractExpression gbExpr = aggNode.getGroupByExpressions().get(1);
assertTrue(gbExpr instanceof ScalarValueExpression);
assertTrue(gbExpr.getLeft() instanceof SelectSubqueryExpression);
}
use of org.voltdb.plannodes.AbstractScanPlanNode in project voltdb by VoltDB.
the class TestPlansInExistsSubQueries method verifyAggregateSubquery.
private void verifyAggregateSubquery(AbstractExpression exists, int columnCount, int groupByCount, boolean hasHaving) {
assertNotNull(exists);
assertEquals(ExpressionType.OPERATOR_EXISTS, exists.getExpressionType());
AbstractSubqueryExpression se = (AbstractSubqueryExpression) exists.getLeft();
AbstractPlanNode sn = se.getSubqueryNode();
assertTrue(sn instanceof AbstractScanPlanNode);
AbstractPlanNode inline = sn.getInlinePlanNode(PlanNodeType.AGGREGATE);
assertNotNull(inline);
assertEquals(columnCount, inline.getOutputSchema().size());
AggregatePlanNode agg = (AggregatePlanNode) inline;
assertEquals(groupByCount, agg.getGroupByExpressions().size());
assertEquals(hasHaving, agg.getPostPredicate() != null);
}
use of org.voltdb.plannodes.AbstractScanPlanNode in project voltdb by VoltDB.
the class TestPlansInExistsSubQueries method testInToExistWithOffset.
public void testInToExistWithOffset() {
AbstractPlanNode pn = compile("select r2.c from r2 where r2.a in (select c from r1 limit 1 offset 3)");
pn = pn.getChild(0);
assertTrue(pn instanceof AbstractScanPlanNode);
AbstractScanPlanNode spl = (AbstractScanPlanNode) pn;
// Check param indexes
AbstractExpression e = spl.getPredicate();
assertEquals(ExpressionType.COMPARE_EQUAL, e.getExpressionType());
assertEquals(QuantifierType.ANY, ((ComparisonExpression) e).getQuantifier());
}
use of org.voltdb.plannodes.AbstractScanPlanNode in project voltdb by VoltDB.
the class TestPlansDML method checkDMLPlanNodeAndSubqueryExpression.
void checkDMLPlanNodeAndSubqueryExpression(String dmlSQL, ExpressionType filterType) {
List<AbstractPlanNode> pns = compileToFragments(dmlSQL);
AbstractPlanNode dmlNode;
if (pns.size() == 2) {
dmlNode = pns.get(1).getChild(0);
} else {
dmlNode = pns.get(0);
}
String dmlType = dmlSQL.substring(0, dmlSQL.indexOf(' ')).trim().toUpperCase();
if ("UPSERT".equalsIgnoreCase(dmlType)) {
// UPSERT is INSERT
dmlType = "INSERT";
}
// it could be extended in some way.
if ((dmlNode instanceof SeqScanPlanNode) && "INSERT".equals(dmlType)) {
assertNotNull("Expected an insert node.", dmlNode.getInlinePlanNode(PlanNodeType.INSERT));
} else {
assertEquals(dmlType, dmlNode.getPlanNodeType().toString());
}
PlanNodeType nodeType = dmlNode.getPlanNodeType();
while (nodeType != PlanNodeType.SEQSCAN && nodeType != PlanNodeType.MATERIALIZE && nodeType != PlanNodeType.INDEXSCAN) {
dmlNode = dmlNode.getChild(0);
nodeType = dmlNode.getPlanNodeType();
}
assertNotNull(dmlNode);
// Verify DML Predicate
if (filterType != null) {
AbstractExpression predicate = ((AbstractScanPlanNode) dmlNode).getPredicate();
assertNotNull(predicate);
assertEquals(filterType, predicate.getExpressionType());
assertTrue(predicate.hasAnySubexpressionOfClass(SelectSubqueryExpression.class));
}
}
Aggregations