Search in sources :

Example 81 with HepProgram

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

Example 82 with HepProgram

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

Example 83 with HepProgram

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

Example 84 with HepProgram

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();
}
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 85 with HepProgram

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

Aggregations

HepProgram (org.apache.calcite.plan.hep.HepProgram)190 Test (org.junit.Test)171 HepProgramBuilder (org.apache.calcite.plan.hep.HepProgramBuilder)142 HepPlanner (org.apache.calcite.plan.hep.HepPlanner)55 RelNode (org.apache.calcite.rel.RelNode)9 AggregateExtractProjectRule (org.apache.calcite.rel.rules.AggregateExtractProjectRule)4 RelBuilderFactory (org.apache.calcite.tools.RelBuilderFactory)4 Ignore (org.junit.Ignore)4 ImmutableList (com.google.common.collect.ImmutableList)3 List (java.util.List)3 Context (org.apache.calcite.plan.Context)3 RelDataType (org.apache.calcite.rel.type.RelDataType)3 RelDataTypeFactory (org.apache.calcite.rel.type.RelDataTypeFactory)3 Properties (java.util.Properties)2 CalciteConnectionConfigImpl (org.apache.calcite.config.CalciteConnectionConfigImpl)2 Project (org.apache.calcite.rel.core.Project)2 LogicalProject (org.apache.calcite.rel.logical.LogicalProject)2 FilterJoinRule (org.apache.calcite.rel.rules.FilterJoinRule)2 RelBuilder (org.apache.calcite.tools.RelBuilder)2 ImmutableMap (com.google.common.collect.ImmutableMap)1