Search in sources :

Example 26 with HepProgram

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

the class RelOptRulesTest method testDistinctCountMixed.

@Test
public void testDistinctCountMixed() {
    final HepProgram program = HepProgram.builder().addRuleInstance(AggregateExpandDistinctAggregatesRule.INSTANCE).addRuleInstance(ProjectMergeRule.INSTANCE).build();
    checkPlanning(program, "select deptno, count(distinct deptno, job) as cddj, sum(sal) as s\n" + " from sales.emp group by deptno");
}
Also used : HepProgram(org.apache.calcite.plan.hep.HepProgram) Test(org.junit.Test)

Example 27 with HepProgram

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

the class RelOptRulesTest method testCastInAggregateReduceFunctions.

/**
 * Test case for
 * <a href="https://issues.apache.org/jira/browse/CALCITE-1621">[CALCITE-1621]
 * Adding a cast around the null literal in aggregate rules</a>.
 */
@Test
public void testCastInAggregateReduceFunctions() {
    final HepProgram program = HepProgram.builder().addRuleInstance(AggregateReduceFunctionsRule.INSTANCE).build();
    final String sql = "select name, stddev_pop(deptno), avg(deptno)," + " stddev_samp(deptno),var_pop(deptno), var_samp(deptno)\n" + "from sales.dept group by name";
    sql(sql).with(program).check();
}
Also used : HepProgram(org.apache.calcite.plan.hep.HepProgram) Test(org.junit.Test)

Example 28 with HepProgram

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

the class RelOptRulesTest method checkReduceNullableToNotNull.

private void checkReduceNullableToNotNull(ReduceExpressionsRule rule) {
    HepProgram program = new HepProgramBuilder().addRuleInstance(rule).build();
    final String sql = "select\n" + "  empno + case when 'a' = 'a' then 1 else null end as newcol\n" + "from emp";
    sql(sql).with(program).withProperty(Hook.REL_BUILDER_SIMPLIFY, false).check();
}
Also used : HepProgram(org.apache.calcite.plan.hep.HepProgram) HepProgramBuilder(org.apache.calcite.plan.hep.HepProgramBuilder)

Example 29 with HepProgram

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

the class RelOptRulesTest method testPushAggregateThroughJoinDistinct.

/**
 * Push a aggregate functions into a relation that is unique on the join
 * key.
 */
@Test
public void testPushAggregateThroughJoinDistinct() {
    final HepProgram preProgram = new HepProgramBuilder().addRuleInstance(AggregateProjectMergeRule.INSTANCE).build();
    final HepProgram program = new HepProgramBuilder().addRuleInstance(AggregateJoinTransposeRule.EXTENDED).build();
    final String sql = "select d.name,\n" + "  sum(sal) as sum_sal, count(*) as c\n" + "from sales.emp as e\n" + "join (select distinct name from sales.dept) as d\n" + "  on e.job = d.name\n" + "group by d.name";
    checkPlanning(tester, preProgram, 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 30 with HepProgram

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

the class RelOptRulesTest method testReduceValuesUnderProjectFilter.

@Test
public void testReduceValuesUnderProjectFilter() throws Exception {
    HepProgram program = new HepProgramBuilder().addRuleInstance(FilterProjectTransposeRule.INSTANCE).addRuleInstance(ProjectMergeRule.INSTANCE).addRuleInstance(ValuesReduceRule.PROJECT_FILTER_INSTANCE).build();
    // Plan should be same as for
    // select * from (values (11, 1, 10), (23, 3, 20)) as t(x, b, a)");
    checkPlanning(program, "select a + b as x, b, a from (values (10, 1), (30, 7), (20, 3)) as t(a, b)" + " where a - b < 21");
}
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