Search in sources :

Example 51 with HepProgram

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

the class RelOptRulesTest method testDistinctCountMixed2.

@Test
public void testDistinctCountMixed2() {
    final HepProgram program = HepProgram.builder().addRuleInstance(AggregateExpandDistinctAggregatesRule.INSTANCE).addRuleInstance(AggregateProjectMergeRule.INSTANCE).addRuleInstance(ProjectMergeRule.INSTANCE).build();
    checkPlanning(program, "select deptno, count(distinct ename) as cde,\n" + "  count(distinct job, ename) as cdje,\n" + "  count(distinct deptno, job) as cddj,\n" + "  sum(sal) as s\n" + " from sales.emp group by deptno");
}
Also used : HepProgram(org.apache.calcite.plan.hep.HepProgram) Test(org.junit.Test)

Example 52 with HepProgram

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

the class RelOptRulesTest method testJoinProjectTranspose.

@Test
public void testJoinProjectTranspose() {
    final HepProgram preProgram = HepProgram.builder().addRuleInstance(ProjectJoinTransposeRule.INSTANCE).addRuleInstance(ProjectMergeRule.INSTANCE).build();
    final HepProgram program = HepProgram.builder().addRuleInstance(JoinProjectTransposeRule.LEFT_PROJECT_INCLUDE_OUTER).addRuleInstance(ProjectMergeRule.INSTANCE).addRuleInstance(JoinProjectTransposeRule.RIGHT_PROJECT_INCLUDE_OUTER).addRuleInstance(JoinProjectTransposeRule.LEFT_PROJECT_INCLUDE_OUTER).addRuleInstance(ProjectMergeRule.INSTANCE).build();
    final String sql = "select a.name\n" + "from dept a\n" + "left join dept b on b.deptno > 10\n" + "right join dept c on b.deptno > 10\n";
    checkPlanning(tester, preProgram, new HepPlanner(program), sql);
}
Also used : HepProgram(org.apache.calcite.plan.hep.HepProgram) HepPlanner(org.apache.calcite.plan.hep.HepPlanner) Test(org.junit.Test)

Example 53 with HepProgram

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

the class RelOptRulesTest method testPushFilterPastProject.

/**
 * Test case for
 * <a href="https://issues.apache.org/jira/browse/CALCITE-448">[CALCITE-448]
 * FilterIntoJoinRule creates filters containing invalid RexInputRef</a>.
 */
@Test
public void testPushFilterPastProject() {
    final HepProgram preProgram = HepProgram.builder().addRuleInstance(ProjectMergeRule.INSTANCE).build();
    final FilterJoinRule.Predicate predicate = new FilterJoinRule.Predicate() {

        public boolean apply(Join join, JoinRelType joinType, RexNode exp) {
            return joinType != JoinRelType.INNER;
        }
    };
    final FilterJoinRule join = new FilterJoinRule.JoinConditionPushRule(RelBuilder.proto(), predicate);
    final FilterJoinRule filterOnJoin = new FilterJoinRule.FilterIntoJoinRule(true, RelBuilder.proto(), predicate);
    final HepProgram program = HepProgram.builder().addGroupBegin().addRuleInstance(FilterProjectTransposeRule.INSTANCE).addRuleInstance(join).addRuleInstance(filterOnJoin).addGroupEnd().build();
    final String sql = "select a.name\n" + "from dept a\n" + "left join dept b on b.deptno > 10\n" + "right join dept c on b.deptno > 10\n";
    checkPlanning(tester, preProgram, new HepPlanner(program), sql);
}
Also used : JoinRelType(org.apache.calcite.rel.core.JoinRelType) HepProgram(org.apache.calcite.plan.hep.HepProgram) Join(org.apache.calcite.rel.core.Join) FilterJoinRule(org.apache.calcite.rel.rules.FilterJoinRule) HepPlanner(org.apache.calcite.plan.hep.HepPlanner) RexNode(org.apache.calcite.rex.RexNode) Test(org.junit.Test)

Example 54 with HepProgram

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

the class RelOptRulesTest method testSemiJoinRuleRight.

/**
 * Test case for
 * <a href="https://issues.apache.org/jira/browse/CALCITE-1495">[CALCITE-1495]
 * SemiJoinRule should not apply to RIGHT and FULL JOIN</a>.
 */
@Test
public void testSemiJoinRuleRight() {
    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 right 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 55 with HepProgram

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

the class RelOptRulesTest method basePullConstantTroughAggregate.

private void basePullConstantTroughAggregate() throws Exception {
    HepProgram program = new HepProgramBuilder().addRuleInstance(ProjectMergeRule.INSTANCE).addRuleInstance(AggregateProjectPullUpConstantsRule.INSTANCE).addRuleInstance(ProjectMergeRule.INSTANCE).build();
    checkPlanning(program, "${sql}");
}
Also used : HepProgram(org.apache.calcite.plan.hep.HepProgram) HepProgramBuilder(org.apache.calcite.plan.hep.HepProgramBuilder)

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