use of org.apache.calcite.plan.hep.HepProgramBuilder in project calcite by apache.
the class RelOptRulesTest method testPushFilterWithRankExpr.
@Test
public void testPushFilterWithRankExpr() throws Exception {
HepProgram program = new HepProgramBuilder().addRuleInstance(FilterProjectTransposeRule.INSTANCE).build();
final String sql = "select e1.ename, r\n" + "from (\n" + " select ename,\n" + " rank() over(partition by deptno order by sal) + 1 as r " + " from emp) e1\n" + "where r < 2";
checkPlanUnchanged(new HepPlanner(program), sql);
}
use of org.apache.calcite.plan.hep.HepProgramBuilder in project calcite by apache.
the class RelOptRulesTest method checkPlanning.
private void checkPlanning(String query) throws Exception {
final Tester tester1 = tester.withCatalogReaderFactory(new Function<RelDataTypeFactory, Prepare.CatalogReader>() {
public Prepare.CatalogReader apply(RelDataTypeFactory typeFactory) {
return new MockCatalogReader(typeFactory, true) {
@Override
public MockCatalogReader init() {
// CREATE SCHEMA abc;
// CREATE TABLE a(a INT);
// ...
// CREATE TABLE j(j INT);
MockSchema schema = new MockSchema("SALES");
registerSchema(schema);
final RelDataType intType = typeFactory.createSqlType(SqlTypeName.INTEGER);
for (int i = 0; i < 10; i++) {
String t = String.valueOf((char) ('A' + i));
MockTable table = MockTable.create(this, schema, t, false, 100);
table.addColumn(t, intType);
registerTable(table);
}
return this;
}
}.init();
}
});
HepProgram program = new HepProgramBuilder().addMatchOrder(HepMatchOrder.BOTTOM_UP).addRuleInstance(ProjectRemoveRule.INSTANCE).addRuleInstance(JoinToMultiJoinRule.INSTANCE).build();
checkPlanning(tester1, null, new HepPlanner(program), query);
}
use of org.apache.calcite.plan.hep.HepProgramBuilder in project calcite by apache.
the class RelOptRulesTest method testReduceNullableCase.
@Test
public void testReduceNullableCase() {
HepProgramBuilder builder = new HepProgramBuilder();
builder.addRuleClass(ReduceExpressionsRule.class);
HepPlanner hepPlanner = new HepPlanner(builder.build());
hepPlanner.addRule(ReduceExpressionsRule.PROJECT_INSTANCE);
final String sql = "SELECT CASE WHEN 1=2 " + "THEN cast((values(1)) as integer) " + "ELSE 2 end from (values(1))";
sql(sql).with(hepPlanner).check();
}
use of org.apache.calcite.plan.hep.HepProgramBuilder in project calcite by apache.
the class RelOptRulesTest method testSkipReduceConstantsCaseEquals.
@Test
public void testSkipReduceConstantsCaseEquals() throws Exception {
HepProgram program = new HepProgramBuilder().addRuleInstance(ReduceExpressionsRule.PROJECT_INSTANCE).addRuleInstance(ReduceExpressionsRule.FILTER_INSTANCE).addRuleInstance(FilterJoinRule.FilterIntoJoinRule.FILTER_ON_JOIN).build();
checkPlanning(program, "select * from emp e1, emp e2\n" + "where coalesce(e1.mgr, -1) = coalesce(e2.mgr, -1)");
}
use of org.apache.calcite.plan.hep.HepProgramBuilder in project calcite by apache.
the class RelOptRulesTest method testMinusMergeRule.
@Test
public void testMinusMergeRule() throws Exception {
HepProgram program = new HepProgramBuilder().addRuleInstance(ProjectSetOpTransposeRule.INSTANCE).addRuleInstance(ProjectRemoveRule.INSTANCE).addRuleInstance(UnionMergeRule.MINUS_INSTANCE).build();
checkPlanning(program, "select * from (\n" + "select * from (\n" + " select name, deptno from\n" + " (\n" + " select name, deptno, count(1) from dept group by name, deptno\n" + " except all\n" + " select name, deptno, 1 from dept\n" + " ) subq\n" + " except all\n" + " select name, deptno from\n" + " (\n" + " select name, deptno, 1 from dept\n" + " except all\n" + " select name, deptno, count(1) from dept group by name, deptno\n" + " ) subq2\n" + ") a\n" + "except all\n" + "select name, deptno from dept\n" + ") aa\n");
}
Aggregations