Search in sources :

Example 71 with AbstractExpression

use of org.voltdb.expressions.AbstractExpression in project voltdb by VoltDB.

the class TestPlansOrderBy method validateMergeReceive.

private void validateMergeReceive(AbstractPlanNode pn, boolean hasLimit, int[] sortColumnIdx) {
    assertEquals(PlanNodeType.MERGERECEIVE, pn.getPlanNodeType());
    MergeReceivePlanNode rpn = (MergeReceivePlanNode) pn;
    assertNotNull(rpn.getInlinePlanNode(PlanNodeType.ORDERBY));
    assertEquals(hasLimit, rpn.getInlinePlanNode(PlanNodeType.LIMIT) != null);
    OrderByPlanNode opn = (OrderByPlanNode) rpn.getInlinePlanNode(PlanNodeType.ORDERBY);
    List<AbstractExpression> ses = opn.getSortExpressions();
    assertEquals(sortColumnIdx.length, ses.size());
    int idx = 0;
    List<AbstractExpression> sesTves = new ArrayList<>();
    for (AbstractExpression se : ses) {
        sesTves.addAll(se.findAllTupleValueSubexpressions());
    }
    assertEquals(sortColumnIdx.length, sesTves.size());
    for (AbstractExpression seTve : sesTves) {
        assertEquals(sortColumnIdx[idx++], ((TupleValueExpression) seTve).getColumnIndex());
    }
}
Also used : AbstractExpression(org.voltdb.expressions.AbstractExpression) OrderByPlanNode(org.voltdb.plannodes.OrderByPlanNode) ArrayList(java.util.ArrayList) MergeReceivePlanNode(org.voltdb.plannodes.MergeReceivePlanNode)

Example 72 with AbstractExpression

use of org.voltdb.expressions.AbstractExpression in project voltdb by VoltDB.

the class TestPlansJoin method perJoinOpTestBasicIndexOuterJoin.

