Search in sources :

Example 16 with HepProgram

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

the class RelOptRulesTest method testDistinctCountMultiple.

/**
 * Tests implementing multiple distinct count the new way, using GROUPING
 *  SETS.
 */
@Test
public void testDistinctCountMultiple() {
    final HepProgram program = HepProgram.builder().addRuleInstance(AggregateExpandDistinctAggregatesRule.INSTANCE).addRuleInstance(AggregateProjectMergeRule.INSTANCE).build();
    checkPlanning(program, "select deptno, count(distinct ename), count(distinct job)\n" + " from sales.emp group by deptno");
}
Also used : HepProgram(org.apache.calcite.plan.hep.HepProgram) Test(org.junit.Test)

Example 17 with HepProgram

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

the class RelOptRulesTest method testWindowFunctionOnAggregations.

/**
 * Test case for
 * <a href="https://issues.apache.org/jira/browse/CALCITE-2078">[CALCITE-2078]
 * Aggregate functions in OVER clause</a>.
 */
@Test
public void testWindowFunctionOnAggregations() {
    final HepProgram program = HepProgram.builder().addRuleInstance(ProjectToWindowRule.PROJECT).build();
    final String sql = "SELECT\n" + "  min(empno),\n" + "  sum(sal),\n" + "  sum(sum(sal))\n" + "    over (partition by min(empno) order by sum(sal))\n" + "from emp\n" + "group by deptno";
    checkPlanning(program, sql);
}
Also used : HepProgram(org.apache.calcite.plan.hep.HepProgram) Test(org.junit.Test)

Example 18 with HepProgram

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

the class RelOptRulesTest method testRemoveSemiJoinRight.

@Test
public void testRemoveSemiJoinRight() throws Exception {
    HepProgram program = new HepProgramBuilder().addRuleInstance(FilterJoinRule.FILTER_ON_JOIN).addRuleInstance(JoinAddRedundantSemiJoinRule.INSTANCE).addRuleInstance(SemiJoinJoinTransposeRule.INSTANCE).addRuleInstance(SemiJoinRemoveRule.INSTANCE).build();
    checkPlanning(program, "select e1.ename from emp e1, dept d, emp e2 " + "where e1.deptno = d.deptno and d.deptno = e2.deptno");
}
Also used : HepProgram(org.apache.calcite.plan.hep.HepProgram) HepProgramBuilder(org.apache.calcite.plan.hep.HepProgramBuilder) Test(org.junit.Test)

Example 19 with HepProgram

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

the class RelOptRulesTest method testDistinctCountMultipleViaJoin.

/**
 * Tests implementing multiple distinct count the old way, using a join.
 */
@Test
public void testDistinctCountMultipleViaJoin() {
    final HepProgram program = HepProgram.builder().addRuleInstance(AggregateExpandDistinctAggregatesRule.JOIN).addRuleInstance(AggregateProjectMergeRule.INSTANCE).build();
    checkPlanning(program, "select deptno, count(distinct ename), count(distinct job, ename),\n" + "  count(distinct deptno, job), sum(sal)\n" + " from sales.emp group by deptno");
}
Also used : HepProgram(org.apache.calcite.plan.hep.HepProgram) Test(org.junit.Test)

Example 20 with HepProgram

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

the class RelOptRulesTest method testPullConstantThroughUnion3.

@Test
public void testPullConstantThroughUnion3() throws Exception {
    // We should leave at least a single column in each Union input
    HepProgram program = HepProgram.builder().addRuleInstance(UnionPullUpConstantsRule.INSTANCE).addRuleInstance(ProjectMergeRule.INSTANCE).build();
    final String sql = "select 2, 3 from emp as e1\n" + "union all\n" + "select 2, 3 from emp as e2";
    sql(sql).withTrim(true).with(program).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