Search in sources :

Example 6 with HepProgram

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

the class RelOptRulesTest method testMergeSetOpMixed.

/**
 * Tests that {@link UnionMergeRule} does nothing if its arguments have
 * are different set operators, {@link Union} and {@link Intersect}.
 */
@Test
public void testMergeSetOpMixed() throws Exception {
    HepProgram program = new HepProgramBuilder().addRuleInstance(UnionMergeRule.INSTANCE).addRuleInstance(UnionMergeRule.INTERSECT_INSTANCE).build();
    final String sql = "select * from emp where deptno = 10\n" + "union\n" + "select * from emp where deptno = 20\n" + "intersect\n" + "select * from emp where deptno = 30\n";
    sql(sql).with(program).checkUnchanged();
}
Also used : HepProgram(org.apache.calcite.plan.hep.HepProgram) HepProgramBuilder(org.apache.calcite.plan.hep.HepProgramBuilder) Test(org.junit.Test)

Example 7 with HepProgram

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

the class RelOptRulesTest method testProjectWindowTransposeRuleWithConstants.

@Test
public void testProjectWindowTransposeRuleWithConstants() {
    HepProgram program = new HepProgramBuilder().addRuleInstance(ProjectToWindowRule.PROJECT).addRuleInstance(ProjectMergeRule.INSTANCE).addRuleInstance(ProjectWindowTransposeRule.INSTANCE).build();
    final String sql = "select col1, col2\n" + "from (\n" + "  select empno,\n" + "    sum(100) over (partition by  deptno order by sal) as col1,\n" + "  sum(1000) over(partition by deptno order by sal) as col2\n" + "  from emp)";
    checkPlanning(program, sql);
}
Also used : HepProgram(org.apache.calcite.plan.hep.HepProgram) HepProgramBuilder(org.apache.calcite.plan.hep.HepProgramBuilder) Test(org.junit.Test)

Example 8 with HepProgram

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

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

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

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