Search in sources :

Example 11 with PlanNodeType

use of org.voltdb.types.PlanNodeType in project voltdb by VoltDB.

the class TestPlansDML method testDeleteOrderByPlan.

public void testDeleteOrderByPlan() {
    System.out.println("\n\n\nRUNNING testDeleteOrderByPlan\n\n");
    List<AbstractPlanNode> pns;
    PlanNodeType[] deleteFromIndexScan = { PlanNodeType.SEND, PlanNodeType.DELETE, PlanNodeType.INDEXSCAN };
    PlanNodeType[] deleteFromSortedIndexScan = { PlanNodeType.SEND, PlanNodeType.DELETE, PlanNodeType.ORDERBY, PlanNodeType.INDEXSCAN };
    PlanNodeType[] deleteFromSortedSeqScan = { PlanNodeType.SEND, PlanNodeType.DELETE, PlanNodeType.ORDERBY, PlanNodeType.SEQSCAN };
    // No ORDER BY node, since we can use index instead
    pns = compileToFragments("DELETE FROM R5 ORDER BY A LIMIT ?");
    assertEquals(2, pns.size());
    AbstractPlanNode collectorRoot = pns.get(1);
    assertLeftChain(collectorRoot, deleteFromIndexScan);
    // No ORDER BY node, since index scan is used to evaluate predicate
    pns = compileToFragments("DELETE FROM R5 WHERE A = 1 ORDER BY A LIMIT ?");
    assertEquals(2, pns.size());
    collectorRoot = pns.get(1);
    assertLeftChain(collectorRoot, deleteFromIndexScan);
    // Index used to evaluate predicate not suitable for ORDER BY
    pns = compileToFragments("DELETE FROM R5 WHERE A = 1 ORDER BY B, A, C, D LIMIT ?");
    assertEquals(2, pns.size());
    collectorRoot = pns.get(1);
    assertLeftChain(collectorRoot, deleteFromSortedIndexScan);
    // Index can't be used either for predicate evaluation or ORDER BY
    pns = compileToFragments("DELETE FROM R5 WHERE B = 1 ORDER BY B, A, C, D LIMIT ?");
    assertEquals(2, pns.size());
    collectorRoot = pns.get(1);
    assertLeftChain(collectorRoot, deleteFromSortedSeqScan);
}
Also used : AbstractPlanNode(org.voltdb.plannodes.AbstractPlanNode) PlanNodeType(org.voltdb.types.PlanNodeType)

Example 12 with PlanNodeType

use of org.voltdb.types.PlanNodeType 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)

Example 13 with PlanNodeType

use of org.voltdb.types.PlanNodeType in project voltdb by VoltDB.

the class TestPlansGroupBy method checkGroupByPartitionKey.

private void checkGroupByPartitionKey(List<AbstractPlanNode> pns, boolean topAgg, boolean having) {
    AbstractPlanNode p;
    AggregatePlanNode aggNode;
    p = pns.get(0).getChild(0);
    if (topAgg) {
        assertTrue(p instanceof AggregatePlanNode);
        if (having) {
            aggNode = (AggregatePlanNode) p;
            assertNotNull(aggNode.getPostPredicate());
        }
        p = p.getChild(0);
    }
    assertTrue(p instanceof ReceivePlanNode);
    p = pns.get(1).getChild(0);
    assertTrue(p instanceof AbstractScanPlanNode);
    PlanNodeType aggType = PlanNodeType.HASHAGGREGATE;
    if (p instanceof IndexScanPlanNode && ((IndexScanPlanNode) p).isForGroupingOnly()) {
        aggType = PlanNodeType.AGGREGATE;
    }
    assertNotNull(p.getInlinePlanNode(aggType));
    if (having && !topAgg) {
        aggNode = (AggregatePlanNode) p.getInlinePlanNode(aggType);
        assertNotNull(aggNode.getPostPredicate());
    }
}
Also used : AbstractPlanNode(org.voltdb.plannodes.AbstractPlanNode) PlanNodeType(org.voltdb.types.PlanNodeType) AbstractScanPlanNode(org.voltdb.plannodes.AbstractScanPlanNode) HashAggregatePlanNode(org.voltdb.plannodes.HashAggregatePlanNode) AggregatePlanNode(org.voltdb.plannodes.AggregatePlanNode) IndexScanPlanNode(org.voltdb.plannodes.IndexScanPlanNode) ReceivePlanNode(org.voltdb.plannodes.ReceivePlanNode) AbstractReceivePlanNode(org.voltdb.plannodes.AbstractReceivePlanNode)

Example 14 with PlanNodeType

use of org.voltdb.types.PlanNodeType in project voltdb by VoltDB.

the class PlannerTestCase method followAssertedLeftChain.

/**
     * Find a specific node in a plan tree following the left-most path,
     * (child[0]), and asserting the expected class of each plan node along the
     * way, inclusive of the start and end.
     * @param expectedClasses a list of expected AbstractPlanNode classes
     * @param actualPlan the top of a plan node tree expected to have instances
     *                   of the expected classes along its left-most branch
     *                   listed in top-down order.
     * @return the child node matching the last expected class in the list.
     *                   It need not be a leaf node.
     */
protected static AbstractPlanNode followAssertedLeftChain(AbstractPlanNode start, PlanNodeType startType, PlanNodeType... nodeTypes) {
    AbstractPlanNode result = start;
    assertEquals(startType, result.getPlanNodeType());
    for (PlanNodeType type : nodeTypes) {
        assertTrue(result.getChildCount() > 0);
        result = result.getChild(0);
        assertEquals(type, result.getPlanNodeType());
    }
    return result;
}
Also used : AbstractPlanNode(org.voltdb.plannodes.AbstractPlanNode) PlanNodeType(org.voltdb.types.PlanNodeType)

Aggregations

PlanNodeType (org.voltdb.types.PlanNodeType)14 AbstractPlanNode (org.voltdb.plannodes.AbstractPlanNode)12 ArrayList (java.util.ArrayList)4 AbstractScanPlanNode (org.voltdb.plannodes.AbstractScanPlanNode)3 ReceivePlanNode (org.voltdb.plannodes.ReceivePlanNode)2 EmptyStackException (java.util.EmptyStackException)1 LinkedHashMap (java.util.LinkedHashMap)1 LinkedList (java.util.LinkedList)1 Stack (java.util.Stack)1 JSONArray (org.json_voltpatches.JSONArray)1 JSONException (org.json_voltpatches.JSONException)1 JSONObject (org.json_voltpatches.JSONObject)1 JSONString (org.json_voltpatches.JSONString)1 AbstractExpression (org.voltdb.expressions.AbstractExpression)1 SelectSubqueryExpression (org.voltdb.expressions.SelectSubqueryExpression)1 AbstractReceivePlanNode (org.voltdb.plannodes.AbstractReceivePlanNode)1 AggregatePlanNode (org.voltdb.plannodes.AggregatePlanNode)1 HashAggregatePlanNode (org.voltdb.plannodes.HashAggregatePlanNode)1 IndexScanPlanNode (org.voltdb.plannodes.IndexScanPlanNode)1 MergeReceivePlanNode (org.voltdb.plannodes.MergeReceivePlanNode)1