Search in sources :

Example 71 with TupleValueExpression

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

the class TestPlansJoin method testDisplayColumnFromUsingCondition.

public void testDisplayColumnFromUsingCondition() {
    String query;
    List<AbstractPlanNode> lpn;
    AbstractPlanNode pn;
    AbstractPlanNode node;
    NestLoopPlanNode nlj;
    AbstractExpression predicate;
    SeqScanPlanNode seqScan;
    SchemaColumn sc0;
    List<SchemaColumn> selectColumns;
    query = "SELECT max(A) FROM R1 JOIN R2 USING(A)";
    pn = compileToTopDownTree(query, 1, PlanNodeType.SEND, PlanNodeType.NESTLOOP, PlanNodeType.SEQSCAN, PlanNodeType.SEQSCAN);
    selectColumns = pn.getOutputSchema().getColumns();
    for (SchemaColumn sc : selectColumns) {
        AbstractExpression e = sc.getExpression();
        assertTrue(e instanceof TupleValueExpression);
        TupleValueExpression tve = (TupleValueExpression) e;
        assertNotSame(-1, tve.getColumnIndex());
    }
    node = followAssertedLeftChain(pn, PlanNodeType.SEND, PlanNodeType.NESTLOOP);
    assertNotNull(AggregatePlanNode.getInlineAggregationNode(node));
    query = "SELECT distinct(A) FROM R1 JOIN R2 USING(A)";
    pn = compileToTopDownTree(query, 1, PlanNodeType.SEND, PlanNodeType.NESTLOOP, PlanNodeType.SEQSCAN, PlanNodeType.SEQSCAN);
    selectColumns = pn.getOutputSchema().getColumns();
    for (SchemaColumn sc : selectColumns) {
        AbstractExpression e = sc.getExpression();
        assertTrue(e instanceof TupleValueExpression);
        TupleValueExpression tve = (TupleValueExpression) e;
        assertNotSame(-1, tve.getColumnIndex());
    }
    query = "SELECT A FROM R1 JOIN R2 USING(A) ORDER BY A";
    pn = compileToTopDownTree(query, 1, PlanNodeType.SEND, PlanNodeType.PROJECTION, PlanNodeType.ORDERBY, PlanNodeType.NESTLOOP, PlanNodeType.SEQSCAN, PlanNodeType.SEQSCAN);
    selectColumns = pn.getOutputSchema().getColumns();
    for (SchemaColumn sc : selectColumns) {
        AbstractExpression e = sc.getExpression();
        assertTrue(e instanceof TupleValueExpression);
        TupleValueExpression tve = (TupleValueExpression) e;
        assertNotSame(-1, tve.getColumnIndex());
    }
    query = "SELECT * FROM P1 LABEL JOIN R2 USING(A) " + "WHERE A > 0 AND R2.C >= 5";
    lpn = compileToFragments(query);
    assertProjectingCoordinator(lpn);
    pn = lpn.get(1);
    assertTopDownTree(pn, PlanNodeType.SEND, PlanNodeType.NESTLOOP, PlanNodeType.SEQSCAN, PlanNodeType.SEQSCAN);
    node = followAssertedLeftChain(lpn.get(1), PlanNodeType.SEND, PlanNodeType.NESTLOOP);
    nlj = (NestLoopPlanNode) node;
    assertNull(nlj.getPreJoinPredicate());
    predicate = nlj.getJoinPredicate();
    assertExprTopDownTree(predicate, ExpressionType.COMPARE_EQUAL, ExpressionType.VALUE_TUPLE, ExpressionType.VALUE_TUPLE);
    assertNull(nlj.getWherePredicate());
    seqScan = (SeqScanPlanNode) nlj.getChild(0);
    predicate = seqScan.getPredicate();
    assertExprTopDownTree(predicate, ExpressionType.CONJUNCTION_AND, ExpressionType.COMPARE_GREATERTHANOREQUALTO, ExpressionType.VALUE_TUPLE, ExpressionType.VALUE_CONSTANT, ExpressionType.COMPARE_GREATERTHAN, ExpressionType.VALUE_TUPLE, ExpressionType.VALUE_CONSTANT);
    seqScan = (SeqScanPlanNode) nlj.getChild(1);
    assertNull(seqScan.getPredicate());
    query = "SELECT * FROM P1 LABEL LEFT JOIN R2 USING(A) WHERE A > 0";
    lpn = compileToFragments(query);
    node = followAssertedLeftChain(lpn.get(1), PlanNodeType.SEND, PlanNodeType.NESTLOOP);
    nlj = (NestLoopPlanNode) node;
    assertTrue(JoinType.LEFT == nlj.getJoinType());
    assertNull(nlj.getPreJoinPredicate());
    predicate = nlj.getJoinPredicate();
    assertExprTopDownTree(predicate, ExpressionType.COMPARE_EQUAL, ExpressionType.VALUE_TUPLE, ExpressionType.VALUE_TUPLE);
    assertNull(nlj.getWherePredicate());
    seqScan = (SeqScanPlanNode) nlj.getChild(0);
    predicate = seqScan.getPredicate();
    assertExprTopDownTree(predicate, ExpressionType.COMPARE_GREATERTHAN, ExpressionType.VALUE_TUPLE, ExpressionType.VALUE_CONSTANT);
    query = "SELECT A FROM R2 LABEL RIGHT JOIN P1 AP1 USING(A) WHERE A > 0";
    lpn = compileToFragments(query);
    assertProjectingCoordinator(lpn);
    pn = lpn.get(0);
    selectColumns = pn.getOutputSchema().getColumns();
    assertEquals(1, selectColumns.size());
    sc0 = selectColumns.get(0);
    assertEquals("AP1", sc0.getTableAlias());
    assertEquals("P1", sc0.getTableName());
    pn = lpn.get(1);
    assertTopDownTree(pn, PlanNodeType.SEND, PlanNodeType.NESTLOOP, PlanNodeType.SEQSCAN, PlanNodeType.SEQSCAN);
    node = followAssertedLeftChain(lpn.get(1), PlanNodeType.SEND, PlanNodeType.NESTLOOP);
    nlj = (NestLoopPlanNode) node;
    assertEquals(JoinType.LEFT, nlj.getJoinType());
    assertNull(nlj.getPreJoinPredicate());
    predicate = nlj.getJoinPredicate();
    assertExprTopDownTree(predicate, ExpressionType.COMPARE_EQUAL, ExpressionType.VALUE_TUPLE, ExpressionType.VALUE_TUPLE);
    assertNull(nlj.getWherePredicate());
    seqScan = (SeqScanPlanNode) nlj.getChild(0);
    predicate = seqScan.getPredicate();
    assertExprTopDownTree(predicate, ExpressionType.COMPARE_GREATERTHAN, ExpressionType.VALUE_TUPLE, ExpressionType.VALUE_CONSTANT);
    selectColumns = seqScan.getOutputSchema().getColumns();
    assertEquals(1, selectColumns.size());
    sc0 = selectColumns.get(0);
    assertEquals("AP1", sc0.getTableAlias());
    assertEquals("P1", sc0.getTableName());
}
Also used : AbstractPlanNode(org.voltdb.plannodes.AbstractPlanNode) SeqScanPlanNode(org.voltdb.plannodes.SeqScanPlanNode) TupleValueExpression(org.voltdb.expressions.TupleValueExpression) AbstractExpression(org.voltdb.expressions.AbstractExpression) SchemaColumn(org.voltdb.plannodes.SchemaColumn) NestLoopPlanNode(org.voltdb.plannodes.NestLoopPlanNode)

