Search in sources :

Example 51 with HepProgramBuilder

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

the class RelOptRulesTest method testMultipleDistinctWithGrouping.

@Test
public void testMultipleDistinctWithGrouping() {
    final String sql = "SELECT sal, SUM(comm), MIN(DISTINCT comm), SUM(DISTINCT sal)\n" + "FROM emp\n" + "GROUP BY sal";
    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 52 with HepProgramBuilder

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

the class RelOptRulesTest method testUnionMergeRule.

/**
 * Tests to see if the final branch of union is missed
 */
@Test
public void testUnionMergeRule() throws Exception {
    HepProgram program = new HepProgramBuilder().addRuleInstance(ProjectSetOpTransposeRule.INSTANCE).addRuleInstance(ProjectRemoveRule.INSTANCE).addRuleInstance(UnionMergeRule.INSTANCE).build();
    checkPlanning(program, "select * from (\n" + "select * from (\n" + "  select name, deptno from dept\n" + "  union all\n" + "  select name, deptno from\n" + "  (\n" + "    select name, deptno, count(1) from dept group by name, deptno\n" + "    union all\n" + "    select name, deptno, count(1) from dept group by name, deptno\n" + "  ) subq\n" + ") a\n" + "union 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)

Example 53 with HepProgramBuilder

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

the class RelOptRulesTest method testEmptyAggregateEmptyKeyWithAggregateValuesRule.

@Test
public void testEmptyAggregateEmptyKeyWithAggregateValuesRule() {
    HepProgram preProgram = HepProgram.builder().addRuleInstance(ReduceExpressionsRule.FILTER_INSTANCE).addRuleInstance(PruneEmptyRules.PROJECT_INSTANCE).build();
    HepProgram program = new HepProgramBuilder().addRuleInstance(AggregateValuesRule.INSTANCE).build();
    final String sql = "select count(*), sum(empno) from emp where false";
    sql(sql).withPre(preProgram).with(program).check();
}
Also used : HepProgram(org.apache.calcite.plan.hep.HepProgram) HepProgramBuilder(org.apache.calcite.plan.hep.HepProgramBuilder) Test(org.junit.Test)

Example 54 with HepProgramBuilder

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

the class RelOptRulesTest method testEmptyJoin.

@Test
public void testEmptyJoin() {
    HepProgram program = new HepProgramBuilder().addRuleInstance(ReduceExpressionsRule.FILTER_INSTANCE).addRuleInstance(PruneEmptyRules.PROJECT_INSTANCE).addRuleInstance(PruneEmptyRules.JOIN_LEFT_INSTANCE).addRuleInstance(PruneEmptyRules.JOIN_RIGHT_INSTANCE).build();
    // Plan should be empty
    checkPlanning(program, "select * from (\n" + "select * from emp where false)\n" + "join dept using (deptno)");
}
Also used : HepProgram(org.apache.calcite.plan.hep.HepProgram) HepProgramBuilder(org.apache.calcite.plan.hep.HepProgramBuilder) Test(org.junit.Test)

Example 55 with HepProgramBuilder

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

the class RelOptRulesTest method testReduceConstantsNull.

/**
 * Test case for
 * <a href="https://issues.apache.org/jira/browse/CALCITE-1860">[CALCITE-1860]
 * Duplicate null predicates cause NullPointerException in RexUtil</a>.
 */
@Test
public void testReduceConstantsNull() throws Exception {
    HepProgram program = new HepProgramBuilder().addRuleInstance(ReduceExpressionsRule.FILTER_INSTANCE).build();
    final String sql = "select * from (\n" + "  select *\n" + "  from (\n" + "    select cast(null as integer) as n\n" + "    from emp)\n" + "  where n is null and n is null)\n" + "where n is null";
    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)

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