use of org.apache.calcite.plan.hep.HepProgramBuilder 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.HepProgramBuilder 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();
}
use of org.apache.calcite.plan.hep.HepProgramBuilder in project calcite by apache.
the class RelOptRulesTest method testSortJoinTranspose3.
@Test
public void testSortJoinTranspose3() {
final HepProgram preProgram = new HepProgramBuilder().addRuleInstance(SortProjectTransposeRule.INSTANCE).build();
final HepProgram program = new HepProgramBuilder().addRuleInstance(SortJoinTransposeRule.INSTANCE).build();
// This one cannot be pushed down
final String sql = "select * from sales.emp left join (\n" + "select * from sales.dept) using (deptno)\n" + "order by sal, name limit 10";
checkPlanning(tester, preProgram, new HepPlanner(program), sql, true);
}
use of org.apache.calcite.plan.hep.HepProgramBuilder in project calcite by apache.
the class RelOptRulesTest method testReduceNot.
@Test
public void testReduceNot() {
HepProgram preProgram = new HepProgramBuilder().build();
HepProgramBuilder builder = new HepProgramBuilder();
builder.addRuleClass(ReduceExpressionsRule.class);
HepPlanner hepPlanner = new HepPlanner(builder.build());
hepPlanner.addRule(ReduceExpressionsRule.FILTER_INSTANCE);
final String sql = "select *\n" + "from (select (case when sal > 1000 then null else false end) as caseCol from emp)\n" + "where NOT(caseCol)";
checkPlanning(tester, preProgram, hepPlanner, sql, true);
}
use of org.apache.calcite.plan.hep.HepProgramBuilder in project calcite by apache.
the class RelOptRulesTest method testDistinctNonDistinctTwoAggregatesWithGrouping.
@Test
public void testDistinctNonDistinctTwoAggregatesWithGrouping() {
final String sql = "SELECT deptno, SUM(comm), MIN(comm), SUM(DISTINCT sal)\n" + "FROM emp\n" + "GROUP BY deptno";
HepProgram program = new HepProgramBuilder().addRuleInstance(AggregateExpandDistinctAggregatesRule.JOIN).build();
sql(sql).with(program).check();
}
Aggregations