Search in sources :

Example 21 with HepProgramBuilder

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

the class RelOptRulesTest method testPushFilterWithRankExpr.

@Test
public void testPushFilterWithRankExpr() throws Exception {
    HepProgram program = new HepProgramBuilder().addRuleInstance(FilterProjectTransposeRule.INSTANCE).build();
    final String sql = "select e1.ename, r\n" + "from (\n" + "  select ename,\n" + "  rank() over(partition by  deptno order by sal) + 1 as r " + "  from emp) e1\n" + "where r < 2";
    checkPlanUnchanged(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 22 with HepProgramBuilder

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

the class RelOptRulesTest method checkPlanning.

private void checkPlanning(String query) throws Exception {
    final Tester tester1 = tester.withCatalogReaderFactory(new Function<RelDataTypeFactory, Prepare.CatalogReader>() {

        public Prepare.CatalogReader apply(RelDataTypeFactory typeFactory) {
            return new MockCatalogReader(typeFactory, true) {

                @Override
                public MockCatalogReader init() {
                    // CREATE SCHEMA abc;
                    // CREATE TABLE a(a INT);
                    // ...
                    // CREATE TABLE j(j INT);
                    MockSchema schema = new MockSchema("SALES");
                    registerSchema(schema);
                    final RelDataType intType = typeFactory.createSqlType(SqlTypeName.INTEGER);
                    for (int i = 0; i < 10; i++) {
                        String t = String.valueOf((char) ('A' + i));
                        MockTable table = MockTable.create(this, schema, t, false, 100);
                        table.addColumn(t, intType);
                        registerTable(table);
                    }
                    return this;
                }
            }.init();
        }
    });
    HepProgram program = new HepProgramBuilder().addMatchOrder(HepMatchOrder.BOTTOM_UP).addRuleInstance(ProjectRemoveRule.INSTANCE).addRuleInstance(JoinToMultiJoinRule.INSTANCE).build();
    checkPlanning(tester1, null, new HepPlanner(program), query);
}
Also used : HepProgram(org.apache.calcite.plan.hep.HepProgram) HepProgramBuilder(org.apache.calcite.plan.hep.HepProgramBuilder) RelDataType(org.apache.calcite.rel.type.RelDataType) HepPlanner(org.apache.calcite.plan.hep.HepPlanner) RelDataTypeFactory(org.apache.calcite.rel.type.RelDataTypeFactory)

Example 23 with HepProgramBuilder

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

the class RelOptRulesTest method testReduceNullableCase.

@Test
public void testReduceNullableCase() {
    HepProgramBuilder builder = new HepProgramBuilder();
    builder.addRuleClass(ReduceExpressionsRule.class);
    HepPlanner hepPlanner = new HepPlanner(builder.build());
    hepPlanner.addRule(ReduceExpressionsRule.PROJECT_INSTANCE);
    final String sql = "SELECT CASE WHEN 1=2 " + "THEN cast((values(1)) as integer) " + "ELSE 2 end from (values(1))";
    sql(sql).with(hepPlanner).check();
}
Also used : HepProgramBuilder(org.apache.calcite.plan.hep.HepProgramBuilder) HepPlanner(org.apache.calcite.plan.hep.HepPlanner) Test(org.junit.Test)

Example 24 with HepProgramBuilder

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

the class RelOptRulesTest method testSkipReduceConstantsCaseEquals.

@Test
public void testSkipReduceConstantsCaseEquals() throws Exception {
    HepProgram program = new HepProgramBuilder().addRuleInstance(ReduceExpressionsRule.PROJECT_INSTANCE).addRuleInstance(ReduceExpressionsRule.FILTER_INSTANCE).addRuleInstance(FilterJoinRule.FilterIntoJoinRule.FILTER_ON_JOIN).build();
    checkPlanning(program, "select * from emp e1, emp e2\n" + "where coalesce(e1.mgr, -1) = coalesce(e2.mgr, -1)");
}
Also used : HepProgram(org.apache.calcite.plan.hep.HepProgram) HepProgramBuilder(org.apache.calcite.plan.hep.HepProgramBuilder) Test(org.junit.Test)

Example 25 with HepProgramBuilder

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

the class RelOptRulesTest method testMinusMergeRule.

@Test
public void testMinusMergeRule() throws Exception {
    HepProgram program = new HepProgramBuilder().addRuleInstance(ProjectSetOpTransposeRule.INSTANCE).addRuleInstance(ProjectRemoveRule.INSTANCE).addRuleInstance(UnionMergeRule.MINUS_INSTANCE).build();
    checkPlanning(program, "select * from (\n" + "select * from (\n" + "  select name, deptno from\n" + "  (\n" + "    select name, deptno, count(1) from dept group by name, deptno\n" + "    except all\n" + "    select name, deptno, 1 from dept\n" + "  ) subq\n" + "  except all\n" + "  select name, deptno from\n" + "  (\n" + "    select name, deptno, 1 from dept\n" + "    except all\n" + "    select name, deptno, count(1) from dept group by name, deptno\n" + "  ) subq2\n" + ") a\n" + "except all\n" + "select name, deptno from dept\n" + ") aa\n");
}
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