Search in sources :

Example 91 with HepProgram

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

the class RelOptRulesTest method testDistinctCount3.

/**
 * Test case for
 * <a href="https://issues.apache.org/jira/browse/CALCITE-1293">[CALCITE-1293]
 * Bad code generated when argument to COUNT(DISTINCT) is a # GROUP BY
 * column</a>.
 */
@Test
public void testDistinctCount3() {
    final String sql = "select count(distinct deptno), sum(sal)" + " from sales.emp group by deptno";
    final HepProgram program = HepProgram.builder().addRuleInstance(AggregateExpandDistinctAggregatesRule.INSTANCE).build();
    sql(sql).with(program).check();
}
Also used : HepProgram(org.apache.calcite.plan.hep.HepProgram) Test(org.junit.Test)

Example 92 with HepProgram

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

the class RelOptRulesTest method testCustomColumnResolvingInNonCorrelatedSubQuery.

@Test
public void testCustomColumnResolvingInNonCorrelatedSubQuery() {
    final String sql = "select *\n" + "from struct.t t1\n" + "where c0 in (\n" + "  select f1.c0 from struct.t t2)";
    final HepProgram program = new HepProgramBuilder().addRuleInstance(SubQueryRemoveRule.PROJECT).addRuleInstance(SubQueryRemoveRule.FILTER).addRuleInstance(SubQueryRemoveRule.JOIN).build();
    sql(sql).withTrim(true).expand(false).with(program).check();
}
Also used : HepProgram(org.apache.calcite.plan.hep.HepProgram) HepProgramBuilder(org.apache.calcite.plan.hep.HepProgramBuilder) Test(org.junit.Test)

Example 93 with HepProgram

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

the class RelOptRulesTest method testHeterogeneousConversion.

@Ignore("cycles")
@Test
public void testHeterogeneousConversion() throws Exception {
    // This one tests the planner's ability to correctly
    // apply different converters on top of a common
    // sub-expression.  The common sub-expression is the
    // reference to the table sales.emps.  On top of that
    // are two projections, unioned at the top.  For one
    // of the projections, we force a Fennel implementation.
    // For the other, we force a Java implementation.
    // Then, we request conversion from Fennel to Java,
    // and verify that it only applies to one usage of the
    // table, not both (which would be incorrect).
    HepProgram program = new HepProgramBuilder().addRuleInstance(TableScanRule.INSTANCE).addRuleInstance(ProjectToCalcRule.INSTANCE).addMatchLimit(1).addMatchLimit(HepProgram.MATCH_UNTIL_FIXPOINT).build();
    checkPlanning(program, "select upper(ename) from emp union all" + " select lower(ename) from emp");
}
Also used : HepProgram(org.apache.calcite.plan.hep.HepProgram) HepProgramBuilder(org.apache.calcite.plan.hep.HepProgramBuilder) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 94 with HepProgram

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

the class FlinkRelDecorrelator method removeCorrelationViaRule.

public RelNode removeCorrelationViaRule(RelNode root) {
    HepProgram program = HepProgram.builder().addRuleInstance(new RemoveSingleAggregateRule()).addRuleInstance(new RemoveCorrelationForScalarProjectRule()).addRuleInstance(new RemoveCorrelationForScalarAggregateRule()).build();
    HepPlanner planner = createPlanner(program);
    planner.setRoot(root);
    return planner.findBestExp();
}
Also used : HepProgram(org.apache.calcite.plan.hep.HepProgram) HepPlanner(org.apache.calcite.plan.hep.HepPlanner)

Example 95 with HepProgram

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

the class RelOptRulesTest method testReduceConstantsCalc.

@Test
public void testReduceConstantsCalc() throws Exception {
    // This reduction does not work using
    // ReduceExpressionsRule.PROJECT_INSTANCE or FILTER_INSTANCE,
    // only CALC_INSTANCE, because we need to pull the project expression
    // upper('table')
    // into the condition
    // upper('table') = 'TABLE'
    // and reduce it to TRUE. Only in the Calc are projects and conditions
    // combined.
    HepProgram program = new HepProgramBuilder().addRuleInstance(FilterProjectTransposeRule.INSTANCE).addRuleInstance(FilterSetOpTransposeRule.INSTANCE).addRuleInstance(FilterToCalcRule.INSTANCE).addRuleInstance(ProjectToCalcRule.INSTANCE).addRuleInstance(CalcMergeRule.INSTANCE).addRuleInstance(ReduceExpressionsRule.CALC_INSTANCE).addRuleInstance(PruneEmptyRules.UNION_INSTANCE).addRuleInstance(ProjectToCalcRule.INSTANCE).addRuleInstance(CalcMergeRule.INSTANCE).addRuleInstance(ReduceExpressionsRule.CALC_INSTANCE).build();
    // Result should be same as typing
    // SELECT * FROM (VALUES ('TABLE        ', 'T')) AS T(U, S)
    checkPlanning(program, "select * from (\n" + "  select upper(substring(x FROM 1 FOR 2) || substring(x FROM 3)) as u,\n" + "      substring(x FROM 1 FOR 1) as s\n" + "  from (\n" + "    select 'table' as x from (values (true))\n" + "    union\n" + "    select 'view' from (values (true))\n" + "    union\n" + "    select 'foreign table' from (values (true))\n" + "  )\n" + ") where u = 'TABLE'");
}
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