Search in sources :

Example 26 with SchemaColumn

use of org.voltdb.plannodes.SchemaColumn in project voltdb by VoltDB.

the class AbstractParsedStmt method toString.

@Override
public String toString() {
    String retval = "SQL:\n\t" + m_sql + "\n";
    retval += "PARAMETERS:\n\t";
    for (Map.Entry<Integer, ParameterValueExpression> paramEntry : m_paramsByIndex.entrySet()) {
        retval += paramEntry.getValue().toString() + " ";
    }
    retval += "\nTABLE SOURCES:\n\t";
    for (Table table : m_tableList) {
        retval += table.getTypeName() + " ";
    }
    retval += "\nSCAN COLUMNS:\n";
    boolean hasAll = true;
    for (StmtTableScan tableScan : m_tableAliasMap.values()) {
        List<SchemaColumn> scanColumns = tableScan.getScanColumns();
        if (scanColumns.isEmpty()) {
            continue;
        }
        hasAll = false;
        retval += "\tTable Alias: " + tableScan.getTableAlias() + ":\n";
        for (SchemaColumn col : scanColumns) {
            retval += "\t\tColumn: " + col.getColumnName() + ": ";
            retval += col.getExpression().toString() + "\n";
        }
    }
    if (hasAll) {
        retval += "\tALL\n";
    }
    retval += "\nJOIN TREE :\n";
    if (m_joinTree != null) {
        retval += m_joinTree.toString();
    }
    retval += "NO TABLE SELECTION LIST:\n";
    int i = 0;
    for (AbstractExpression expr : m_noTableSelectionList) {
        retval += "\t(" + String.valueOf(i++) + ") " + expr.toString() + "\n";
    }
    return retval;
}
Also used : Table(org.voltdb.catalog.Table) AbstractExpression(org.voltdb.expressions.AbstractExpression) SchemaColumn(org.voltdb.plannodes.SchemaColumn) ParameterValueExpression(org.voltdb.expressions.ParameterValueExpression) HashMap(java.util.HashMap) Map(java.util.Map) TreeMap(java.util.TreeMap) CatalogMap(org.voltdb.catalog.CatalogMap) Constraint(org.voltdb.catalog.Constraint) StmtTableScan(org.voltdb.planner.parseinfo.StmtTableScan)

Example 27 with SchemaColumn

use of org.voltdb.plannodes.SchemaColumn in project voltdb by VoltDB.

the class PlanAssembler method canPushDownDistinctAggregation.

private boolean canPushDownDistinctAggregation(AggregateExpression aggExpr) {
    assert (m_parsedSelect != null);
    assert (aggExpr != null);
    assert (aggExpr.isDistinct());
    if (aggExpr.getExpressionType() == ExpressionType.AGGREGATE_COUNT_STAR) {
        return true;
    }
    AbstractExpression aggArg = aggExpr.getLeft();
    // constant
    if (aggArg instanceof ConstantValueExpression || aggArg instanceof ParameterValueExpression) {
        return true;
    }
    if (!(aggArg instanceof TupleValueExpression)) {
        return false;
    }
    TupleValueExpression tve = (TupleValueExpression) aggArg;
    String tableAlias = tve.getTableAlias();
    StmtTableScan scanTable = m_parsedSelect.getStmtTableScanByAlias(tableAlias);
    // table alias may be from AbstractParsedStmt.TEMP_TABLE_NAME.
    if (scanTable == null || scanTable.getPartitioningColumns() == null) {
        return false;
    }
    for (SchemaColumn pcol : scanTable.getPartitioningColumns()) {
        if (pcol != null && pcol.getColumnName().equals(tve.getColumnName())) {
            return true;
        }
    }
    return false;
}
Also used : TupleValueExpression(org.voltdb.expressions.TupleValueExpression) AbstractExpression(org.voltdb.expressions.AbstractExpression) ConstantValueExpression(org.voltdb.expressions.ConstantValueExpression) SchemaColumn(org.voltdb.plannodes.SchemaColumn) ParameterValueExpression(org.voltdb.expressions.ParameterValueExpression) StmtTableScan(org.voltdb.planner.parseinfo.StmtTableScan)

Example 28 with SchemaColumn

use of org.voltdb.plannodes.SchemaColumn in project voltdb by VoltDB.

the class PlanAssembler method addProjection.

/**
     * Given a relatively complete plan-sub-graph, apply a trivial projection
     * (filter) to it. If the root node can embed the projection do so. If not,
     * add a new projection node.
     *
     * @param rootNode
     *            The root of the plan-sub-graph to add the projection to.
     * @return The new root of the plan-sub-graph (might be the same as the
     *         input).
     */
