use of org.apache.calcite.plan.hep.HepProgramBuilder 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.HepProgramBuilder 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.HepProgramBuilder 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);
}
use of org.apache.calcite.plan.hep.HepProgramBuilder in project calcite by apache.
the class RelOptRulesTest method testAggregateProjectPullUpConstants2.
@Test
public void testAggregateProjectPullUpConstants2() {
final HepProgram preProgram = new HepProgramBuilder().addRuleInstance(AggregateProjectMergeRule.INSTANCE).build();
HepProgram program = new HepProgramBuilder().addRuleInstance(AggregateProjectPullUpConstantsRule.INSTANCE2).build();
final String sql = "select ename, sal\n" + "from (select '1', ename, sal from emp where ename = 'John') subq\n" + "group by ename, sal";
checkPlanning(tester, preProgram, new HepPlanner(program), sql);
}
use of org.apache.calcite.plan.hep.HepProgramBuilder in project calcite by apache.
the class RelOptRulesTest method testRemoveSemiJoinRightWithFilter.
@Test
public void testRemoveSemiJoinRightWithFilter() throws Exception {
HepProgram program = new HepProgramBuilder().addRuleInstance(FilterJoinRule.FILTER_ON_JOIN).addRuleInstance(JoinAddRedundantSemiJoinRule.INSTANCE).addRuleInstance(SemiJoinJoinTransposeRule.INSTANCE).addRuleInstance(SemiJoinFilterTransposeRule.INSTANCE).addRuleInstance(SemiJoinRemoveRule.INSTANCE).build();
checkPlanning(program, "select e1.ename from emp e1, dept d, emp e2 " + "where e1.deptno = d.deptno and d.deptno = e2.deptno " + "and d.name = 'foo'");
}
Aggregations