Search in sources :

Example 36 with AbstractScanPlanNode

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));
}
Also used : AbstractPlanNode(org.voltdb.plannodes.AbstractPlanNode) AbstractScanPlanNode(org.voltdb.plannodes.AbstractScanPlanNode) ScalarValueExpression(org.voltdb.expressions.ScalarValueExpression) SchemaColumn(org.voltdb.plannodes.SchemaColumn) NodeSchema(org.voltdb.plannodes.NodeSchema) ProjectionPlanNode(org.voltdb.plannodes.ProjectionPlanNode)

Example 37 with AbstractScanPlanNode

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);
}
Also used : AbstractPlanNode(org.voltdb.plannodes.AbstractPlanNode) AbstractScanPlanNode(org.voltdb.plannodes.AbstractScanPlanNode) TupleValueExpression(org.voltdb.expressions.TupleValueExpression) AbstractExpression(org.voltdb.expressions.AbstractExpression) ScalarValueExpression(org.voltdb.expressions.ScalarValueExpression) HashAggregatePlanNode(org.voltdb.plannodes.HashAggregatePlanNode) SelectSubqueryExpression(org.voltdb.expressions.SelectSubqueryExpression) NodeSchema(org.voltdb.plannodes.NodeSchema) ProjectionPlanNode(org.voltdb.plannodes.ProjectionPlanNode)

Example 38 with AbstractScanPlanNode

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

Example 39 with AbstractScanPlanNode

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

Example 40 with AbstractScanPlanNode

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));
    }
}
Also used : AbstractPlanNode(org.voltdb.plannodes.AbstractPlanNode) SeqScanPlanNode(org.voltdb.plannodes.SeqScanPlanNode) PlanNodeType(org.voltdb.types.PlanNodeType) AbstractScanPlanNode(org.voltdb.plannodes.AbstractScanPlanNode) AbstractExpression(org.voltdb.expressions.AbstractExpression) SelectSubqueryExpression(org.voltdb.expressions.SelectSubqueryExpression)

Aggregations

AbstractScanPlanNode (org.voltdb.plannodes.AbstractScanPlanNode)48 AbstractPlanNode (org.voltdb.plannodes.AbstractPlanNode)46 AbstractExpression (org.voltdb.expressions.AbstractExpression)21 AggregatePlanNode (org.voltdb.plannodes.AggregatePlanNode)15 HashAggregatePlanNode (org.voltdb.plannodes.HashAggregatePlanNode)14 ProjectionPlanNode (org.voltdb.plannodes.ProjectionPlanNode)14 NodeSchema (org.voltdb.plannodes.NodeSchema)8 ReceivePlanNode (org.voltdb.plannodes.ReceivePlanNode)8 AbstractSubqueryExpression (org.voltdb.expressions.AbstractSubqueryExpression)7 AbstractReceivePlanNode (org.voltdb.plannodes.AbstractReceivePlanNode)7 OrderByPlanNode (org.voltdb.plannodes.OrderByPlanNode)6 SchemaColumn (org.voltdb.plannodes.SchemaColumn)6 SeqScanPlanNode (org.voltdb.plannodes.SeqScanPlanNode)5 IndexScanPlanNode (org.voltdb.plannodes.IndexScanPlanNode)4 LimitPlanNode (org.voltdb.plannodes.LimitPlanNode)4 ArrayList (java.util.ArrayList)3 TupleValueExpression (org.voltdb.expressions.TupleValueExpression)3 AbstractJoinPlanNode (org.voltdb.plannodes.AbstractJoinPlanNode)3 PlanNodeType (org.voltdb.types.PlanNodeType)3 JSONException (org.json_voltpatches.JSONException)2