use of org.apache.calcite.plan.hep.HepProgram in project calcite by apache.
the class RelOptRulesTest method testSwapOuterJoin.
@Test
public void testSwapOuterJoin() {
final HepProgram program = new HepProgramBuilder().addMatchLimit(1).addRuleInstance(JoinCommuteRule.SWAP_OUTER).build();
checkPlanning(program, "select 1 from sales.dept d left outer join sales.emp e" + " on d.deptno = e.deptno");
}
use of org.apache.calcite.plan.hep.HepProgram in project calcite by apache.
the class RelOptRulesTest method testReduceConstantsCaseEquals2.
@Test
public void testReduceConstantsCaseEquals2() throws Exception {
HepProgram program = new HepProgramBuilder().addRuleInstance(ReduceExpressionsRule.PROJECT_INSTANCE).addRuleInstance(ReduceExpressionsRule.FILTER_INSTANCE).addRuleInstance(ReduceExpressionsRule.JOIN_INSTANCE).build();
// Equivalent to 'case when deptno = 20 then false
// when deptno = 10 then true
// else null end'
checkPlanning(program, "select count(1) from emp\n" + "where case deptno\n" + " when 20 then 2\n" + " when 10 then 1\n" + " else cast(null as integer) end = 1");
}
use of org.apache.calcite.plan.hep.HepProgram in project calcite by apache.
the class RelOptRulesTest method testEmptyAggregate.
@Test
public void testEmptyAggregate() {
HepProgram preProgram = HepProgram.builder().addRuleInstance(ReduceExpressionsRule.FILTER_INSTANCE).addRuleInstance(PruneEmptyRules.PROJECT_INSTANCE).build();
HepProgram program = new HepProgramBuilder().addRuleInstance(ReduceExpressionsRule.FILTER_INSTANCE).addRuleInstance(PruneEmptyRules.PROJECT_INSTANCE).addRuleInstance(PruneEmptyRules.AGGREGATE_INSTANCE).addRuleInstance(PruneEmptyRules.PROJECT_INSTANCE).build();
final String sql = "select sum(empno) from emp where false group by deptno";
checkPlanning(tester, preProgram, new HepPlanner(program), sql);
}
use of org.apache.calcite.plan.hep.HepProgram in project calcite by apache.
the class RelOptRulesTest method testEmptyMinus2.
@Test
public void testEmptyMinus2() throws Exception {
HepProgram program = new HepProgramBuilder().addRuleInstance(ValuesReduceRule.PROJECT_FILTER_INSTANCE).addRuleInstance(PruneEmptyRules.PROJECT_INSTANCE).addRuleInstance(PruneEmptyRules.MINUS_INSTANCE).build();
// Second and fourth inputs are empty; they are removed
final String sql = "select * from (values (30, 3)) as t (x, y)\n" + "except\n" + "select * from (values (20, 2)) as t (x, y) where x > 30\n" + "except\n" + "select * from (values (40, 4))\n" + "except\n" + "select * from (values (50, 5)) as t (x, y) where x > 50";
sql(sql).with(program).check();
}
use of org.apache.calcite.plan.hep.HepProgram in project calcite by apache.
the class RelOptRulesTest method testCorrelationScalarAggAndFilter.
/**
* Test case for
* <a href="https://issues.apache.org/jira/browse/CALCITE-2110">[CALCITE-2110]
* ArrayIndexOutOfBoundsException in RexSimplify when using
* ReduceExpressionsRule.JOIN_INSTANCE</a>.
*/
@Test
public void testCorrelationScalarAggAndFilter() {
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)";
HepProgram program = new HepProgramBuilder().addRuleInstance(ReduceExpressionsRule.PROJECT_INSTANCE).addRuleInstance(ReduceExpressionsRule.FILTER_INSTANCE).addRuleInstance(ReduceExpressionsRule.JOIN_INSTANCE).build();
sql(sql).withDecorrelation(true).withTrim(true).expand(true).withPre(program).with(program).checkUnchanged();
}
Aggregations