Java Code Examples for org.apache.calcite.plan.hep.HepProgramBuilder#addMatchOrder()

The following examples show how to use org.apache.calcite.plan.hep.HepProgramBuilder#addMatchOrder() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: HepPlannerTest.java    From calcite with Apache License 2.0 6 votes vote down vote up
@Test void testSubprogram() throws Exception {
  // Verify that subprogram gets re-executed until fixpoint.
  // In this case, the first time through we limit it to generate
  // only one calc; the second time through it will generate
  // a second calc, and then merge them.
  HepProgramBuilder subprogramBuilder = HepProgram.builder();
  subprogramBuilder.addMatchOrder(HepMatchOrder.TOP_DOWN);
  subprogramBuilder.addMatchLimit(1);
  subprogramBuilder.addRuleInstance(ProjectToCalcRule.INSTANCE);
  subprogramBuilder.addRuleInstance(FilterToCalcRule.INSTANCE);
  subprogramBuilder.addRuleInstance(CalcMergeRule.INSTANCE);

  HepProgramBuilder programBuilder = HepProgram.builder();
  programBuilder.addSubprogram(subprogramBuilder.build());

  final String sql = "select upper(ename) from\n"
      + "(select lower(ename) as ename from emp where empno = 100)";
  sql(sql).with(programBuilder.build()).check();
}
 
Example 2
Source File: HepPlannerTest.java    From calcite with Apache License 2.0 6 votes vote down vote up
@Test void testGC() throws Exception {
  HepProgramBuilder programBuilder = HepProgram.builder();
  programBuilder.addMatchOrder(HepMatchOrder.TOP_DOWN);
  programBuilder.addRuleInstance(CalcMergeRule.INSTANCE);
  programBuilder.addRuleInstance(ProjectToCalcRule.INSTANCE);
  programBuilder.addRuleInstance(FilterToCalcRule.INSTANCE);

  HepPlanner planner = new HepPlanner(programBuilder.build());
  planner.setRoot(
      tester.convertSqlToRel("select upper(name) from dept where deptno=20").rel);
  planner.findBestExp();
  // Reuse of HepPlanner (should trigger GC).
  planner.setRoot(
      tester.convertSqlToRel("select upper(name) from dept where deptno=20").rel);
  planner.findBestExp();
}
 
Example 3
Source File: MaterializationExpander.java    From dremio-oss with Apache License 2.0 5 votes vote down vote up
private static RelNode applyRule(RelNode node, RelOptRule rule) {
  final HepProgramBuilder builder = HepProgram.builder();
  builder.addMatchOrder(HepMatchOrder.ARBITRARY);
  builder.addRuleCollection(ImmutableList.of(rule));
  final HepProgram program = builder.build();

  final HepPlanner planner = new HepPlanner(program);
  planner.setRoot(node);
  return planner.findBestExp();
}
 
Example 4
Source File: HepPlannerTest.java    From calcite with Apache License 2.0 5 votes vote down vote up
@Test void testMatchLimitOneTopDown() throws Exception {
  // Verify that only the top union gets rewritten.

  HepProgramBuilder programBuilder = HepProgram.builder();
  programBuilder.addMatchOrder(HepMatchOrder.TOP_DOWN);
  programBuilder.addMatchLimit(1);
  programBuilder.addRuleInstance(UnionToDistinctRule.INSTANCE);

  sql(UNION_TREE).with(programBuilder.build()).check();
}
 
Example 5
Source File: HepPlannerTest.java    From calcite with Apache License 2.0 5 votes vote down vote up
@Test void testMatchLimitOneBottomUp() throws Exception {
  // Verify that only the bottom union gets rewritten.

  HepProgramBuilder programBuilder = HepProgram.builder();
  programBuilder.addMatchLimit(1);
  programBuilder.addMatchOrder(HepMatchOrder.BOTTOM_UP);
  programBuilder.addRuleInstance(UnionToDistinctRule.INSTANCE);

  sql(UNION_TREE).with(programBuilder.build()).check();
}
 
Example 6
Source File: HepPlannerTest.java    From calcite with Apache License 2.0 5 votes vote down vote up
private long checkRuleApplyCount(HepMatchOrder matchOrder) {
  final HepProgramBuilder programBuilder = HepProgram.builder();
  programBuilder.addMatchOrder(matchOrder);
  programBuilder.addRuleInstance(ReduceExpressionsRule.FILTER_INSTANCE);
  programBuilder.addRuleInstance(ReduceExpressionsRule.PROJECT_INSTANCE);

  final HepTestListener listener = new HepTestListener(0);
  HepPlanner planner = new HepPlanner(programBuilder.build());
  planner.addListener(listener);
  planner.setRoot(tester.convertSqlToRel(COMPLEX_UNION_TREE).rel);
  planner.findBestExp();
  return listener.getApplyTimes();
}