Example 72 with TupleValueExpression

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

the class TestPlansSubQueries method checkPredicateComparisonExpression.

private void checkPredicateComparisonExpression(AbstractPlanNode pn, String tableAlias) {
    AbstractExpression expr = ((SeqScanPlanNode) pn).getPredicate();
    assertTrue(expr instanceof ComparisonExpression);
    expr = expr.getLeft();
    assertTrue(expr instanceof TupleValueExpression);
    assertEquals(tableAlias, ((TupleValueExpression) expr).getTableAlias());
}
Also used : SeqScanPlanNode(org.voltdb.plannodes.SeqScanPlanNode) ComparisonExpression(org.voltdb.expressions.ComparisonExpression) TupleValueExpression(org.voltdb.expressions.TupleValueExpression) AbstractExpression(org.voltdb.expressions.AbstractExpression)

Example 73 with TupleValueExpression

use of org.voltdb.expressions.TupleValueExpression 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 74 with TupleValueExpression

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

the class ProjectionPlanNode method resolveColumnIndexesUsingSchema.

/**
     * Given an input schema, resolve all the TVEs in all the output column
     * expressions.  This method is necessary to be able to do this for
     * inlined projection nodes that don't have a child from which they can get
     * an output schema.
     */
void resolveColumnIndexesUsingSchema(NodeSchema inputSchema) {
    // get all the TVEs in the output columns
    int difftor = 0;
    for (SchemaColumn col : m_outputSchema.getColumns()) {
        col.setDifferentiator(difftor);
        ++difftor;
        Collection<TupleValueExpression> allTves = ExpressionUtil.getTupleValueExpressions(col.getExpression());
        // and update their indexes against the table schema
        for (TupleValueExpression tve : allTves) {
            tve.setColumnIndexUsingSchema(inputSchema);
        }
    }
// DON'T RE-SORT HERE
}
Also used : TupleValueExpression(org.voltdb.expressions.TupleValueExpression)

