use of org.apache.calcite.plan.hep.HepProgramBuilder in project calcite by apache.
the class RelOptRulesTest method testMultipleDistinctWithGrouping.
@Test
public void testMultipleDistinctWithGrouping() {
final String sql = "SELECT sal, SUM(comm), MIN(DISTINCT comm), SUM(DISTINCT sal)\n" + "FROM emp\n" + "GROUP BY sal";
HepProgram program = new HepProgramBuilder().addRuleInstance(AggregateExpandDistinctAggregatesRule.JOIN).build();
sql(sql).with(program).check();
}
use of org.apache.calcite.plan.hep.HepProgramBuilder in project calcite by apache.
the class RelOptRulesTest method testUnionMergeRule.
/**
* Tests to see if the final branch of union is missed
*/
@Test
public void testUnionMergeRule() throws Exception {
HepProgram program = new HepProgramBuilder().addRuleInstance(ProjectSetOpTransposeRule.INSTANCE).addRuleInstance(ProjectRemoveRule.INSTANCE).addRuleInstance(UnionMergeRule.INSTANCE).build();
checkPlanning(program, "select * from (\n" + "select * from (\n" + " select name, deptno from dept\n" + " union all\n" + " select name, deptno from\n" + " (\n" + " select name, deptno, count(1) from dept group by name, deptno\n" + " union all\n" + " select name, deptno, count(1) from dept group by name, deptno\n" + " ) subq\n" + ") a\n" + "union all\n" + "select name, deptno from dept\n" + ") aa\n");
}
use of org.apache.calcite.plan.hep.HepProgramBuilder in project calcite by apache.
the class RelOptRulesTest method testEmptyAggregateEmptyKeyWithAggregateValuesRule.
@Test
public void testEmptyAggregateEmptyKeyWithAggregateValuesRule() {
HepProgram preProgram = HepProgram.builder().addRuleInstance(ReduceExpressionsRule.FILTER_INSTANCE).addRuleInstance(PruneEmptyRules.PROJECT_INSTANCE).build();
HepProgram program = new HepProgramBuilder().addRuleInstance(AggregateValuesRule.INSTANCE).build();
final String sql = "select count(*), sum(empno) from emp where false";
sql(sql).withPre(preProgram).with(program).check();
}
use of org.apache.calcite.plan.hep.HepProgramBuilder in project calcite by apache.
the class RelOptRulesTest method testEmptyJoin.
@Test
public void testEmptyJoin() {
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 empty
checkPlanning(program, "select * from (\n" + "select * from emp where false)\n" + "join dept using (deptno)");
}
use of org.apache.calcite.plan.hep.HepProgramBuilder in project calcite by apache.
the class RelOptRulesTest method testReduceConstantsNull.
/**
* Test case for
* <a href="https://issues.apache.org/jira/browse/CALCITE-1860">[CALCITE-1860]
* Duplicate null predicates cause NullPointerException in RexUtil</a>.
*/
@Test
public void testReduceConstantsNull() throws Exception {
HepProgram program = new HepProgramBuilder().addRuleInstance(ReduceExpressionsRule.FILTER_INSTANCE).build();
final String sql = "select * from (\n" + " select *\n" + " from (\n" + " select cast(null as integer) as n\n" + " from emp)\n" + " where n is null and n is null)\n" + "where n is null";
sql(sql).with(program).check();
}
Aggregations