Search in sources :

Example 26 with HepProgramBuilder

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

the class RelOptRulesTest method checkReduceNullableToNotNull.

private void checkReduceNullableToNotNull(ReduceExpressionsRule rule) {
    HepProgram program = new HepProgramBuilder().addRuleInstance(rule).build();
    final String sql = "select\n" + "  empno + case when 'a' = 'a' then 1 else null 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)

Example 27 with HepProgramBuilder

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

the class RelOptRulesTest method testPushAggregateThroughJoinDistinct.

/**
 * Push a aggregate functions into a relation that is unique on the join
 * key.
 */
@Test
public void testPushAggregateThroughJoinDistinct() {
    final HepProgram preProgram = new HepProgramBuilder().addRuleInstance(AggregateProjectMergeRule.INSTANCE).build();
    final HepProgram program = new HepProgramBuilder().addRuleInstance(AggregateJoinTransposeRule.EXTENDED).build();
    final String sql = "select d.name,\n" + "  sum(sal) as sum_sal, count(*) as c\n" + "from sales.emp as e\n" + "join (select distinct name from sales.dept) as d\n" + "  on e.job = d.name\n" + "group by 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 28 with HepProgramBuilder

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

the class RelOptRulesTest method testReduceValuesUnderProjectFilter.

@Test
public void testReduceValuesUnderProjectFilter() throws Exception {
    HepProgram program = new HepProgramBuilder().addRuleInstance(FilterProjectTransposeRule.INSTANCE).addRuleInstance(ProjectMergeRule.INSTANCE).addRuleInstance(ValuesReduceRule.PROJECT_FILTER_INSTANCE).build();
    // Plan should be same as for
    // select * from (values (11, 1, 10), (23, 3, 20)) as t(x, b, a)");
    checkPlanning(program, "select a + b as x, b, a from (values (10, 1), (30, 7), (20, 3)) as t(a, b)" + " where a - b < 21");
}
Also used : HepProgram(org.apache.calcite.plan.hep.HepProgram) HepProgramBuilder(org.apache.calcite.plan.hep.HepProgramBuilder) Test(org.junit.Test)

Example 29 with HepProgramBuilder

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

the class RelOptRulesTest method testSwapOuterJoin.

@Test
public void testSwapOuterJoin() {
    final HepProgram program = new HepProgramBuilder().addMatchLimit(1).addRuleInstance(JoinCommuteRule.SWAP_OUTER).build();
    checkPlanning(program, "select 1 from sales.dept d left outer join sales.emp e" + " on d.deptno = e.deptno");
}
Also used : HepProgram(org.apache.calcite.plan.hep.HepProgram) HepProgramBuilder(org.apache.calcite.plan.hep.HepProgramBuilder) Test(org.junit.Test)

Example 30 with HepProgramBuilder

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

the class RelOptRulesTest method testReduceConstantsCaseEquals2.

@Test
public void testReduceConstantsCaseEquals2() throws Exception {
    HepProgram program = new HepProgramBuilder().addRuleInstance(ReduceExpressionsRule.PROJECT_INSTANCE).addRuleInstance(ReduceExpressionsRule.FILTER_INSTANCE).addRuleInstance(ReduceExpressionsRule.JOIN_INSTANCE).build();
    // Equivalent to 'case when deptno = 20 then false
    // when deptno = 10 then true
    // else null end'
    checkPlanning(program, "select count(1) from emp\n" + "where case deptno\n" + "  when 20 then 2\n" + "  when 10 then 1\n" + "  else cast(null as integer) end = 1");
}
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