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