use of org.voltdb.plannodes.SchemaColumn 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.plannodes.SchemaColumn in project voltdb by VoltDB.
the class StmtTargetTableScan method findPartitioningColumns.
private List<SchemaColumn> findPartitioningColumns() {
if (m_partitioningColumns != null) {
return m_partitioningColumns;
}
if (getIsReplicated()) {
return null;
}
Column partitionCol = m_table.getPartitioncolumn();
// because it has no recognized partitioning join key.
if (partitionCol == null) {
return null;
}
String tbName = m_table.getTypeName();
TupleValueExpression tve = new TupleValueExpression(tbName, m_tableAlias, partitionCol, partitionCol.getIndex());
String colName = partitionCol.getTypeName();
SchemaColumn scol = new SchemaColumn(tbName, m_tableAlias, colName, colName, tve);
m_partitioningColumns = new ArrayList<SchemaColumn>();
m_partitioningColumns.add(scol);
return m_partitioningColumns;
}
use of org.voltdb.plannodes.SchemaColumn in project voltdb by VoltDB.
the class TestWindowedFunctions method validateWindowedFunctionPlan.
/**
* Validate that each similar windowed query in testRank produces a similar
* plan, with the expected minor variation to its ORDER BY node.
* @param windowedQuery a variant of a test query of a known basic format
* @param nSorts the expected number of sort criteria that should have been
* extracted from the variant query's PARTITION BY and ORDER BY.
* @param descSortIndex the position among the sort criteria of the original
* ORDER BY column, always distinguishable by its "DESC" direction.
**/
private void validateWindowedFunctionPlan(String windowedQuery, int nSorts, int descSortIndex, int numPartitionExprs, ExpressionType winOpType) {
// Sometimes we get multi-fragment nodes when we
// expect single fragment nodes. Keeping all the fragments
// helps to diagnose the problem.
List<AbstractPlanNode> nodes = compileToFragments(windowedQuery);
assertEquals(1, nodes.size());
AbstractPlanNode node = nodes.get(0);
// The plan should look like:
// SendNode -> ProjectionPlanNode -> PartitionByPlanNode -> OrderByPlanNode -> SeqScanNode
// We also do some sanity checking on the PartitionPlan node.
// First dissect the plan.
assertTrue(node instanceof SendPlanNode);
AbstractPlanNode projPlanNode = node.getChild(0);
assertTrue(projPlanNode instanceof ProjectionPlanNode);
AbstractPlanNode windowFuncPlanNode = projPlanNode.getChild(0);
assertTrue(windowFuncPlanNode instanceof WindowFunctionPlanNode);
AbstractPlanNode abstractOrderByNode = windowFuncPlanNode.getChild(0);
assertTrue(abstractOrderByNode instanceof OrderByPlanNode);
OrderByPlanNode orderByNode = (OrderByPlanNode) abstractOrderByNode;
NodeSchema input_schema = orderByNode.getOutputSchema();
assertNotNull(input_schema);
AbstractPlanNode seqScanNode = orderByNode.getChild(0);
assertTrue(seqScanNode instanceof SeqScanPlanNode || seqScanNode instanceof NestLoopPlanNode);
WindowFunctionPlanNode wfPlanNode = (WindowFunctionPlanNode) windowFuncPlanNode;
NodeSchema schema = wfPlanNode.getOutputSchema();
//
// Check that the window function plan node's output schema is correct.
// Look at the first expression, to verify that it's the windowed expression.
// Then check that the TVEs all make sense.
//
SchemaColumn column = schema.getColumns().get(0);
assertEquals("ARANK", column.getColumnAlias());
assertEquals(numPartitionExprs, wfPlanNode.getPartitionByExpressions().size());
validateTVEs(input_schema, wfPlanNode, false);
//
// Check that the operation is what we expect.
//
assertTrue(wfPlanNode.getAggregateTypes().size() > 0);
assertEquals(winOpType, wfPlanNode.getAggregateTypes().get(0));
//
for (List<AbstractExpression> exprs : wfPlanNode.getAggregateExpressions()) {
if (exprs != null) {
for (AbstractExpression expr : exprs) {
assertNotNull(expr.getValueType());
}
}
}
//
// Check that the order by node has the right number of expressions.
// and that they have the correct order.
//
assertEquals(nSorts, orderByNode.getSortExpressions().size());
int sortIndex = 0;
for (SortDirectionType direction : orderByNode.getSortDirections()) {
SortDirectionType expected = (sortIndex == descSortIndex) ? SortDirectionType.DESC : SortDirectionType.ASC;
assertEquals(expected, direction);
++sortIndex;
}
}
use of org.voltdb.plannodes.SchemaColumn in project voltdb by VoltDB.
the class TestWindowedFunctions method validateQueryWithSubquery.
/**
* Validate that each similar windowed query in testRankWithSubqueries
* produces a similar plan
* @param windowedQuery a variant of a test query of a known basic format
**/
private void validateQueryWithSubquery(String windowedQuery, boolean waiveAliasMatch) {
AbstractPlanNode node = compile(windowedQuery);
// Dissect the plan.
assertTrue(node instanceof SendPlanNode);
AbstractPlanNode projectionPlanNode = node.getChild(0);
assertTrue(projectionPlanNode instanceof ProjectionPlanNode);
AbstractPlanNode partitionByPlanNode = projectionPlanNode.getChild(0);
assertTrue(partitionByPlanNode instanceof WindowFunctionPlanNode);
AbstractPlanNode orderByPlanNode = partitionByPlanNode.getChild(0);
assertTrue(orderByPlanNode instanceof OrderByPlanNode);
NodeSchema input_schema = orderByPlanNode.getOutputSchema();
AbstractPlanNode scanNode = orderByPlanNode.getChild(0);
assertTrue(scanNode instanceof NestLoopPlanNode);
NodeSchema schema = partitionByPlanNode.getOutputSchema();
SchemaColumn column = schema.getColumns().get(0);
assertEquals("ARANK", column.getColumnAlias());
validateTVEs(input_schema, (WindowFunctionPlanNode) partitionByPlanNode, waiveAliasMatch);
}
use of org.voltdb.plannodes.SchemaColumn in project voltdb by VoltDB.
the class TestWindowedFunctions method nodeSchemaString.
public String nodeSchemaString(String label, NodeSchema schema) {
List<SchemaColumn> columns = schema.getColumns();
StringBuffer sb = new StringBuffer();
sb.append(label).append(": \n");
for (SchemaColumn col : columns) {
sb.append(" ").append(col.getTableName()).append(": ").append(col.getTableAlias()).append(", ").append(col.getColumnName()).append(": ").append(col.getColumnAlias()).append(";");
sb.append("\n");
}
return sb.toString();
}
Aggregations