use of org.voltdb.expressions.TupleValueExpression 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());
}
use of org.voltdb.expressions.TupleValueExpression in project voltdb by VoltDB.
the class TestPlansSubQueries method checkPredicateComparisonExpression.
private void checkPredicateComparisonExpression(AbstractPlanNode pn, String tableAlias) {
AbstractExpression expr = ((SeqScanPlanNode) pn).getPredicate();
assertTrue(expr instanceof ComparisonExpression);
expr = expr.getLeft();
assertTrue(expr instanceof TupleValueExpression);
assertEquals(tableAlias, ((TupleValueExpression) expr).getTableAlias());
}
use of org.voltdb.expressions.TupleValueExpression in project voltdb by VoltDB.
the class TestPlansScalarSubQueries method testSelectCorrelatedScalarInGroupbyClause.
public void testSelectCorrelatedScalarInGroupbyClause() {
String sql = "select franchise_id, count(*) as stores_in_category_AdHoc " + " from stores group by franchise_id, (select category from store_types where type_id = stores.type_id);";
AbstractPlanNode pn = compile(sql);
pn = pn.getChild(0);
assertTrue(pn instanceof ProjectionPlanNode);
NodeSchema schema = pn.getOutputSchema();
assertEquals(2, schema.size());
pn = pn.getChild(0);
assertTrue(pn instanceof AbstractScanPlanNode);
assertNotNull(pn.getInlinePlanNode(PlanNodeType.HASHAGGREGATE));
HashAggregatePlanNode aggNode = (HashAggregatePlanNode) pn.getInlinePlanNode(PlanNodeType.HASHAGGREGATE);
assertEquals(2, aggNode.getGroupByExpressionsSize());
AbstractExpression tveExpr = aggNode.getGroupByExpressions().get(0);
assertTrue(tveExpr instanceof TupleValueExpression);
AbstractExpression gbExpr = aggNode.getGroupByExpressions().get(1);
assertTrue(gbExpr instanceof ScalarValueExpression);
assertTrue(gbExpr.getLeft() instanceof SelectSubqueryExpression);
}
use of org.voltdb.expressions.TupleValueExpression in project voltdb by VoltDB.
the class ProjectionPlanNode method resolveColumnIndexesUsingSchema.
/**
* Given an input schema, resolve all the TVEs in all the output column
* expressions. This method is necessary to be able to do this for
* inlined projection nodes that don't have a child from which they can get
* an output schema.
*/
void resolveColumnIndexesUsingSchema(NodeSchema inputSchema) {
// get all the TVEs in the output columns
int difftor = 0;
for (SchemaColumn col : m_outputSchema.getColumns()) {
col.setDifferentiator(difftor);
++difftor;
Collection<TupleValueExpression> allTves = ExpressionUtil.getTupleValueExpressions(col.getExpression());
// and update their indexes against the table schema
for (TupleValueExpression tve : allTves) {
tve.setColumnIndexUsingSchema(inputSchema);
}
}
// DON'T RE-SORT HERE
}
use of org.voltdb.expressions.TupleValueExpression in project voltdb by VoltDB.
the class SchemaColumn method reset.
public void reset(String tbName, String tbAlias, String colName, String colAlias) {
m_tableName = tbName;
m_tableAlias = tbAlias;
m_columnName = colName;
m_columnAlias = colAlias;
if (m_expression instanceof TupleValueExpression) {
TupleValueExpression tve = (TupleValueExpression) m_expression;
tve.setTableName(m_tableName);
tve.setTableAlias(m_tableAlias);
tve.setColumnName(m_columnName);
tve.setColumnAlias(m_columnAlias);
}
}
Aggregations