use of org.apache.calcite.plan.hep.HepProgramBuilder 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.HepProgramBuilder 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.HepProgramBuilder 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();
}
use of org.apache.calcite.plan.hep.HepProgramBuilder in project calcite by apache.
the class RelOptRulesTest method testPushAggregateSumThroughJoinAfterAggregateReduce.
/**
* Test case for
* <a href="https://issues.apache.org/jira/browse/CALCITE-2108">[CALCITE-2108]
* AggregateJoinTransposeRule incorrectly splits a SUM0 call when Aggregate
* has no group keys</a>.
*
* <p>Similar to {@link #testPushAggregateSumThroughJoin()},
* but also uses {@link AggregateReduceFunctionsRule}.
*/
@Test
public void testPushAggregateSumThroughJoinAfterAggregateReduce() {
final HepProgram preProgram = new HepProgramBuilder().addRuleInstance(AggregateProjectMergeRule.INSTANCE).build();
final HepProgram program = new HepProgramBuilder().addRuleInstance(AggregateReduceFunctionsRule.INSTANCE).addRuleInstance(AggregateJoinTransposeRule.EXTENDED).build();
final String sql = "select sum(sal)\n" + "from (select * from sales.emp where empno = 10) as e\n" + "join sales.dept as d on e.job = 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 testReduceCase.
/**
* Test case for
* <a href="https://issues.apache.org/jira/browse/CALCITE-1439">[CALCITE-1439]
* Handling errors during constant reduction</a>.
*/
@Test
public void testReduceCase() throws Exception {
HepProgram program = new HepProgramBuilder().addRuleInstance(ReduceExpressionsRule.PROJECT_INSTANCE).build();
final String sql = "select\n" + " case when false then cast(2.1 as float)\n" + " else cast(1 as integer) end as newcol\n" + "from emp";
sql(sql).with(program).withProperty(Hook.REL_BUILDER_SIMPLIFY, false).check();
}
Aggregations