use of org.apache.calcite.plan.hep.HepProgram in project calcite by apache.
the class RelOptRulesTest method testDistinctNonDistinctAggregatesWithGrouping2.
@Test
public void testDistinctNonDistinctAggregatesWithGrouping2() {
final String sql = "SELECT deptno, COUNT(deptno), SUM(DISTINCT sal)\n" + "FROM emp\n" + "GROUP BY deptno";
HepProgram program = new HepProgramBuilder().addRuleInstance(AggregateExpandDistinctAggregatesRule.JOIN).build();
sql(sql).with(program).check();
}
use of org.apache.calcite.plan.hep.HepProgram in project calcite by apache.
the class RelOptRulesTest method testReduceCastTimeUnchanged.
/**
* Tests that a cast from a TIME to a TIMESTAMP is not reduced. It is not
* constant because the result depends upon the current date.
*/
@Test
public void testReduceCastTimeUnchanged() throws Exception {
HepProgram program = new HepProgramBuilder().addRuleInstance(ReduceExpressionsRule.PROJECT_INSTANCE).addRuleInstance(ReduceExpressionsRule.FILTER_INSTANCE).addRuleInstance(ReduceExpressionsRule.JOIN_INSTANCE).build();
sql("select cast(time '12:34:56' as timestamp) from emp as e").with(program).checkUnchanged();
}
use of org.apache.calcite.plan.hep.HepProgram in project calcite by apache.
the class RelOptRulesTest method testReduceValuesToEmpty.
@Test
public void testReduceValuesToEmpty() 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)) as t(a, b)" + " where a - b < 0");
}
use of org.apache.calcite.plan.hep.HepProgram in project calcite by apache.
the class RelOptRulesTest method testEmptyProject2.
/**
* Same query as {@link #testEmptyProject()}, and {@link PruneEmptyRules}
* is able to do the job that {@link ValuesReduceRule} cannot do.
*/
@Test
public void testEmptyProject2() throws Exception {
HepProgram program = new HepProgramBuilder().addRuleInstance(ValuesReduceRule.FILTER_INSTANCE).addRuleInstance(PruneEmptyRules.PROJECT_INSTANCE).build();
final String sql = "select z + x from (\n" + " select x + y as z, x from (\n" + " select * from (values (10, 1), (30, 3)) as t (x, y)\n" + " where x + y > 50))";
sql(sql).with(program).check();
}
use of org.apache.calcite.plan.hep.HepProgram in project calcite by apache.
the class RelOptRulesTest method testCustomColumnResolvingInCorrelatedSubQuery.
@Test
public void testCustomColumnResolvingInCorrelatedSubQuery() {
final String sql = "select *\n" + "from struct.t t1\n" + "where c0 = (\n" + " select max(f1.c0) from struct.t t2 where t1.k0 = t2.k0)";
final HepProgram program = new HepProgramBuilder().addRuleInstance(SubQueryRemoveRule.PROJECT).addRuleInstance(SubQueryRemoveRule.FILTER).addRuleInstance(SubQueryRemoveRule.JOIN).build();
sql(sql).withTrim(true).expand(false).with(program).check();
}
Aggregations