Search in sources :

Example 31 with HepProgramBuilder

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

the class RelOptRulesTest method testEmptyAggregate.

@Test
public void testEmptyAggregate() {
    HepProgram preProgram = HepProgram.builder().addRuleInstance(ReduceExpressionsRule.FILTER_INSTANCE).addRuleInstance(PruneEmptyRules.PROJECT_INSTANCE).build();
    HepProgram program = new HepProgramBuilder().addRuleInstance(ReduceExpressionsRule.FILTER_INSTANCE).addRuleInstance(PruneEmptyRules.PROJECT_INSTANCE).addRuleInstance(PruneEmptyRules.AGGREGATE_INSTANCE).addRuleInstance(PruneEmptyRules.PROJECT_INSTANCE).build();
    final String sql = "select sum(empno) from emp where false group by deptno";
    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 32 with HepProgramBuilder

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

the class RelOptRulesTest method testEmptyMinus2.

@Test
public void testEmptyMinus2() throws Exception {
    HepProgram program = new HepProgramBuilder().addRuleInstance(ValuesReduceRule.PROJECT_FILTER_INSTANCE).addRuleInstance(PruneEmptyRules.PROJECT_INSTANCE).addRuleInstance(PruneEmptyRules.MINUS_INSTANCE).build();
    // Second and fourth inputs are empty; they are removed
    final String sql = "select * from (values (30, 3)) as t (x, y)\n" + "except\n" + "select * from (values (20, 2)) as t (x, y) where x > 30\n" + "except\n" + "select * from (values (40, 4))\n" + "except\n" + "select * from (values (50, 5)) as t (x, y) where x > 50";
    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)

Example 33 with HepProgramBuilder

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

the class RelOptRulesTest method testCorrelationScalarAggAndFilter.

/**
 * Test case for
 * <a href="https://issues.apache.org/jira/browse/CALCITE-2110">[CALCITE-2110]
 * ArrayIndexOutOfBoundsException in RexSimplify when using
 * ReduceExpressionsRule.JOIN_INSTANCE</a>.
 */
@Test
public void testCorrelationScalarAggAndFilter() {
    final String sql = "SELECT e1.empno\n" + "FROM emp e1, dept d1 where e1.deptno = d1.deptno\n" + "and e1.deptno < 10 and d1.deptno < 15\n" + "and e1.sal > (select avg(sal) from emp e2 where e1.empno = e2.empno)";
    HepProgram program = new HepProgramBuilder().addRuleInstance(ReduceExpressionsRule.PROJECT_INSTANCE).addRuleInstance(ReduceExpressionsRule.FILTER_INSTANCE).addRuleInstance(ReduceExpressionsRule.JOIN_INSTANCE).build();
    sql(sql).withDecorrelation(true).withTrim(true).expand(true).withPre(program).with(program).checkUnchanged();
}
Also used : HepProgram(org.apache.calcite.plan.hep.HepProgram) HepProgramBuilder(org.apache.calcite.plan.hep.HepProgramBuilder) Test(org.junit.Test)

Example 34 with HepProgramBuilder

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

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

Aggregations

HepProgramBuilder (org.apache.calcite.plan.hep.HepProgramBuilder)167 Test (org.junit.Test)147 HepProgram (org.apache.calcite.plan.hep.HepProgram)142 HepPlanner (org.apache.calcite.plan.hep.HepPlanner)55 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