Example 75 with TupleValueExpression

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

the class SchemaColumn method reset.

public void reset(String tbName, String tbAlias, String colName, String colAlias) {
    m_tableName = tbName;
    m_tableAlias = tbAlias;
    m_columnName = colName;
    m_columnAlias = colAlias;
    if (m_expression instanceof TupleValueExpression) {
        TupleValueExpression tve = (TupleValueExpression) m_expression;
        tve.setTableName(m_tableName);
        tve.setTableAlias(m_tableAlias);
        tve.setColumnName(m_columnName);
        tve.setColumnAlias(m_columnAlias);
    }
}
Also used : TupleValueExpression(org.voltdb.expressions.TupleValueExpression)

Aggregations

TupleValueExpression (org.voltdb.expressions.TupleValueExpression)83 AbstractExpression (org.voltdb.expressions.AbstractExpression)59 SchemaColumn (org.voltdb.plannodes.SchemaColumn)19 Column (org.voltdb.catalog.Column)17 ArrayList (java.util.ArrayList)16 HashSet (java.util.HashSet)14 Constraint (org.voltdb.catalog.Constraint)13 Table (org.voltdb.catalog.Table)10 ColumnRef (org.voltdb.catalog.ColumnRef)9 ParameterValueExpression (org.voltdb.expressions.ParameterValueExpression)9 StmtTableScan (org.voltdb.planner.parseinfo.StmtTableScan)9 JSONException (org.json_voltpatches.JSONException)8 AbstractPlanNode (org.voltdb.plannodes.AbstractPlanNode)8 NodeSchema (org.voltdb.plannodes.NodeSchema)8 ConstantValueExpression (org.voltdb.expressions.ConstantValueExpression)7 VoltXMLElement (org.hsqldb_voltpatches.VoltXMLElement)6 Set (java.util.Set)5 Index (org.voltdb.catalog.Index)5 StmtTargetTableScan (org.voltdb.planner.parseinfo.StmtTargetTableScan)5 ProjectionPlanNode (org.voltdb.plannodes.ProjectionPlanNode)5