private void perJoinOpTestBasicIndexOuterJoin(JoinOp joinOp) {
    // R3 is indexed but it's the outer table and the join expression
    // must stay at the NLJ so the index can't be used
    String query;
    AbstractPlanNode pn;
    AbstractPlanNode node;
    NestLoopIndexPlanNode nlij;
    NestLoopPlanNode nlj;
    SeqScanPlanNode seqScan;
    IndexScanPlanNode indexScan;
    AbstractExpression predicate;
    query = "SELECT * FROM R3 LEFT JOIN R2 ON R3.A" + joinOp + "R2.C";
    pn = compileToTopDownTree(query, 4, PlanNodeType.SEND, PlanNodeType.PROJECTION, PlanNodeType.NESTLOOP, PlanNodeType.SEQSCAN, PlanNodeType.SEQSCAN);
    node = followAssertedLeftChain(pn, PlanNodeType.SEND, PlanNodeType.PROJECTION, PlanNodeType.NESTLOOP);
    nlj = (NestLoopPlanNode) node;
    assertEquals(JoinType.LEFT, nlj.getJoinType());
    assertNull(nlj.getPreJoinPredicate());
    predicate = nlj.getJoinPredicate();
    assertExprTopDownTree(predicate, joinOp.toOperator(), ExpressionType.VALUE_TUPLE, ExpressionType.VALUE_TUPLE);
    assertNull(nlj.getWherePredicate());
    seqScan = (SeqScanPlanNode) nlj.getChild(0);
    assertEquals("R3", seqScan.getTargetTableName());
    seqScan = (SeqScanPlanNode) nlj.getChild(1);
    assertEquals("R2", seqScan.getTargetTableName());
    // R3 is indexed but it's the outer table so index can't be used
    query = "SELECT * FROM R2 RIGHT JOIN R3 ON R3.A" + joinOp + "R2.C";
    pn = compileToTopDownTree(query, 4, PlanNodeType.SEND, PlanNodeType.PROJECTION, PlanNodeType.NESTLOOP, PlanNodeType.SEQSCAN, PlanNodeType.SEQSCAN);
    node = followAssertedLeftChain(pn, PlanNodeType.SEND, PlanNodeType.PROJECTION, PlanNodeType.NESTLOOP);
    nlj = (NestLoopPlanNode) node;
    assertEquals(JoinType.LEFT, nlj.getJoinType());
    assertNull(nlj.getPreJoinPredicate());
    predicate = nlj.getJoinPredicate();
    assertExprTopDownTree(predicate, joinOp.toOperator(), ExpressionType.VALUE_TUPLE, ExpressionType.VALUE_TUPLE);
    assertNull(nlj.getWherePredicate());
    seqScan = (SeqScanPlanNode) nlj.getChild(0);
    assertEquals("R3", seqScan.getTargetTableName());
    seqScan = (SeqScanPlanNode) nlj.getChild(1);
    assertEquals("R2", seqScan.getTargetTableName());
    if (joinOp != JoinOp.EQUAL) {
        // weaken test for now
        return;
    }
    query = "SELECT * FROM R2 LEFT JOIN R3 ON R2.C" + joinOp + "R3.A";
    pn = compileToTopDownTree(query, 4, PlanNodeType.SEND, PlanNodeType.PROJECTION, PlanNodeType.NESTLOOPINDEX, PlanNodeType.SEQSCAN);
    node = followAssertedLeftChain(pn, PlanNodeType.SEND, PlanNodeType.PROJECTION, PlanNodeType.NESTLOOPINDEX);
    nlij = (NestLoopIndexPlanNode) node;
    assertEquals(JoinType.LEFT, nlij.getJoinType());
    seqScan = (SeqScanPlanNode) nlij.getChild(0);
    assertEquals("R2", seqScan.getTargetTableName());
    indexScan = nlij.getInlineIndexScan();
    assertEquals(IndexLookupType.EQ, indexScan.getLookupType());
    predicate = indexScan.getEndExpression();
    assertExprTopDownTree(predicate, joinOp.toOperator(), ExpressionType.VALUE_TUPLE, ExpressionType.VALUE_TUPLE);
    assertNull(indexScan.getPredicate());
    assertEquals("R3", indexScan.getTargetTableName());
}
Also used : AbstractPlanNode(org.voltdb.plannodes.AbstractPlanNode) SeqScanPlanNode(org.voltdb.plannodes.SeqScanPlanNode) AbstractExpression(org.voltdb.expressions.AbstractExpression) IndexScanPlanNode(org.voltdb.plannodes.IndexScanPlanNode) NestLoopPlanNode(org.voltdb.plannodes.NestLoopPlanNode) NestLoopIndexPlanNode(org.voltdb.plannodes.NestLoopIndexPlanNode)

Example 73 with AbstractExpression

use of org.voltdb.expressions.AbstractExpression in project voltdb by VoltDB.

the class TestPlansScalarSubQueries method testWhereEqualRow.

public void testWhereEqualRow() {
    AbstractPlanNode pn = compile("select r2.c from r2 where (a,c) = (select r1.a, r1.c from r1 where r1.c = r2.c);");
    pn = pn.getChild(0);
    assertTrue(pn instanceof AbstractScanPlanNode);
    AbstractExpression pred = ((AbstractScanPlanNode) pn).getPredicate();
    assertEquals(ExpressionType.COMPARE_EQUAL, pred.getExpressionType());
    assertEquals(ExpressionType.ROW_SUBQUERY, pred.getLeft().getExpressionType());
    assertEquals(ExpressionType.SELECT_SUBQUERY, pred.getRight().getExpressionType());
    assertEquals(1, pred.getRight().getArgs().size());
}
Also used : AbstractPlanNode(org.voltdb.plannodes.AbstractPlanNode) AbstractScanPlanNode(org.voltdb.plannodes.AbstractScanPlanNode) AbstractExpression(org.voltdb.expressions.AbstractExpression)

Example 74 with AbstractExpression

use of org.voltdb.expressions.AbstractExpression in project voltdb by VoltDB.

the class TestPlansScalarSubQueries method testSelectCorrelatedScalar.

