Search in sources :

Example 56 with HepProgramBuilder

use of org.apache.calcite.plan.hep.HepProgramBuilder in project calcite by apache.

the class RelOptRulesTest method testSortJoinTranspose2.

@Test
public void testSortJoinTranspose2() {
    final HepProgram preProgram = new HepProgramBuilder().addRuleInstance(SortProjectTransposeRule.INSTANCE).build();
    final HepProgram program = new HepProgramBuilder().addRuleInstance(SortJoinTransposeRule.INSTANCE).build();
    final String sql = "select * from sales.emp e right join (\n" + "select * from sales.dept d) using (deptno)\n" + "order by name";
    checkPlanning(tester, preProgram, new HepPlanner(program), sql);
}
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 57 with HepProgramBuilder

use of org.apache.calcite.plan.hep.HepProgramBuilder in project calcite by apache.

the class RelOptRulesTest method testReduceConstantsDup2.

/**
 * Test case for
 * <a href="https://issues.apache.org/jira/browse/CALCITE-935">[CALCITE-935]
 * Improve how ReduceExpressionsRule handles duplicate constraints</a>.
 */
@Test
public void testReduceConstantsDup2() throws Exception {
    HepProgram program = new HepProgramBuilder().addRuleInstance(ReduceExpressionsRule.PROJECT_INSTANCE).addRuleInstance(ReduceExpressionsRule.FILTER_INSTANCE).addRuleInstance(ReduceExpressionsRule.JOIN_INSTANCE).build();
    final String sql = "select *\n" + "from emp\n" + "where deptno=7 and deptno=8\n" + "and empno = 10 and mgr is null and empno = 10";
    checkPlanning(program, sql);
}
Also used : HepProgram(org.apache.calcite.plan.hep.HepProgram) HepProgramBuilder(org.apache.calcite.plan.hep.HepProgramBuilder) Test(org.junit.Test)

Example 58 with HepProgramBuilder

use of org.apache.calcite.plan.hep.HepProgramBuilder in project calcite by apache.

the class RelOptRulesTest method testPushFilterWithRank.

@Test
public void testPushFilterWithRank() throws Exception {
    HepProgram program = new HepProgramBuilder().addRuleInstance(FilterProjectTransposeRule.INSTANCE).build();
    final String sql = "select e1.ename, r\n" + "from (\n" + "  select ename, " + "  rank() over(partition by  deptno order by sal) as r " + "  from emp) e1\n" + "where r < 2";
    checkPlanUnchanged(new HepPlanner(program), sql);
}
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 59 with HepProgramBuilder

use of org.apache.calcite.plan.hep.HepProgramBuilder in project calcite by apache.

the class RelOptRulesTest method testPushAggregateThroughJoin3.

@Test
public void testPushAggregateThroughJoin3() {
    final HepProgram preProgram = new HepProgramBuilder().addRuleInstance(AggregateProjectMergeRule.INSTANCE).build();
    final HepProgram program = new HepProgramBuilder().addRuleInstance(AggregateJoinTransposeRule.EXTENDED).build();
    final String sql = "select e.empno,d.deptno\n" + "from (select * from sales.emp where empno = 10) as e\n" + "join sales.dept as d on e.empno < d.deptno\n" + "group by e.empno,d.deptno";
    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 60 with HepProgramBuilder

use of org.apache.calcite.plan.hep.HepProgramBuilder in project calcite by apache.

the class RelOptRulesTest method testPushAggregateSumThroughJoin.

/**
 * SUM is the easiest aggregate function to split.
 */
@Test
public void testPushAggregateSumThroughJoin() {
    final HepProgram preProgram = new HepProgramBuilder().addRuleInstance(AggregateProjectMergeRule.INSTANCE).build();
    final HepProgram program = new HepProgramBuilder().addRuleInstance(AggregateJoinTransposeRule.EXTENDED).build();
    final String sql = "select e.job,sum(sal)\n" + "from (select * from sales.emp where empno = 10) as e\n" + "join sales.dept as d on e.job = d.name\n" + "group by e.job,d.name";
    checkPlanning(tester, preProgram, new HepPlanner(program), sql);
}
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)

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