Search in sources :

Example 61 with HepProgram

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

the class RelOptRulesTest method testSortUnionTranspose2.

/**
 * Test case for
 * <a href="https://issues.apache.org/jira/browse/CALCITE-889">[CALCITE-889]
 * Implement SortUnionTransposeRule</a>.
 */
@Test
public void testSortUnionTranspose2() {
    final HepProgram program = HepProgram.builder().addRuleInstance(ProjectSetOpTransposeRule.INSTANCE).addRuleInstance(SortUnionTransposeRule.MATCH_NULL_FETCH).build();
    final String sql = "select a.name from dept a\n" + "union all\n" + "select b.name from dept b\n" + "order by name";
    checkPlanning(program, sql);
}
Also used : HepProgram(org.apache.calcite.plan.hep.HepProgram) Test(org.junit.Test)

Example 62 with HepProgram

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

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

Example 64 with HepProgram

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

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

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