org.apache.calcite.rel.rules.JoinToMultiJoinRule Java Examples

The following examples show how to use org.apache.calcite.rel.rules.JoinToMultiJoinRule. 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: Programs.java    From Bats with Apache License 2.0 5 votes vote down vote up
/** Creates a program that invokes heuristic join-order optimization
 * (via {@link org.apache.calcite.rel.rules.JoinToMultiJoinRule},
 * {@link org.apache.calcite.rel.rules.MultiJoin} and
 * {@link org.apache.calcite.rel.rules.LoptOptimizeJoinRule})
 * if there are 6 or more joins (7 or more relations). */
public static Program heuristicJoinOrder(
    final Iterable<? extends RelOptRule> rules,
    final boolean bushy, final int minJoinCount) {
  return (planner, rel, requiredOutputTraits, materializations, lattices) -> {
    final int joinCount = RelOptUtil.countJoins(rel);
    final Program program;
    if (joinCount < minJoinCount) {
      program = ofRules(rules);
    } else {
      // Create a program that gathers together joins as a MultiJoin.
      final HepProgram hep = new HepProgramBuilder()
          .addRuleInstance(FilterJoinRule.FILTER_ON_JOIN)
          .addMatchOrder(HepMatchOrder.BOTTOM_UP)
          .addRuleInstance(JoinToMultiJoinRule.INSTANCE)
          .build();
      final Program program1 =
          of(hep, false, DefaultRelMetadataProvider.INSTANCE);

      // Create a program that contains a rule to expand a MultiJoin
      // into heuristically ordered joins.
      // We use the rule set passed in, but remove JoinCommuteRule and
      // JoinPushThroughJoinRule, because they cause exhaustive search.
      final List<RelOptRule> list = Lists.newArrayList(rules);
      list.removeAll(
          ImmutableList.of(JoinCommuteRule.INSTANCE,
              JoinAssociateRule.INSTANCE,
              JoinPushThroughJoinRule.LEFT,
              JoinPushThroughJoinRule.RIGHT));
      list.add(bushy
          ? MultiJoinOptimizeBushyRule.INSTANCE
          : LoptOptimizeJoinRule.INSTANCE);
      final Program program2 = ofRules(list);

      program = sequence(program1, program2);
    }
    return program.run(
        planner, rel, requiredOutputTraits, materializations, lattices);
  };
}
 
Example #2
Source File: Programs.java    From calcite with Apache License 2.0 5 votes vote down vote up
/** Creates a program that invokes heuristic join-order optimization
 * (via {@link org.apache.calcite.rel.rules.JoinToMultiJoinRule},
 * {@link org.apache.calcite.rel.rules.MultiJoin} and
 * {@link org.apache.calcite.rel.rules.LoptOptimizeJoinRule})
 * if there are 6 or more joins (7 or more relations). */
public static Program heuristicJoinOrder(
    final Iterable<? extends RelOptRule> rules,
    final boolean bushy, final int minJoinCount) {
  return (planner, rel, requiredOutputTraits, materializations, lattices) -> {
    final int joinCount = RelOptUtil.countJoins(rel);
    final Program program;
    if (joinCount < minJoinCount) {
      program = ofRules(rules);
    } else {
      // Create a program that gathers together joins as a MultiJoin.
      final HepProgram hep = new HepProgramBuilder()
          .addRuleInstance(FilterJoinRule.FILTER_ON_JOIN)
          .addMatchOrder(HepMatchOrder.BOTTOM_UP)
          .addRuleInstance(JoinToMultiJoinRule.INSTANCE)
          .build();
      final Program program1 =
          of(hep, false, DefaultRelMetadataProvider.INSTANCE);

      // Create a program that contains a rule to expand a MultiJoin
      // into heuristically ordered joins.
      // We use the rule set passed in, but remove JoinCommuteRule and
      // JoinPushThroughJoinRule, because they cause exhaustive search.
      final List<RelOptRule> list = Lists.newArrayList(rules);
      list.removeAll(
          ImmutableList.of(JoinCommuteRule.INSTANCE,
              JoinAssociateRule.INSTANCE,
              JoinPushThroughJoinRule.LEFT,
              JoinPushThroughJoinRule.RIGHT));
      list.add(bushy
          ? MultiJoinOptimizeBushyRule.INSTANCE
          : LoptOptimizeJoinRule.INSTANCE);
      final Program program2 = ofRules(list);

      program = sequence(program1, program2);
    }
    return program.run(
        planner, rel, requiredOutputTraits, materializations, lattices);
  };
}