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;
}
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);
}
}
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;
}
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());
}
}
}
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();
}
Aggregations