private AbstractPlanNode addProjection(AbstractPlanNode rootNode) {
    assert (m_parsedSelect != null);
    assert (m_parsedSelect.m_displayColumns != null);
    // Build the output schema for the projection based on the display columns
    NodeSchema proj_schema = m_parsedSelect.getFinalProjectionSchema();
    for (SchemaColumn col : proj_schema.getColumns()) {
        // Adjust the differentiator fields of TVEs, since they need to
        // reflect the inlined projection node in scan nodes.
        AbstractExpression colExpr = col.getExpression();
        Collection<TupleValueExpression> allTves = ExpressionUtil.getTupleValueExpressions(colExpr);
        for (TupleValueExpression tve : allTves) {
            if (!tve.needsDifferentiation()) {
                // so we just ignore it here.
                continue;
            }
            rootNode.adjustDifferentiatorField(tve);
        }
    }
    ProjectionPlanNode projectionNode = new ProjectionPlanNode();
    projectionNode.setOutputSchemaWithoutClone(proj_schema);
    // projection node inline.
    if (rootNode instanceof AbstractScanPlanNode) {
        rootNode.addInlinePlanNode(projectionNode);
        return rootNode;
    }
    projectionNode.addAndLinkChild(rootNode);
    return projectionNode;
}
Also used : TupleValueExpression(org.voltdb.expressions.TupleValueExpression) AbstractScanPlanNode(org.voltdb.plannodes.AbstractScanPlanNode) AbstractExpression(org.voltdb.expressions.AbstractExpression) SchemaColumn(org.voltdb.plannodes.SchemaColumn) NodeSchema(org.voltdb.plannodes.NodeSchema) ProjectionPlanNode(org.voltdb.plannodes.ProjectionPlanNode)

Example 29 with SchemaColumn

use of org.voltdb.plannodes.SchemaColumn in project voltdb by VoltDB.

the class ParsedSelectStmt method checkPlanColumnMatch.

void checkPlanColumnMatch(List<SchemaColumn> columns) {
    // Sanity-check the output NodeSchema columns against the display columns
    if (m_displayColumns.size() != columns.size()) {
        throw new PlanningErrorException("Mismatched plan output cols to parsed display columns");
    }
    int ii = 0;
    for (ParsedColInfo display_col : m_displayColumns) {
        SchemaColumn sc = columns.get(ii);
        ++ii;
        boolean sameTable = false;
        if (display_col.tableAlias != null) {
            if (display_col.tableAlias.equals(sc.getTableAlias())) {
                sameTable = true;
            }
        } else if (display_col.tableName.equals(sc.getTableName())) {
            sameTable = true;
        }
        if (sameTable) {
            String displayAlias = display_col.alias;
            if (displayAlias != null && !displayAlias.equals("")) {
                if (displayAlias.equals(sc.getColumnAlias())) {
                    continue;
                }
            } else {
                String displayName = display_col.columnName;
                if (displayName != null && (!displayName.equals("")) && displayName.equals(sc.getColumnName())) {
                    continue;
                }
            }
        }
        throw new PlanningErrorException("Mismatched plan output cols to parsed display columns");
    }
}
Also used : SchemaColumn(org.voltdb.plannodes.SchemaColumn)

Example 30 with SchemaColumn

use of org.voltdb.plannodes.SchemaColumn 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)

Aggregations

SchemaColumn (org.voltdb.plannodes.SchemaColumn)37 AbstractExpression (org.voltdb.expressions.AbstractExpression)19 TupleValueExpression (org.voltdb.expressions.TupleValueExpression)16 AbstractPlanNode (org.voltdb.plannodes.AbstractPlanNode)13 NodeSchema (org.voltdb.plannodes.NodeSchema)13 ProjectionPlanNode (org.voltdb.plannodes.ProjectionPlanNode)6 HashSet (java.util.HashSet)5 StmtTableScan (org.voltdb.planner.parseinfo.StmtTableScan)5 AbstractScanPlanNode (org.voltdb.plannodes.AbstractScanPlanNode)5 NestLoopPlanNode (org.voltdb.plannodes.NestLoopPlanNode)5 Table (org.voltdb.catalog.Table)4 OrderByPlanNode (org.voltdb.plannodes.OrderByPlanNode)4 SeqScanPlanNode (org.voltdb.plannodes.SeqScanPlanNode)4 ArrayList (java.util.ArrayList)3 HashMap (java.util.HashMap)3 Column (org.voltdb.catalog.Column)3 Constraint (org.voltdb.catalog.Constraint)3 AbstractReceivePlanNode (org.voltdb.plannodes.AbstractReceivePlanNode)3 SendPlanNode (org.voltdb.plannodes.SendPlanNode)3 Set (java.util.Set)2