Search in sources :

Example 41 with HepProgram

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

the class RelOptRulesTest method testAggregateConstantKeyRule2.

/**
 * Tests {@link AggregateProjectPullUpConstantsRule} where reduction is not
 * possible because "deptno" is the only key.
 */
@Test
public void testAggregateConstantKeyRule2() {
    final HepProgram program = new HepProgramBuilder().addRuleInstance(AggregateProjectPullUpConstantsRule.INSTANCE2).build();
    final String sql = "select count(*) as c\n" + "from sales.emp\n" + "where deptno = 10\n" + "group by deptno";
    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 42 with HepProgram

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

the class RelOptRulesTest method testMergeUnionAll.

/**
 * Tests {@link UnionMergeRule}, which merges 2 {@link Union} operators into
 * a single {@code Union} with 3 inputs.
 */
@Test
public void testMergeUnionAll() throws Exception {
    HepProgram program = new HepProgramBuilder().addRuleInstance(UnionMergeRule.INSTANCE).build();
    final String sql = "select * from emp where deptno = 10\n" + "union all\n" + "select * from emp where deptno = 20\n" + "union all\n" + "select * from emp where deptno = 30\n";
    sql(sql).with(program).check();
}
Also used : HepProgram(org.apache.calcite.plan.hep.HepProgram) HepProgramBuilder(org.apache.calcite.plan.hep.HepProgramBuilder) Test(org.junit.Test)

Example 43 with HepProgram

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

the class RelOptRulesTest method testPushFilterPastAggThree.

/**
 * Test case for
 * <a href="https://issues.apache.org/jira/browse/CALCITE-799">[CALCITE-799]
 * Incorrect result for {@code HAVING count(*) > 1}</a>.
 */
@Test
public void testPushFilterPastAggThree() {
    final HepProgram program = HepProgram.builder().addRuleInstance(FilterAggregateTransposeRule.INSTANCE).build();
    final String sql = "select deptno from emp\n" + "group by deptno having count(*) > 1";
    checkPlanUnchanged(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 44 with HepProgram

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

the class RelOptRulesTest method testReduceConstants.

@Test
public void testReduceConstants() throws Exception {
    HepProgram program = new HepProgramBuilder().addRuleInstance(ReduceExpressionsRule.PROJECT_INSTANCE).addRuleInstance(ReduceExpressionsRule.FILTER_INSTANCE).addRuleInstance(ReduceExpressionsRule.JOIN_INSTANCE).build();
    // NOTE jvs 27-May-2006: among other things, this verifies
    // intentionally different treatment for identical coalesce expression
    // in select and where.
    // There is "CAST(2 AS INTEGER)" in the plan because 2 has type "INTEGER NOT
    // NULL" and we need "INTEGER".
    final String sql = "select" + " 1+2, d.deptno+(3+4), (5+6)+d.deptno, cast(null as integer)," + " coalesce(2,null), row(7+8)" + " from dept d inner join emp e" + " on d.deptno = e.deptno + (5-5)" + " where d.deptno=(7+8) and d.deptno=(8+7) and d.deptno=coalesce(2,null)";
    sql(sql).with(program).withProperty(Hook.REL_BUILDER_SIMPLIFY, false).check();
}
Also used : HepProgram(org.apache.calcite.plan.hep.HepProgram) HepProgramBuilder(org.apache.calcite.plan.hep.HepProgramBuilder) Test(org.junit.Test)

Example 45 with HepProgram

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

the class RelOptRulesTest method testProjectWindowTransposeRule.

@Test
public void testProjectWindowTransposeRule() {
    HepProgram program = new HepProgramBuilder().addRuleInstance(ProjectToWindowRule.PROJECT).addRuleInstance(ProjectWindowTransposeRule.INSTANCE).build();
    final String sql = "select count(empno) over(), deptno 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)

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