use of org.apache.calcite.plan.hep.HepProgram 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.HepProgram 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.HepProgram in project calcite by apache.
the class RelOptRulesTest method testPullFilterThroughAggregateGroupingSets.
@Test
public void testPullFilterThroughAggregateGroupingSets() throws Exception {
HepProgram preProgram = HepProgram.builder().addRuleInstance(ProjectMergeRule.INSTANCE).addRuleInstance(ProjectFilterTransposeRule.INSTANCE).build();
HepProgram program = HepProgram.builder().addRuleInstance(AggregateFilterTransposeRule.INSTANCE).build();
final String sql = "select ename, sal, deptno from (" + " select ename, sal, deptno" + " from emp" + " where sal > 5000)" + "group by rollup(ename, sal, deptno)";
checkPlanning(tester, preProgram, new HepPlanner(program), sql);
}
use of org.apache.calcite.plan.hep.HepProgram 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.HepProgram 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