Search in sources :

Example 11 with HepProgramBuilder

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

the class RelOptRulesTest method testReduceValuesNull.

// Calcite does not support INSERT yet
@Ignore
@Test
public void testReduceValuesNull() throws Exception {
    // The NULL literal presents pitfalls for value-reduction. Only
    // an INSERT statement contains un-CASTed NULL values.
    HepProgram program = new HepProgramBuilder().addRuleInstance(ValuesReduceRule.PROJECT_INSTANCE).build();
    checkPlanning(program, "insert into sales.depts(deptno,name) values (NULL, 'null')");
}
Also used : HepProgram(org.apache.calcite.plan.hep.HepProgram) HepProgramBuilder(org.apache.calcite.plan.hep.HepProgramBuilder) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 12 with HepProgramBuilder

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

the class RelOptRulesTest method testPushSemiJoinPastProject.

@Test
public void testPushSemiJoinPastProject() throws Exception {
    HepProgram program = new HepProgramBuilder().addRuleInstance(FilterJoinRule.FILTER_ON_JOIN).addRuleInstance(JoinAddRedundantSemiJoinRule.INSTANCE).addRuleInstance(SemiJoinProjectTransposeRule.INSTANCE).build();
    checkPlanning(program, "select e.* from " + "(select ename, trim(job), sal * 2, deptno 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 13 with HepProgramBuilder

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

the class RelOptRulesTest method transitiveInference.

private void transitiveInference(RelOptRule... extraRules) throws Exception {
    final DiffRepository diffRepos = getDiffRepos();
    final String sql = diffRepos.expand(null, "${sql}");
    final HepProgram program = new HepProgramBuilder().addRuleInstance(FilterJoinRule.DUMB_FILTER_ON_JOIN).addRuleInstance(FilterJoinRule.JOIN).addRuleInstance(FilterProjectTransposeRule.INSTANCE).addRuleInstance(FilterSetOpTransposeRule.INSTANCE).build();
    final HepPlanner planner = new HepPlanner(program);
    final RelRoot root = tester.convertSqlToRel(sql);
    final RelNode relInitial = root.rel;
    assertTrue(relInitial != null);
    List<RelMetadataProvider> list = Lists.newArrayList();
    list.add(DefaultRelMetadataProvider.INSTANCE);
    planner.registerMetadataProviders(list);
    RelMetadataProvider plannerChain = ChainedRelMetadataProvider.of(list);
    relInitial.getCluster().setMetadataProvider(new CachingRelMetadataProvider(plannerChain, planner));
    planner.setRoot(relInitial);
    RelNode relBefore = planner.findBestExp();
    String planBefore = NL + RelOptUtil.toString(relBefore);
    diffRepos.assertEquals("planBefore", "${planBefore}", planBefore);
    HepProgram program2 = new HepProgramBuilder().addMatchOrder(HepMatchOrder.BOTTOM_UP).addRuleInstance(FilterJoinRule.DUMB_FILTER_ON_JOIN).addRuleInstance(FilterJoinRule.JOIN).addRuleInstance(FilterProjectTransposeRule.INSTANCE).addRuleInstance(FilterSetOpTransposeRule.INSTANCE).addRuleInstance(JoinPushTransitivePredicatesRule.INSTANCE).addRuleCollection(Arrays.asList(extraRules)).build();
    final HepPlanner planner2 = new HepPlanner(program2);
    planner.registerMetadataProviders(list);
    planner2.setRoot(relBefore);
    RelNode relAfter = planner2.findBestExp();
    String planAfter = NL + RelOptUtil.toString(relAfter);
    diffRepos.assertEquals("planAfter", "${planAfter}", planAfter);
}
Also used : HepProgram(org.apache.calcite.plan.hep.HepProgram) RelNode(org.apache.calcite.rel.RelNode) CachingRelMetadataProvider(org.apache.calcite.rel.metadata.CachingRelMetadataProvider) HepProgramBuilder(org.apache.calcite.plan.hep.HepProgramBuilder) DefaultRelMetadataProvider(org.apache.calcite.rel.metadata.DefaultRelMetadataProvider) ChainedRelMetadataProvider(org.apache.calcite.rel.metadata.ChainedRelMetadataProvider) CachingRelMetadataProvider(org.apache.calcite.rel.metadata.CachingRelMetadataProvider) RelMetadataProvider(org.apache.calcite.rel.metadata.RelMetadataProvider) RelRoot(org.apache.calcite.rel.RelRoot) HepPlanner(org.apache.calcite.plan.hep.HepPlanner)

Example 14 with HepProgramBuilder

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

the class RelOptRulesTest method testAggregateProjectPullUpConstants2.

@Test
public void testAggregateProjectPullUpConstants2() {
    final HepProgram preProgram = new HepProgramBuilder().addRuleInstance(AggregateProjectMergeRule.INSTANCE).build();
    HepProgram program = new HepProgramBuilder().addRuleInstance(AggregateProjectPullUpConstantsRule.INSTANCE2).build();
    final String sql = "select ename, sal\n" + "from (select '1', ename, sal from emp where ename = 'John') subq\n" + "group by ename, sal";
    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 15 with HepProgramBuilder

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

the class RelOptRulesTest method testRemoveSemiJoinRightWithFilter.

@Test
public void testRemoveSemiJoinRightWithFilter() throws Exception {
    HepProgram program = new HepProgramBuilder().addRuleInstance(FilterJoinRule.FILTER_ON_JOIN).addRuleInstance(JoinAddRedundantSemiJoinRule.INSTANCE).addRuleInstance(SemiJoinJoinTransposeRule.INSTANCE).addRuleInstance(SemiJoinFilterTransposeRule.INSTANCE).addRuleInstance(SemiJoinRemoveRule.INSTANCE).build();
    checkPlanning(program, "select e1.ename from emp e1, dept d, emp e2 " + "where e1.deptno = d.deptno and d.deptno = e2.deptno " + "and d.name = 'foo'");
}
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