Search in sources :

Example 56 with HepProgram

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

the class RelOptRulesTest method testReduceConstantsRequiresExecutor.

/**
 * Test case for
 * <a href="https://issues.apache.org/jira/browse/CALCITE-566">[CALCITE-566]
 * ReduceExpressionsRule requires planner to have an Executor</a>.
 */
@Test
public void testReduceConstantsRequiresExecutor() throws Exception {
    HepProgram program = new HepProgramBuilder().addRuleInstance(ReduceExpressionsRule.FILTER_INSTANCE).build();
    // Remove the executor
    tester.convertSqlToRel("values 1").rel.getCluster().getPlanner().setExecutor(null);
    // Rule should not fire, but there should be no NPE
    final String sql = "select * from (values (1,2)) where 1 + 2 > 3 + CAST(NULL AS INTEGER)";
    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 57 with HepProgram

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

the class RelOptRulesTest method testDistinctWithMultipleInputs.

@Test
public void testDistinctWithMultipleInputs() {
    final String sql = "SELECT deptno, SUM(comm), MIN(comm), COUNT(DISTINCT sal, comm)\n" + "FROM emp\n" + "GROUP BY deptno";
    HepProgram program = new HepProgramBuilder().addRuleInstance(AggregateExpandDistinctAggregatesRule.JOIN).build();
    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 58 with HepProgram

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

the class RelOptRulesTest method testMergeIntersect.

/**
 * Tests {@link UnionMergeRule#INTERSECT_INSTANCE}, which merges 2
 * {@link Intersect} operators into a single {@code Intersect} with 3
 * inputs.
 */
@Test
public void testMergeIntersect() throws Exception {
    HepProgram program = new HepProgramBuilder().addRuleInstance(UnionMergeRule.INTERSECT_INSTANCE).build();
    final String sql = "select * from emp where deptno = 10\n" + "intersect\n" + "select * from emp where deptno = 20\n" + "intersect\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 59 with HepProgram

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

the class RelOptRulesTest method testAggregateProjectPullUpConstants.

@Test
public void testAggregateProjectPullUpConstants() {
    HepProgram program = new HepProgramBuilder().addRuleInstance(AggregateProjectPullUpConstantsRule.INSTANCE2).build();
    final String sql = "select job, empno, sal, sum(sal) as s\n" + "from emp where empno = 10\n" + "group by job, empno, sal";
    checkPlanning(program, sql);
}
Also used : HepProgram(org.apache.calcite.plan.hep.HepProgram) HepProgramBuilder(org.apache.calcite.plan.hep.HepProgramBuilder) Test(org.junit.Test)

Example 60 with HepProgram

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

the class RelOptRulesTest method testSemiJoinRuleLeft.

/**
 * Similar to {@link #testSemiJoinRule()} but LEFT.
 */
@Test
public void testSemiJoinRuleLeft() {
    final HepProgram preProgram = HepProgram.builder().addRuleInstance(FilterProjectTransposeRule.INSTANCE).addRuleInstance(FilterJoinRule.FILTER_ON_JOIN).addRuleInstance(ProjectMergeRule.INSTANCE).build();
    final HepProgram program = HepProgram.builder().addRuleInstance(SemiJoinRule.PROJECT).build();
    final String sql = "select name from dept left join (\n" + "  select distinct deptno from emp\n" + "  where sal > 100) using (deptno)";
    sql(sql).withPre(preProgram).with(program).withDecorrelation(true).withTrim(true).check();
}
Also used : HepProgram(org.apache.calcite.plan.hep.HepProgram) 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