public void testSelectCorrelatedScalar() {
    AbstractPlanNode pn = compile("select r2.c, (select d from r1 where r1.c = r2.c ) scalar from r2");
    pn = pn.getChild(0);
    assertTrue(pn instanceof AbstractScanPlanNode);
    AbstractPlanNode proj = pn.getInlinePlanNode(PlanNodeType.PROJECTION);
    NodeSchema schema = proj.getOutputSchema();
    assertEquals(2, schema.size());
    SchemaColumn col = schema.getColumns().get(1);
    assertTrue(col != null);
    assertEquals("SCALAR", col.getColumnName());
    AbstractExpression colExpr = col.getExpression();
    assertEquals(ExpressionType.VALUE_SCALAR, colExpr.getExpressionType());
    assertTrue(colExpr.getLeft() instanceof AbstractSubqueryExpression);
    AbstractSubqueryExpression subqueryExpr = (AbstractSubqueryExpression) colExpr.getLeft();
    List<Integer> params = subqueryExpr.getParameterIdxList();
    assertEquals(1, params.size());
    assertEquals(new Integer(0), params.get(0));
}
Also used : AbstractPlanNode(org.voltdb.plannodes.AbstractPlanNode) AbstractScanPlanNode(org.voltdb.plannodes.AbstractScanPlanNode) AbstractExpression(org.voltdb.expressions.AbstractExpression) AbstractSubqueryExpression(org.voltdb.expressions.AbstractSubqueryExpression) SchemaColumn(org.voltdb.plannodes.SchemaColumn) NodeSchema(org.voltdb.plannodes.NodeSchema)

Example 75 with AbstractExpression

use of org.voltdb.expressions.AbstractExpression in project voltdb by VoltDB.

the class TestPlansScalarSubQueries method testWhereUserParamScalar.

public void testWhereUserParamScalar() {
    AbstractPlanNode pn = compile("select r2.c from r2 where r2.c = (select r1.a from r1 where r1.a = ?);");
    pn = pn.getChild(0);
    assertTrue(pn instanceof AbstractScanPlanNode);
    AbstractExpression pred = ((AbstractScanPlanNode) pn).getPredicate();
    assertEquals(ExpressionType.COMPARE_EQUAL, pred.getExpressionType());
    assertEquals(ExpressionType.VALUE_TUPLE, pred.getLeft().getExpressionType());
    assertEquals(ExpressionType.SELECT_SUBQUERY, pred.getRight().getExpressionType());
    assertEquals(0, pred.getRight().getArgs().size());
}
Also used : AbstractPlanNode(org.voltdb.plannodes.AbstractPlanNode) AbstractScanPlanNode(org.voltdb.plannodes.AbstractScanPlanNode) AbstractExpression(org.voltdb.expressions.AbstractExpression)

Aggregations

AbstractExpression (org.voltdb.expressions.AbstractExpression)215 TupleValueExpression (org.voltdb.expressions.TupleValueExpression)59 AbstractPlanNode (org.voltdb.plannodes.AbstractPlanNode)55 ArrayList (java.util.ArrayList)43 SeqScanPlanNode (org.voltdb.plannodes.SeqScanPlanNode)26 SchemaColumn (org.voltdb.plannodes.SchemaColumn)25 NestLoopPlanNode (org.voltdb.plannodes.NestLoopPlanNode)23 Constraint (org.voltdb.catalog.Constraint)22 IndexScanPlanNode (org.voltdb.plannodes.IndexScanPlanNode)22 HashSet (java.util.HashSet)21 Column (org.voltdb.catalog.Column)21 AbstractScanPlanNode (org.voltdb.plannodes.AbstractScanPlanNode)21 JSONException (org.json_voltpatches.JSONException)19 ColumnRef (org.voltdb.catalog.ColumnRef)19 Table (org.voltdb.catalog.Table)17 AbstractSubqueryExpression (org.voltdb.expressions.AbstractSubqueryExpression)16 ParameterValueExpression (org.voltdb.expressions.ParameterValueExpression)16 StmtTableScan (org.voltdb.planner.parseinfo.StmtTableScan)16 ExpressionType (org.voltdb.types.ExpressionType)16 VoltXMLElement (org.hsqldb_voltpatches.VoltXMLElement)14