Search in sources :

Example 46 with HepProgramBuilder

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

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

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

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

the class RelOptRulesTest method testPullAggregateThroughUnion.

@Test
public void testPullAggregateThroughUnion() {
    HepProgram program = new HepProgramBuilder().addRuleInstance(AggregateUnionAggregateRule.INSTANCE).build();
    final String sql = "select deptno, job from" + " (select deptno, job from emp as e1" + " group by deptno,job" + "  union all" + " select deptno, job from emp as e2" + " group by deptno,job)" + " group by deptno,job";
    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 50 with HepProgramBuilder

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

the class RelOptRulesTest method testReduceConstantsNullEqualsOne.

// see HIVE-9645
@Test
public void testReduceConstantsNullEqualsOne() throws Exception {
    HepProgram program = new HepProgramBuilder().addRuleInstance(ReduceExpressionsRule.PROJECT_INSTANCE).addRuleInstance(ReduceExpressionsRule.FILTER_INSTANCE).addRuleInstance(ReduceExpressionsRule.JOIN_INSTANCE).build();
    checkPlanning(program, "select count(1) from emp where cast(null as integer) = 1");
}
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)168 Test (org.junit.Test)147 HepProgram (org.apache.calcite.plan.hep.HepProgram)143 HepPlanner (org.apache.calcite.plan.hep.HepPlanner)56 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