Search in sources :

Example 21 with TupleValueExpression

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

the class ParsedSelectStmt method isPartitionColumnInWindowedAggregatePartitionByList.

/**
     * Return true iff all the windowed partition expressions
     * have a table partition column in their partition by list,
     * and if there is one such windowed partition expression.
     * If there are no windowed expressions, we return false.
     * Note that there can only be one windowed
     * expression currently, so this is more general than it needs to be.
     *
     * @return
     */
public boolean isPartitionColumnInWindowedAggregatePartitionByList() {
    if (getWindowFunctionExpressions().size() == 0) {
        return false;
    }
    // If we ever do, this should fail gracelessly.
    assert (getWindowFunctionExpressions().size() == 1);
    WindowFunctionExpression we = getWindowFunctionExpressions().get(0);
    List<AbstractExpression> partitionByExprs = we.getPartitionByExpressions();
    boolean foundPartExpr = false;
    for (AbstractExpression ae : partitionByExprs) {
        if (!(ae instanceof TupleValueExpression)) {
            continue;
        }
        TupleValueExpression tve = (TupleValueExpression) ae;
        String tableAlias = tve.getTableAlias();
        String columnName = tve.getColumnName();
        StmtTableScan scanTable = getStmtTableScanByAlias(tableAlias);
        if (scanTable == null || scanTable.getPartitioningColumns() == null) {
            continue;
        }
        boolean foundPartCol = false;
        for (SchemaColumn pcol : scanTable.getPartitioningColumns()) {
            if (pcol != null && pcol.getColumnName().equals(columnName)) {
                foundPartCol = true;
                break;
            }
        }
        // in this windowed expression.
        if (foundPartCol) {
            foundPartExpr = true;
            break;
        }
    }
    return foundPartExpr;
}
Also used : TupleValueExpression(org.voltdb.expressions.TupleValueExpression) AbstractExpression(org.voltdb.expressions.AbstractExpression) WindowFunctionExpression(org.voltdb.expressions.WindowFunctionExpression) SchemaColumn(org.voltdb.plannodes.SchemaColumn) StmtTableScan(org.voltdb.planner.parseinfo.StmtTableScan)

Example 22 with TupleValueExpression

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

the class StmtSubqueryScan method addPartitioningColumns.

private void addPartitioningColumns(List<SchemaColumn> scols) {
    // in order to be referenced on parent level.
    for (SchemaColumn partitionCol : scols) {
        SchemaColumn matchedCol = null;
        // Find whether the partition column is in output column list
        for (SchemaColumn outputCol : m_outputColumnList) {
            AbstractExpression outputExpr = outputCol.getExpression();
            if (!(outputExpr instanceof TupleValueExpression)) {
                continue;
            }
            TupleValueExpression tve = (TupleValueExpression) outputExpr;
            if (tve.getTableName().equals(partitionCol.getTableName()) && tve.getColumnName().equals(partitionCol.getColumnName())) {
                matchedCol = outputCol;
                break;
            }
        }
        String colNameForParentQuery;
        if (matchedCol != null) {
            colNameForParentQuery = matchedCol.getColumnAlias();
        } else // including partition column in its display column list
        if (!m_subqueriesPartitioning.requiresTwoFragments()) {
            colNameForParentQuery = partitionCol.getColumnName();
        } else {
            continue;
        }
        partitionCol.reset(m_tableAlias, m_tableAlias, colNameForParentQuery, colNameForParentQuery);
        m_partitioningColumns.add(partitionCol);
    }
}
Also used : TupleValueExpression(org.voltdb.expressions.TupleValueExpression) AbstractExpression(org.voltdb.expressions.AbstractExpression) SchemaColumn(org.voltdb.plannodes.SchemaColumn)

Example 23 with TupleValueExpression

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

the class StmtSubqueryScan method getOutputExpression.

