Search in sources :

Example 36 with HepProgram

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

the class RelOptRulesTest method testPushAggregateSumThroughJoinAfterAggregateReduce.

/**
 * Test case for
 * <a href="https://issues.apache.org/jira/browse/CALCITE-2108">[CALCITE-2108]
 * AggregateJoinTransposeRule incorrectly splits a SUM0 call when Aggregate
 * has no group keys</a>.
 *
 * <p>Similar to {@link #testPushAggregateSumThroughJoin()},
 * but also uses {@link AggregateReduceFunctionsRule}.
 */
@Test
public void testPushAggregateSumThroughJoinAfterAggregateReduce() {
    final HepProgram preProgram = new HepProgramBuilder().addRuleInstance(AggregateProjectMergeRule.INSTANCE).build();
    final HepProgram program = new HepProgramBuilder().addRuleInstance(AggregateReduceFunctionsRule.INSTANCE).addRuleInstance(AggregateJoinTransposeRule.EXTENDED).build();
    final String sql = "select sum(sal)\n" + "from (select * from sales.emp where empno = 10) as e\n" + "join sales.dept as d on 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)

Example 37 with HepProgram

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

the class RelOptRulesTest method testReduceCase.

/**
 * Test case for
 * <a href="https://issues.apache.org/jira/browse/CALCITE-1439">[CALCITE-1439]
 * Handling errors during constant reduction</a>.
 */
@Test
public void testReduceCase() throws Exception {
    HepProgram program = new HepProgramBuilder().addRuleInstance(ReduceExpressionsRule.PROJECT_INSTANCE).build();
    final String sql = "select\n" + "  case when false then cast(2.1 as float)\n" + "   else cast(1 as integer) end as newcol\n" + "from emp";
    sql(sql).with(program).withProperty(Hook.REL_BUILDER_SIMPLIFY, false).check();
}
Also used : HepProgram(org.apache.calcite.plan.hep.HepProgram) HepProgramBuilder(org.apache.calcite.plan.hep.HepProgramBuilder) Test(org.junit.Test)

Example 38 with HepProgram

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

the class RelOptRulesTest method testEmptyJoinRight.

@Test
public void testEmptyJoinRight() {
    HepProgram program = new HepProgramBuilder().addRuleInstance(ReduceExpressionsRule.FILTER_INSTANCE).addRuleInstance(PruneEmptyRules.PROJECT_INSTANCE).addRuleInstance(PruneEmptyRules.JOIN_LEFT_INSTANCE).addRuleInstance(PruneEmptyRules.JOIN_RIGHT_INSTANCE).build();
    // Plan should be equivalent to "select * from emp join dept".
    // Cannot optimize away the join because of RIGHT.
    checkPlanning(program, "select * from (\n" + "select * from emp where false)\n" + "right join dept using (deptno)");
}
Also used : HepProgram(org.apache.calcite.plan.hep.HepProgram) HepProgramBuilder(org.apache.calcite.plan.hep.HepProgramBuilder) Test(org.junit.Test)

Example 39 with HepProgram

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

the class RelOptRulesTest method testPushSemiJoinPastFilter.

@Test
public void testPushSemiJoinPastFilter() throws Exception {
    HepProgram program = new HepProgramBuilder().addRuleInstance(FilterJoinRule.FILTER_ON_JOIN).addRuleInstance(JoinAddRedundantSemiJoinRule.INSTANCE).addRuleInstance(SemiJoinFilterTransposeRule.INSTANCE).build();
    checkPlanning(program, "select e.ename from emp e, dept d " + "where e.deptno = d.deptno and e.ename = 'foo'");
}
Also used : HepProgram(org.apache.calcite.plan.hep.HepProgram) HepProgramBuilder(org.apache.calcite.plan.hep.HepProgramBuilder) Test(org.junit.Test)

Example 40 with HepProgram

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

the class RelOptRulesTest method testSemiJoinReduceConstants.

/**
 * Test case for
 * <a href="https://issues.apache.org/jira/browse/CALCITE-571">[CALCITE-571]
 * ReduceExpressionsRule tries to reduce SemiJoin condition to non-equi
 * condition</a>.
 */
@Test
public void testSemiJoinReduceConstants() {
    final HepProgram preProgram = HepProgram.builder().addRuleInstance(SemiJoinRule.PROJECT).build();
    final HepProgram program = HepProgram.builder().addRuleInstance(ReduceExpressionsRule.JOIN_INSTANCE).build();
    final String sql = "select e1.sal\n" + "from (select * from emp where deptno = 200) as e1\n" + "where e1.deptno in (\n" + "  select e2.deptno from emp e2 where e2.sal = 100)";
    sql(sql).withDecorrelation(false).withTrim(true).withPre(preProgram).with(program).checkUnchanged();
}
Also used : HepProgram(org.apache.calcite.plan.hep.HepProgram) 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