Search in sources :

Example 91 with HepProgramBuilder

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

the class RelOptRulesTest method testMergeJoinFilter.

/**
 * Tests that a filters is combined are combined if they are identical,
 * even if one of them originates in an ON clause of a JOIN.
 */
@Test
public void testMergeJoinFilter() throws Exception {
    HepProgram program = new HepProgramBuilder().addRuleInstance(FilterProjectTransposeRule.INSTANCE).addRuleInstance(FilterMergeRule.INSTANCE).addRuleInstance(FilterJoinRule.FILTER_ON_JOIN).build();
    checkPlanning(program, "select * from (\n" + "  select d.deptno, e.ename\n" + "  from emp as e\n" + "  join dept as d\n" + "  on e.deptno = d.deptno\n" + "  and d.deptno = 10)\n" + "where deptno = 10\n");
}
Also used : HepProgram(org.apache.calcite.plan.hep.HepProgram) HepProgramBuilder(org.apache.calcite.plan.hep.HepProgramBuilder) Test(org.junit.Test)

Example 92 with HepProgramBuilder

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

the class RelOptRulesTest method testRemoveSemiJoin.

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

Example 93 with HepProgramBuilder

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

the class RelOptRulesTest method testJoinPushTransitivePredicatesRule.

/**
 * Test case for
 * <a href="https://issues.apache.org/jira/browse/CALCITE-2200">[CALCITE-2200]
 * Infinite loop for JoinPushTransitivePredicatesRule</a>.
 */
@Test
public void testJoinPushTransitivePredicatesRule() {
    HepProgram preProgram = new HepProgramBuilder().addRuleInstance(FilterJoinRule.FILTER_ON_JOIN).addRuleInstance(FilterJoinRule.JOIN).addRuleInstance(JoinPushTransitivePredicatesRule.INSTANCE).build();
    final HepPlanner hepPlanner = new HepPlanner(new HepProgramBuilder().build());
    final String sql = "select d.deptno from sales.emp d where d.deptno\n" + "IN (select e.deptno from sales.emp e " + "where e.deptno = d.deptno or e.deptno = 4)";
    sql(sql).withPre(preProgram).with(hepPlanner).checkUnchanged();
}
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 94 with HepProgramBuilder

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

the class RelOptRulesTest method testExtractYearMonthToRange.

@Test
public void testExtractYearMonthToRange() {
    final String sql = "select *\n" + "from sales.emp_b as e\n" + "where extract(year from birthdate) = 2014" + "and extract(month from birthdate) = 4";
    HepProgram program = new HepProgramBuilder().addRuleInstance(DateRangeRules.FILTER_INSTANCE).build();
    final Context context = Contexts.of(new CalciteConnectionConfigImpl(new Properties()));
    sql(sql).with(program).withContext(context).check();
}
Also used : Context(org.apache.calcite.plan.Context) CalciteConnectionConfigImpl(org.apache.calcite.config.CalciteConnectionConfigImpl) HepProgram(org.apache.calcite.plan.hep.HepProgram) HepProgramBuilder(org.apache.calcite.plan.hep.HepProgramBuilder) Properties(java.util.Properties) Test(org.junit.Test)

Example 95 with HepProgramBuilder

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

the class RelOptRulesTest method testReduceCasts.

@Test
public void testReduceCasts() throws Exception {
    HepProgram program = new HepProgramBuilder().addRuleInstance(ReduceExpressionsRule.PROJECT_INSTANCE).addRuleInstance(ReduceExpressionsRule.FILTER_INSTANCE).addRuleInstance(ReduceExpressionsRule.JOIN_INSTANCE).build();
    // The resulting plan should have no cast expressions
    checkPlanning(program, "select cast(d.name as varchar(128)), cast(e.empno as integer) " + "from dept as d inner join emp as e " + "on cast(d.deptno as integer) = cast(e.deptno as integer) " + "where cast(e.job as varchar(1)) = 'Manager'");
}
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)168 Test (org.junit.Test)147 HepProgram (org.apache.calcite.plan.hep.HepProgram)143 HepPlanner (org.apache.calcite.plan.hep.HepPlanner)56 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