use of org.apache.calcite.test.SqlToRelTestBase.CustomCorrelate in project calcite by apache.
the class RelOptRulesTest method testCustomDecorrelate.
/**
* Test case for
* <a href="https://issues.apache.org/jira/browse/CALCITE-3111">[CALCITE-3111]
* Allow custom implementations of Correlate in RelDecorrelator</a>.
*/
@Test
void testCustomDecorrelate() {
final String sql = "SELECT e1.empno\n" + "FROM emp e1, dept d1 where e1.deptno = d1.deptno\n" + "and e1.deptno < 10 and d1.deptno < 15\n" + "and e1.sal > (select avg(sal) from emp e2 where e1.empno = e2.empno)";
// Convert sql to rel
final RelOptFixture fixture = sql(sql);
final RelNode rel = fixture.toRel();
// Create a duplicate rel tree with a CustomCorrelate instead of
// LogicalCorrelate.
final LogicalCorrelate logicalCorrelate = (LogicalCorrelate) rel.getInput(0).getInput(0);
CustomCorrelate customCorrelate = new CustomCorrelate(logicalCorrelate.getCluster(), logicalCorrelate.getTraitSet(), logicalCorrelate.getHints(), logicalCorrelate.getLeft(), logicalCorrelate.getRight(), logicalCorrelate.getCorrelationId(), logicalCorrelate.getRequiredColumns(), logicalCorrelate.getJoinType());
RelNode newRoot = rel.copy(rel.getTraitSet(), ImmutableList.of(rel.getInput(0).copy(rel.getInput(0).getTraitSet(), ImmutableList.of(customCorrelate))));
// Decorrelate both trees using the same relBuilder
final RelBuilder relBuilder = RelBuilder.create(RelBuilderTest.config().build());
RelNode logicalDecorrelated = RelDecorrelator.decorrelateQuery(rel, relBuilder);
RelNode customDecorrelated = RelDecorrelator.decorrelateQuery(newRoot, relBuilder);
String logicalDecorrelatedPlan = NL + RelOptUtil.toString(logicalDecorrelated);
String customDecorrelatedPlan = NL + RelOptUtil.toString(customDecorrelated);
// Ensure that the plans are equal
fixture.diffRepos.assertEquals("Comparing Plans from LogicalCorrelate and CustomCorrelate", logicalDecorrelatedPlan, customDecorrelatedPlan);
}
Aggregations