use of org.apache.calcite.rel.rules.AggregateProjectMergeRule in project calcite by apache.
the class RelOptRulesTest method testAggregateExtractProjectRuleWithFilter.
@Test
void testAggregateExtractProjectRuleWithFilter() {
final String sql = "select sum(sal) filter (where empno = 40)\n" + "from emp";
HepProgram pre = new HepProgramBuilder().addRuleInstance(CoreRules.AGGREGATE_PROJECT_MERGE).build();
// AggregateProjectMergeRule does not merges Project with Filter.
// Force match Aggregate on top of Project once explicitly in unit test.
final AggregateExtractProjectRule rule = AggregateExtractProjectRule.SCAN.config.withOperandSupplier(b0 -> b0.operand(Aggregate.class).oneInput(b1 -> b1.operand(Project.class).predicate(new Predicate<Project>() {
int matchCount = 0;
public boolean test(Project project) {
return matchCount++ == 0;
}
}).anyInputs())).as(AggregateExtractProjectRule.Config.class).toRule();
sql(sql).withPre(pre).withRule(rule).checkUnchanged();
}
Aggregations