Search in sources :

Example 66 with HepProgramBuilder

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();
}
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 67 with HepProgramBuilder

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

Example 68 with HepProgramBuilder

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

Example 69 with HepProgramBuilder

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

Example 70 with HepProgramBuilder

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

Aggregations

HepProgramBuilder (org.apache.calcite.plan.hep.HepProgramBuilder)168 Test (org.junit.Test)147 HepProgram (org.apache.calcite.plan.hep.HepProgram)143 HepPlanner (org.apache.calcite.plan.hep.HepPlanner)56 RelNode (org.apache.calcite.rel.RelNode)9 RelOptRule (org.apache.calcite.plan.RelOptRule)5 RelDataType (org.apache.calcite.rel.type.RelDataType)5 RexBuilder (org.apache.calcite.rex.RexBuilder)5 JavaTypeFactoryImpl (org.apache.calcite.jdbc.JavaTypeFactoryImpl)4 RelOptCluster (org.apache.calcite.plan.RelOptCluster)4 AggregateExtractProjectRule (org.apache.calcite.rel.rules.AggregateExtractProjectRule)4 Ignore (org.junit.Ignore)4 RelOptPlanner (org.apache.calcite.plan.RelOptPlanner)3 RelTraitSet (org.apache.calcite.plan.RelTraitSet)3 LogicalTableScan (org.apache.calcite.rel.logical.LogicalTableScan)3 RuleSet (org.apache.calcite.tools.RuleSet)3 Before (org.junit.Before)3 Properties (java.util.Properties)2 CalciteConnectionConfigImpl (org.apache.calcite.config.CalciteConnectionConfigImpl)2 Context (org.apache.calcite.plan.Context)2