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();
}
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();
}
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");
}
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();
}
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'");
}
Aggregations