public void testDisplayColumnFromUsingCondition() {
AbstractPlanNode pn = compile("select max(A) FROM R1 JOIN R2 USING(A)");
pn = pn.getChild(0);
assertNotNull(AggregatePlanNode.getInlineAggregationNode(pn));
assertTrue(pn instanceof NestLoopPlanNode);
NodeSchema ns = pn.getOutputSchema();
for (SchemaColumn sc : ns.getColumns()) {
AbstractExpression e = sc.getExpression();
assertTrue(e instanceof TupleValueExpression);
TupleValueExpression tve = (TupleValueExpression) e;
assertNotSame(-1, tve.getColumnIndex());
}
pn = compile("select distinct(A) FROM R1 JOIN R2 USING(A)");
pn = pn.getChild(0);
assertTrue(pn instanceof ProjectionPlanNode);
ns = pn.getOutputSchema();
for (SchemaColumn sc : ns.getColumns()) {
AbstractExpression e = sc.getExpression();
assertTrue(e instanceof TupleValueExpression);
TupleValueExpression tve = (TupleValueExpression) e;
assertNotSame(-1, tve.getColumnIndex());
}
pn = pn.getChild(0);
assertTrue(pn instanceof DistinctPlanNode);
ns = pn.getOutputSchema();
for (SchemaColumn sc : ns.getColumns()) {
AbstractExpression e = sc.getExpression();
assertTrue(e instanceof TupleValueExpression);
TupleValueExpression tve = (TupleValueExpression) e;
assertNotSame(-1, tve.getColumnIndex());
}
pn = compile("select A FROM R1 JOIN R2 USING(A) ORDER BY A");
pn = pn.getChild(0);
assertTrue(pn instanceof ProjectionPlanNode);
ns = pn.getOutputSchema();
for (SchemaColumn sc : ns.getColumns()) {
AbstractExpression e = sc.getExpression();
assertTrue(e instanceof TupleValueExpression);
TupleValueExpression tve = (TupleValueExpression) e;
assertNotSame(-1, tve.getColumnIndex());
}
pn = pn.getChild(0);
assertTrue(pn instanceof OrderByPlanNode);
ns = pn.getOutputSchema();
for (SchemaColumn sc : ns.getColumns()) {
AbstractExpression e = sc.getExpression();
assertTrue(e instanceof TupleValueExpression);
TupleValueExpression tve = (TupleValueExpression) e;
assertNotSame(-1, tve.getColumnIndex());
}
List<AbstractPlanNode> apl;
AbstractPlanNode node;
SeqScanPlanNode seqScan;
NestLoopPlanNode nlj;
apl = compileToFragments("select * FROM P1 LABEL JOIN R2 USING(A) WHERE A > 0 and R2.C >= 5");
pn = apl.get(1);
node = pn.getChild(0);
assertTrue(node instanceof NestLoopPlanNode);
assertEquals(ExpressionType.COMPARE_EQUAL,
((NestLoopPlanNode)node).getJoinPredicate().getExpressionType());
assertTrue(node.getChild(0) instanceof SeqScanPlanNode);
seqScan = (SeqScanPlanNode)node.getChild(0);
assertTrue(seqScan.getPredicate() == null);
node = node.getChild(1);
assertTrue(node instanceof SeqScanPlanNode);
seqScan = (SeqScanPlanNode)node;
assertEquals(ExpressionType.CONJUNCTION_AND, seqScan.getPredicate().getExpressionType());
apl = compileToFragments("select * FROM P1 LABEL LEFT JOIN R2 USING(A) WHERE A > 0");
pn = apl.get(1);
node = pn.getChild(0);
assertTrue(node instanceof NestLoopPlanNode);
nlj = (NestLoopPlanNode) node;
assertTrue(JoinType.LEFT == nlj.getJoinType());
assertEquals(ExpressionType.COMPARE_EQUAL, nlj.getJoinPredicate().getExpressionType());
seqScan = (SeqScanPlanNode)node.getChild(0);
assertTrue(seqScan.getPredicate() != null);
assertEquals(ExpressionType.COMPARE_GREATERTHAN, seqScan.getPredicate().getExpressionType());
apl = compileToFragments("select A FROM R2 LABEL RIGHT JOIN P1 AP1 USING(A) WHERE A > 0");
pn = apl.get(0);
ns = pn.getOutputSchema();
assertEquals(1, ns.size());
SchemaColumn sc = ns.getColumns().get(0);
assertEquals("AP1", sc.getTableAlias());
assertEquals("P1", sc.getTableName());
pn = apl.get(1);
node = pn.getChild(0);
assertTrue(node instanceof NestLoopPlanNode);
nlj = (NestLoopPlanNode) node;
assertTrue(JoinType.LEFT == nlj.getJoinType());
assertEquals(ExpressionType.COMPARE_EQUAL, nlj.getJoinPredicate().getExpressionType());
seqScan = (SeqScanPlanNode)node.getChild(0);
assertTrue(seqScan.getPredicate() != null);
assertEquals(ExpressionType.COMPARE_GREATERTHAN, seqScan.getPredicate().getExpressionType());
ns = seqScan.getOutputSchema();
assertEquals(1, ns.size());
sc = ns.getColumns().get(0);
assertEquals("AP1", sc.getTableAlias());
assertEquals("P1", sc.getTableName());
}