use of org.apache.calcite.plan.hep.HepProgramBuilder in project calcite by apache.
the class RelOptRulesTest method checkReduceNullableToNotNull.
private void checkReduceNullableToNotNull(ReduceExpressionsRule rule) {
HepProgram program = new HepProgramBuilder().addRuleInstance(rule).build();
final String sql = "select\n" + " empno + case when 'a' = 'a' then 1 else null end as newcol\n" + "from emp";
sql(sql).with(program).withProperty(Hook.REL_BUILDER_SIMPLIFY, false).check();
}
use of org.apache.calcite.plan.hep.HepProgramBuilder in project calcite by apache.
the class RelOptRulesTest method testPushAggregateThroughJoinDistinct.
/**
* Push a aggregate functions into a relation that is unique on the join
* key.
*/
@Test
public void testPushAggregateThroughJoinDistinct() {
final HepProgram preProgram = new HepProgramBuilder().addRuleInstance(AggregateProjectMergeRule.INSTANCE).build();
final HepProgram program = new HepProgramBuilder().addRuleInstance(AggregateJoinTransposeRule.EXTENDED).build();
final String sql = "select d.name,\n" + " sum(sal) as sum_sal, count(*) as c\n" + "from sales.emp as e\n" + "join (select distinct name from sales.dept) as d\n" + " on e.job = d.name\n" + "group by d.name";
checkPlanning(tester, preProgram, new HepPlanner(program), sql);
}
use of org.apache.calcite.plan.hep.HepProgramBuilder in project calcite by apache.
the class RelOptRulesTest method testReduceValuesUnderProjectFilter.
@Test
public void testReduceValuesUnderProjectFilter() throws Exception {
HepProgram program = new HepProgramBuilder().addRuleInstance(FilterProjectTransposeRule.INSTANCE).addRuleInstance(ProjectMergeRule.INSTANCE).addRuleInstance(ValuesReduceRule.PROJECT_FILTER_INSTANCE).build();
// Plan should be same as for
// select * from (values (11, 1, 10), (23, 3, 20)) as t(x, b, a)");
checkPlanning(program, "select a + b as x, b, a from (values (10, 1), (30, 7), (20, 3)) as t(a, b)" + " where a - b < 21");
}
use of org.apache.calcite.plan.hep.HepProgramBuilder 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.HepProgramBuilder 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");
}
Aggregations