use of org.apache.calcite.plan.hep.HepProgramBuilder in project calcite by apache.
the class RelOptRulesTest method testMergeJoinFilter.
/**
* Tests that a filters is combined are combined if they are identical,
* even if one of them originates in an ON clause of a JOIN.
*/
@Test
public void testMergeJoinFilter() throws Exception {
HepProgram program = new HepProgramBuilder().addRuleInstance(FilterProjectTransposeRule.INSTANCE).addRuleInstance(FilterMergeRule.INSTANCE).addRuleInstance(FilterJoinRule.FILTER_ON_JOIN).build();
checkPlanning(program, "select * from (\n" + " select d.deptno, e.ename\n" + " from emp as e\n" + " join dept as d\n" + " on e.deptno = d.deptno\n" + " and d.deptno = 10)\n" + "where deptno = 10\n");
}
use of org.apache.calcite.plan.hep.HepProgramBuilder in project calcite by apache.
the class RelOptRulesTest method testRemoveSemiJoin.
@Test
public void testRemoveSemiJoin() throws Exception {
HepProgram program = new HepProgramBuilder().addRuleInstance(FilterJoinRule.FILTER_ON_JOIN).addRuleInstance(JoinAddRedundantSemiJoinRule.INSTANCE).addRuleInstance(SemiJoinRemoveRule.INSTANCE).build();
checkPlanning(program, "select e.ename 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 testJoinPushTransitivePredicatesRule.
/**
* Test case for
* <a href="https://issues.apache.org/jira/browse/CALCITE-2200">[CALCITE-2200]
* Infinite loop for JoinPushTransitivePredicatesRule</a>.
*/
@Test
public void testJoinPushTransitivePredicatesRule() {
HepProgram preProgram = new HepProgramBuilder().addRuleInstance(FilterJoinRule.FILTER_ON_JOIN).addRuleInstance(FilterJoinRule.JOIN).addRuleInstance(JoinPushTransitivePredicatesRule.INSTANCE).build();
final HepPlanner hepPlanner = new HepPlanner(new HepProgramBuilder().build());
final String sql = "select d.deptno from sales.emp d where d.deptno\n" + "IN (select e.deptno from sales.emp e " + "where e.deptno = d.deptno or e.deptno = 4)";
sql(sql).withPre(preProgram).with(hepPlanner).checkUnchanged();
}
use of org.apache.calcite.plan.hep.HepProgramBuilder in project calcite by apache.
the class RelOptRulesTest method testExtractYearMonthToRange.
@Test
public void testExtractYearMonthToRange() {
final String sql = "select *\n" + "from sales.emp_b as e\n" + "where extract(year from birthdate) = 2014" + "and extract(month from birthdate) = 4";
HepProgram program = new HepProgramBuilder().addRuleInstance(DateRangeRules.FILTER_INSTANCE).build();
final Context context = Contexts.of(new CalciteConnectionConfigImpl(new Properties()));
sql(sql).with(program).withContext(context).check();
}
use of org.apache.calcite.plan.hep.HepProgramBuilder in project calcite by apache.
the class RelOptRulesTest method testReduceCasts.
@Test
public void testReduceCasts() throws Exception {
HepProgram program = new HepProgramBuilder().addRuleInstance(ReduceExpressionsRule.PROJECT_INSTANCE).addRuleInstance(ReduceExpressionsRule.FILTER_INSTANCE).addRuleInstance(ReduceExpressionsRule.JOIN_INSTANCE).build();
// The resulting plan should have no cast expressions
checkPlanning(program, "select cast(d.name as varchar(128)), cast(e.empno as integer) " + "from dept as d inner join emp as e " + "on cast(d.deptno as integer) = cast(e.deptno as integer) " + "where cast(e.job as varchar(1)) = 'Manager'");
}
Aggregations