/** Produce a tuple value expression for a column produced by this subquery */
public TupleValueExpression getOutputExpression(int index) {
    SchemaColumn schemaCol = m_outputColumnList.get(index);
    TupleValueExpression tve = new TupleValueExpression(getTableAlias(), getTableAlias(), schemaCol.getColumnAlias(), schemaCol.getColumnAlias(), index);
    return tve;
}
Also used : TupleValueExpression(org.voltdb.expressions.TupleValueExpression) SchemaColumn(org.voltdb.plannodes.SchemaColumn)

Example 24 with TupleValueExpression

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

the class AbstractScanPlanNode method initTableSchema.

private void initTableSchema(Database db) {
    if (isSubQuery()) {
        assert (m_children.size() == 1);
        AbstractPlanNode childNode = m_children.get(0);
        childNode.generateOutputSchema(db);
        m_tableSchema = childNode.getOutputSchema();
        // step to transfer derived table schema to upper level
        m_tableSchema = m_tableSchema.replaceTableClone(getTargetTableAlias());
    } else {
        m_tableSchema = new NodeSchema();
        CatalogMap<Column> cols = db.getTables().getExact(m_targetTableName).getColumns();
        // you don't strictly need to sort this,
        // but it makes diff-ing easier
        List<Column> sortedCols = CatalogUtil.getSortedCatalogItems(cols, "index");
        for (Column col : sortedCols) {
            // must produce a tuple value expression for this column.
            TupleValueExpression tve = new TupleValueExpression(m_targetTableName, m_targetTableAlias, col, col.getIndex());
            m_tableSchema.addColumn(m_targetTableName, m_targetTableAlias, col.getTypeName(), col.getTypeName(), tve, col.getIndex());
        }
    }
}
Also used : TupleValueExpression(org.voltdb.expressions.TupleValueExpression) Column(org.voltdb.catalog.Column)

Example 25 with TupleValueExpression

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

the class AggregatePlanNode method resolveColumnIndexesUsingSchema.

void resolveColumnIndexesUsingSchema(NodeSchema inputSchema) {
    Collection<TupleValueExpression> allTves;
    // get all the TVEs in the output columns
    for (SchemaColumn col : m_outputSchema.getColumns()) {
        AbstractExpression colExpr = col.getExpression();
        allTves = ExpressionUtil.getTupleValueExpressions(colExpr);
        for (TupleValueExpression tve : allTves) {
            int index = tve.setColumnIndexUsingSchema(inputSchema);
            if (index == -1) {
                // check to see if this TVE is the aggregate output
                if (!tve.getTableName().equals(AbstractParsedStmt.TEMP_TABLE_NAME)) {
                    throw new RuntimeException("Unable to find index for column: " + tve.getColumnName());
                }
            }
        }
    }
    for (AbstractExpression agg_exp : m_aggregateExpressions) {
        allTves = ExpressionUtil.getTupleValueExpressions(agg_exp);
        for (TupleValueExpression tve : allTves) {
            tve.setColumnIndexUsingSchema(inputSchema);
        }
    }
    // Aggregates also need to resolve indexes for group_by inputs
    for (AbstractExpression group_exp : m_groupByExpressions) {
        allTves = ExpressionUtil.getTupleValueExpressions(group_exp);
        for (TupleValueExpression tve : allTves) {
            tve.setColumnIndexUsingSchema(inputSchema);
        }
    }
    // Post filter also needs to resolve indexes, but a little
    // differently since it applies to the OUTPUT tuple.
    allTves = ExpressionUtil.getTupleValueExpressions(m_postPredicate);
    for (TupleValueExpression tve : allTves) {
        int index = m_outputSchema.getIndexOfTve(tve);
        tve.setColumnIndex(index);
    }
    resolveSubqueryColumnIndexes();
}
Also used : TupleValueExpression(org.voltdb.expressions.TupleValueExpression) AbstractExpression(org.voltdb.expressions.AbstractExpression)

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