Search in sources :

Example 21 with HepProgram

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

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

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

the class RelOptRulesTest method testPullFilterThroughAggregateGroupingSets.

@Test
public void testPullFilterThroughAggregateGroupingSets() throws Exception {
    HepProgram preProgram = HepProgram.builder().addRuleInstance(ProjectMergeRule.INSTANCE).addRuleInstance(ProjectFilterTransposeRule.INSTANCE).build();
    HepProgram program = HepProgram.builder().addRuleInstance(AggregateFilterTransposeRule.INSTANCE).build();
    final String sql = "select ename, sal, deptno from (" + "  select ename, sal, deptno" + "  from emp" + "  where sal > 5000)" + "group by rollup(ename, sal, deptno)";
    checkPlanning(tester, preProgram, new HepPlanner(program), sql);
}
Also used : HepProgram(org.apache.calcite.plan.hep.HepProgram) HepPlanner(org.apache.calcite.plan.hep.HepPlanner) Test(org.junit.Test)

Example 24 with HepProgram

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

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

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