use of org.apache.calcite.plan.hep.HepProgram in project calcite by apache.
the class RelOptRulesTest method testMergeSetOpMixed.
/**
* Tests that {@link UnionMergeRule} does nothing if its arguments have
* are different set operators, {@link Union} and {@link Intersect}.
*/
@Test
public void testMergeSetOpMixed() throws Exception {
HepProgram program = new HepProgramBuilder().addRuleInstance(UnionMergeRule.INSTANCE).addRuleInstance(UnionMergeRule.INTERSECT_INSTANCE).build();
final String sql = "select * from emp where deptno = 10\n" + "union\n" + "select * from emp where deptno = 20\n" + "intersect\n" + "select * from emp where deptno = 30\n";
sql(sql).with(program).checkUnchanged();
}
use of org.apache.calcite.plan.hep.HepProgram in project calcite by apache.
the class RelOptRulesTest method testProjectWindowTransposeRuleWithConstants.
@Test
public void testProjectWindowTransposeRuleWithConstants() {
HepProgram program = new HepProgramBuilder().addRuleInstance(ProjectToWindowRule.PROJECT).addRuleInstance(ProjectMergeRule.INSTANCE).addRuleInstance(ProjectWindowTransposeRule.INSTANCE).build();
final String sql = "select col1, col2\n" + "from (\n" + " select empno,\n" + " sum(100) over (partition by deptno order by sal) as col1,\n" + " sum(1000) over(partition by deptno order by sal) as col2\n" + " from emp)";
checkPlanning(program, sql);
}
use of org.apache.calcite.plan.hep.HepProgram in project calcite by apache.
the class RelOptRulesTest method testReduceValuesNull.
// Calcite does not support INSERT yet
@Ignore
@Test
public void testReduceValuesNull() throws Exception {
// The NULL literal presents pitfalls for value-reduction. Only
// an INSERT statement contains un-CASTed NULL values.
HepProgram program = new HepProgramBuilder().addRuleInstance(ValuesReduceRule.PROJECT_INSTANCE).build();
checkPlanning(program, "insert into sales.depts(deptno,name) values (NULL, 'null')");
}
use of org.apache.calcite.plan.hep.HepProgram in project calcite by apache.
the class RelOptRulesTest method testPushSemiJoinPastProject.
@Test
public void testPushSemiJoinPastProject() throws Exception {
HepProgram program = new HepProgramBuilder().addRuleInstance(FilterJoinRule.FILTER_ON_JOIN).addRuleInstance(JoinAddRedundantSemiJoinRule.INSTANCE).addRuleInstance(SemiJoinProjectTransposeRule.INSTANCE).build();
checkPlanning(program, "select e.* from " + "(select ename, trim(job), sal * 2, deptno from emp) e, dept d " + "where e.deptno = d.deptno");
}
use of org.apache.calcite.plan.hep.HepProgram in project calcite by apache.
the class RelOptRulesTest method transitiveInference.
private void transitiveInference(RelOptRule... extraRules) throws Exception {
final DiffRepository diffRepos = getDiffRepos();
final String sql = diffRepos.expand(null, "${sql}");
final HepProgram program = new HepProgramBuilder().addRuleInstance(FilterJoinRule.DUMB_FILTER_ON_JOIN).addRuleInstance(FilterJoinRule.JOIN).addRuleInstance(FilterProjectTransposeRule.INSTANCE).addRuleInstance(FilterSetOpTransposeRule.INSTANCE).build();
final HepPlanner planner = new HepPlanner(program);
final RelRoot root = tester.convertSqlToRel(sql);
final RelNode relInitial = root.rel;
assertTrue(relInitial != null);
List<RelMetadataProvider> list = Lists.newArrayList();
list.add(DefaultRelMetadataProvider.INSTANCE);
planner.registerMetadataProviders(list);
RelMetadataProvider plannerChain = ChainedRelMetadataProvider.of(list);
relInitial.getCluster().setMetadataProvider(new CachingRelMetadataProvider(plannerChain, planner));
planner.setRoot(relInitial);
RelNode relBefore = planner.findBestExp();
String planBefore = NL + RelOptUtil.toString(relBefore);
diffRepos.assertEquals("planBefore", "${planBefore}", planBefore);
HepProgram program2 = new HepProgramBuilder().addMatchOrder(HepMatchOrder.BOTTOM_UP).addRuleInstance(FilterJoinRule.DUMB_FILTER_ON_JOIN).addRuleInstance(FilterJoinRule.JOIN).addRuleInstance(FilterProjectTransposeRule.INSTANCE).addRuleInstance(FilterSetOpTransposeRule.INSTANCE).addRuleInstance(JoinPushTransitivePredicatesRule.INSTANCE).addRuleCollection(Arrays.asList(extraRules)).build();
final HepPlanner planner2 = new HepPlanner(program2);
planner.registerMetadataProviders(list);
planner2.setRoot(relBefore);
RelNode relAfter = planner2.findBestExp();
String planAfter = NL + RelOptUtil.toString(relAfter);
diffRepos.assertEquals("planAfter", "${planAfter}", planAfter);
}
Aggregations