Search in sources :

Example 71 with HepProgram

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

the class RelOptRulesTest method testSemiJoinRuleFull.

/**
 * Similar to {@link #testSemiJoinRuleRight()} but FULL.
 */
@Test
public void testSemiJoinRuleFull() {
    final HepProgram preProgram = HepProgram.builder().addRuleInstance(FilterProjectTransposeRule.INSTANCE).addRuleInstance(FilterJoinRule.FILTER_ON_JOIN).addRuleInstance(ProjectMergeRule.INSTANCE).build();
    final HepProgram program = HepProgram.builder().addRuleInstance(SemiJoinRule.PROJECT).build();
    final String sql = "select dept.* from dept full join (\n" + "  select distinct deptno from emp\n" + "  where sal > 100) using (deptno)";
    sql(sql).withPre(preProgram).with(program).withDecorrelation(true).withTrim(true).checkUnchanged();
}
Also used : HepProgram(org.apache.calcite.plan.hep.HepProgram) Test(org.junit.Test)

Example 72 with HepProgram

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

the class RelOptRulesTest method testDistinctCountMultipleNoGroup.

@Test
public void testDistinctCountMultipleNoGroup() {
    final HepProgram program = HepProgram.builder().addRuleInstance(AggregateExpandDistinctAggregatesRule.INSTANCE).addRuleInstance(AggregateProjectMergeRule.INSTANCE).build();
    checkPlanning(program, "select count(distinct ename), count(distinct job)\n" + " from sales.emp");
}
Also used : HepProgram(org.apache.calcite.plan.hep.HepProgram) Test(org.junit.Test)

Example 73 with HepProgram

use of org.apache.calcite.plan.hep.HepProgram 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 74 with HepProgram

use of org.apache.calcite.plan.hep.HepProgram 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 75 with HepProgram

use of org.apache.calcite.plan.hep.HepProgram 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)

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