use of org.apache.calcite.rel.rules.AggregateExtractProjectRule 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.rel.rules.AggregateExtractProjectRule in project calcite by apache.
the class RelOptRulesTest method testAggregateExtractProjectRule.
@Test
public void testAggregateExtractProjectRule() {
final String sql = "select sum(sal)\n" + "from emp";
HepProgram pre = new HepProgramBuilder().addRuleInstance(AggregateProjectMergeRule.INSTANCE).build();
final AggregateExtractProjectRule rule = new AggregateExtractProjectRule(Aggregate.class, LogicalTableScan.class, RelFactories.LOGICAL_BUILDER);
sql(sql).withPre(pre).withRule(rule).check();
}
use of org.apache.calcite.rel.rules.AggregateExtractProjectRule in project calcite by apache.
the class RelOptRulesTest method testAggregateExtractProjectRuleWithGroupingSets.
@Test
public void testAggregateExtractProjectRuleWithGroupingSets() {
final String sql = "select empno, deptno, sum(sal)\n" + "from emp\n" + "group by grouping sets ((empno, deptno),(deptno),(empno))";
HepProgram pre = new HepProgramBuilder().addRuleInstance(AggregateProjectMergeRule.INSTANCE).build();
final AggregateExtractProjectRule rule = new AggregateExtractProjectRule(Aggregate.class, LogicalTableScan.class, RelFactories.LOGICAL_BUILDER);
sql(sql).withPre(pre).withRule(rule).check();
}
use of org.apache.calcite.rel.rules.AggregateExtractProjectRule in project calcite by apache.
the class RelOptRulesTest method testAggregateExtractProjectRuleWithGroupingSets2.
/**
* Test with column used in both grouping set and argument to aggregate
* function.
*/
@Test
public void testAggregateExtractProjectRuleWithGroupingSets2() {
final String sql = "select empno, deptno, sum(empno)\n" + "from emp\n" + "group by grouping sets ((empno, deptno),(deptno),(empno))";
HepProgram pre = new HepProgramBuilder().addRuleInstance(AggregateProjectMergeRule.INSTANCE).build();
final AggregateExtractProjectRule rule = new AggregateExtractProjectRule(Aggregate.class, LogicalTableScan.class, RelFactories.LOGICAL_BUILDER);
sql(sql).withPre(pre).withRule(rule).check();
}
Aggregations