Search in sources :

Example 1 with AggregateExtractProjectRule

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();
}
Also used : Project(org.apache.calcite.rel.core.Project) LogicalProject(org.apache.calcite.rel.logical.LogicalProject) HepProgram(org.apache.calcite.plan.hep.HepProgram) AggregateExtractProjectRule(org.apache.calcite.rel.rules.AggregateExtractProjectRule) HepProgramBuilder(org.apache.calcite.plan.hep.HepProgramBuilder) Aggregate(org.apache.calcite.rel.core.Aggregate) Test(org.junit.Test)

Example 2 with AggregateExtractProjectRule

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();
}
Also used : HepProgram(org.apache.calcite.plan.hep.HepProgram) AggregateExtractProjectRule(org.apache.calcite.rel.rules.AggregateExtractProjectRule) HepProgramBuilder(org.apache.calcite.plan.hep.HepProgramBuilder) Test(org.junit.Test)

Example 3 with AggregateExtractProjectRule

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();
}
Also used : HepProgram(org.apache.calcite.plan.hep.HepProgram) AggregateExtractProjectRule(org.apache.calcite.rel.rules.AggregateExtractProjectRule) HepProgramBuilder(org.apache.calcite.plan.hep.HepProgramBuilder) Test(org.junit.Test)

Example 4 with AggregateExtractProjectRule

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();
}
Also used : HepProgram(org.apache.calcite.plan.hep.HepProgram) AggregateExtractProjectRule(org.apache.calcite.rel.rules.AggregateExtractProjectRule) HepProgramBuilder(org.apache.calcite.plan.hep.HepProgramBuilder) Test(org.junit.Test)

Aggregations

HepProgram (org.apache.calcite.plan.hep.HepProgram)4 HepProgramBuilder (org.apache.calcite.plan.hep.HepProgramBuilder)4 AggregateExtractProjectRule (org.apache.calcite.rel.rules.AggregateExtractProjectRule)4 Test (org.junit.Test)4 Aggregate (org.apache.calcite.rel.core.Aggregate)1 Project (org.apache.calcite.rel.core.Project)1 LogicalProject (org.apache.calcite.rel.logical.LogicalProject)1