use of org.apache.calcite.plan.hep.HepProgramBuilder in project calcite by apache.
the class RelOptRulesTest method testEmptyJoinRight.
@Test
public void testEmptyJoinRight() {
HepProgram program = new HepProgramBuilder().addRuleInstance(ReduceExpressionsRule.FILTER_INSTANCE).addRuleInstance(PruneEmptyRules.PROJECT_INSTANCE).addRuleInstance(PruneEmptyRules.JOIN_LEFT_INSTANCE).addRuleInstance(PruneEmptyRules.JOIN_RIGHT_INSTANCE).build();
// Plan should be equivalent to "select * from emp join dept".
// Cannot optimize away the join because of RIGHT.
checkPlanning(program, "select * from (\n" + "select * from emp where false)\n" + "right join dept using (deptno)");
}
use of org.apache.calcite.plan.hep.HepProgramBuilder in project calcite by apache.
the class RelOptRulesTest method testPushSemiJoinPastFilter.
@Test
public void testPushSemiJoinPastFilter() throws Exception {
HepProgram program = new HepProgramBuilder().addRuleInstance(FilterJoinRule.FILTER_ON_JOIN).addRuleInstance(JoinAddRedundantSemiJoinRule.INSTANCE).addRuleInstance(SemiJoinFilterTransposeRule.INSTANCE).build();
checkPlanning(program, "select e.ename from emp e, dept d " + "where e.deptno = d.deptno and e.ename = 'foo'");
}
use of org.apache.calcite.plan.hep.HepProgramBuilder in project calcite by apache.
the class RelOptRulesTest method testAggregateConstantKeyRule2.
/**
* Tests {@link AggregateProjectPullUpConstantsRule} where reduction is not
* possible because "deptno" is the only key.
*/
@Test
public void testAggregateConstantKeyRule2() {
final HepProgram program = new HepProgramBuilder().addRuleInstance(AggregateProjectPullUpConstantsRule.INSTANCE2).build();
final String sql = "select count(*) as c\n" + "from sales.emp\n" + "where deptno = 10\n" + "group by deptno";
checkPlanUnchanged(new HepPlanner(program), sql);
}
use of org.apache.calcite.plan.hep.HepProgramBuilder in project calcite by apache.
the class RelOptRulesTest method testMergeUnionAll.
/**
* Tests {@link UnionMergeRule}, which merges 2 {@link Union} operators into
* a single {@code Union} with 3 inputs.
*/
@Test
public void testMergeUnionAll() throws Exception {
HepProgram program = new HepProgramBuilder().addRuleInstance(UnionMergeRule.INSTANCE).build();
final String sql = "select * from emp where deptno = 10\n" + "union all\n" + "select * from emp where deptno = 20\n" + "union all\n" + "select * from emp where deptno = 30\n";
sql(sql).with(program).check();
}
use of org.apache.calcite.plan.hep.HepProgramBuilder in project calcite by apache.
the class RelOptRulesTest method testReduceConstants.
@Test
public void testReduceConstants() throws Exception {
HepProgram program = new HepProgramBuilder().addRuleInstance(ReduceExpressionsRule.PROJECT_INSTANCE).addRuleInstance(ReduceExpressionsRule.FILTER_INSTANCE).addRuleInstance(ReduceExpressionsRule.JOIN_INSTANCE).build();
// NOTE jvs 27-May-2006: among other things, this verifies
// intentionally different treatment for identical coalesce expression
// in select and where.
// There is "CAST(2 AS INTEGER)" in the plan because 2 has type "INTEGER NOT
// NULL" and we need "INTEGER".
final String sql = "select" + " 1+2, d.deptno+(3+4), (5+6)+d.deptno, cast(null as integer)," + " coalesce(2,null), row(7+8)" + " from dept d inner join emp e" + " on d.deptno = e.deptno + (5-5)" + " where d.deptno=(7+8) and d.deptno=(8+7) and d.deptno=coalesce(2,null)";
sql(sql).with(program).withProperty(Hook.REL_BUILDER_SIMPLIFY, false).check();
}
Aggregations