use of org.apache.calcite.plan.hep.HepProgram in project calcite by apache.
the class RelOptRulesTest method testSortJoinTranspose6.
/**
* Test case for
* <a href="https://issues.apache.org/jira/browse/CALCITE-1507">[CALCITE-1507]
* OFFSET cannot be pushed through a JOIN if the non-preserved side of outer
* join is not count-preserving</a>.
*/
@Test
public void testSortJoinTranspose6() {
final HepProgram preProgram = new HepProgramBuilder().addRuleInstance(SortProjectTransposeRule.INSTANCE).build();
final HepProgram program = new HepProgramBuilder().addRuleInstance(SortJoinTransposeRule.INSTANCE).build();
// This one can be pushed down even if it has an OFFSET, since the dept
// table is count-preserving against the join condition.
final String sql = "select d.deptno, empno from sales.dept d\n" + "right join sales.emp e using (deptno) limit 10 offset 2";
sql(sql).withPre(preProgram).with(program).check();
}
use of org.apache.calcite.plan.hep.HepProgram in project calcite by apache.
the class RelOptRulesTest method testDistinctNonDistinctAggregates.
@Test
public void testDistinctNonDistinctAggregates() {
final String sql = "select emp.empno, count(*), avg(distinct dept.deptno)\n" + "from sales.emp emp inner join sales.dept dept\n" + "on emp.deptno = dept.deptno\n" + "group by emp.empno";
final HepProgram program = HepProgram.builder().addRuleInstance(AggregateExpandDistinctAggregatesRule.JOIN).build();
sql(sql).with(program).check();
}
use of org.apache.calcite.plan.hep.HepProgram in project calcite by apache.
the class RelOptRulesTest method testEmptyFilterProjectUnion.
@Test
public void testEmptyFilterProjectUnion() throws Exception {
HepProgram program = new HepProgramBuilder().addRuleInstance(FilterSetOpTransposeRule.INSTANCE).addRuleInstance(FilterProjectTransposeRule.INSTANCE).addRuleInstance(ProjectMergeRule.INSTANCE).addRuleInstance(ValuesReduceRule.PROJECT_FILTER_INSTANCE).addRuleInstance(PruneEmptyRules.PROJECT_INSTANCE).addRuleInstance(PruneEmptyRules.UNION_INSTANCE).build();
// Plan should be same as for
// select * from (values (30, 3)) as t(x, y)");
checkPlanning(program, "select * from (\n" + "select * from (values (10, 1), (30, 3)) as t (x, y)\n" + "union all\n" + "select * from (values (20, 2))\n" + ")\n" + "where x + y > 30");
}
use of org.apache.calcite.plan.hep.HepProgram in project calcite by apache.
the class RelOptRulesTest method testAggregateExtractProjectRuleWithFilter.
@Test
public void testAggregateExtractProjectRuleWithFilter() {
final String sql = "select sum(sal) filter (where empno = 40)\n" + "from emp";
HepProgram pre = new HepProgramBuilder().addRuleInstance(AggregateProjectMergeRule.INSTANCE).build();
// AggregateProjectMergeRule does not merges Project with Filter.
// Force match Aggregate on top of Project once explicitly in unit test.
final AggregateExtractProjectRule rule = new AggregateExtractProjectRule(operand(Aggregate.class, operand(Project.class, null, new PredicateImpl<Project>() {
int matchCount = 0;
public boolean test(@Nullable Project project) {
return matchCount++ == 0;
}
}, none())), RelFactories.LOGICAL_BUILDER);
sql(sql).withPre(pre).withRule(rule).checkUnchanged();
}
use of org.apache.calcite.plan.hep.HepProgram in project calcite by apache.
the class RelOptRulesTest method testPushAggregateThroughJoin6.
/**
* Test case for
* <a href="https://issues.apache.org/jira/browse/CALCITE-2195">[CALCITE-2195]
* AggregateJoinTransposeRule fails to aggregate over unique column</a>.
*/
@Test
public void testPushAggregateThroughJoin6() {
final HepProgram preProgram = new HepProgramBuilder().addRuleInstance(AggregateProjectMergeRule.INSTANCE).build();
final HepProgram program = new HepProgramBuilder().addRuleInstance(AggregateJoinTransposeRule.EXTENDED).build();
final String sql = "select sum(B.sal)\n" + "from sales.emp as A\n" + "join (select distinct sal from sales.emp) as B\n" + "on A.sal=B.sal\n";
sql(sql).withPre(preProgram).with(program).check();
}
Aggregations