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

The following examples show how to use org.apache.calcite.rel.rules.FilterCorrelateRule. 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: EnumerableCorrelateTest.java    From calcite with Apache License 2.0 6 votes vote down vote up
/** Test case for
 * <a href="https://issues.apache.org/jira/browse/CALCITE-2930">[CALCITE-2930]
 * FilterCorrelateRule on a Correlate with SemiJoinType SEMI (or ANTI)
 * throws IllegalStateException</a> */
@Test void semiJoinCorrelateWithFilterCorrelateRule() {
  tester(false, new JdbcTest.HrSchema())
      .query(
          "select empid, name from emps e where e.deptno in (select d.deptno from depts d) and e.empid > 100")
      .withHook(Hook.PLANNER, (Consumer<RelOptPlanner>) planner -> {
        // force the semijoin to run via EnumerableCorrelate
        // instead of EnumerableHashJoin(SEMI),
        // and push the 'empid > 100' filter into the Correlate
        planner.addRule(JoinToCorrelateRule.INSTANCE);
        planner.addRule(FilterCorrelateRule.INSTANCE);
        planner.removeRule(EnumerableRules.ENUMERABLE_JOIN_RULE);
        planner.removeRule(EnumerableRules.ENUMERABLE_MERGE_JOIN_RULE);
      })
      .explainContains(""
          + "EnumerableCalc(expr#0..3=[{inputs}], empid=[$t1], name=[$t3])\n"
          + "  EnumerableCorrelate(correlation=[$cor1], joinType=[inner], requiredColumns=[{0}])\n"
          + "    EnumerableAggregate(group=[{0}])\n"
          + "      EnumerableTableScan(table=[[s, depts]])\n"
          + "    EnumerableCalc(expr#0..4=[{inputs}], expr#5=[$cor1], expr#6=[$t5.deptno], expr#7=[=($t6, $t1)], expr#8=[100], expr#9=[>($t0, $t8)], expr#10=[AND($t7, $t9)], proj#0..2=[{exprs}], $condition=[$t10])\n"
          + "      EnumerableTableScan(table=[[s, emps]])")
      .returnsUnordered(
          "empid=110; name=Theodore",
          "empid=150; name=Sebastian");
}
 
Example #2
Source File: RelDecorrelator.java    From Bats with Apache License 2.0 5 votes vote down vote up
private RelNode decorrelate(RelNode root) {
    // first adjust count() expression if any
    final RelBuilderFactory f = relBuilderFactory();
    HepProgram program = HepProgram.builder().addRuleInstance(new AdjustProjectForCountAggregateRule(false, f))
            .addRuleInstance(new AdjustProjectForCountAggregateRule(true, f))
            .addRuleInstance(new FilterJoinRule.FilterIntoJoinRule(true, f, FilterJoinRule.TRUE_PREDICATE))
            .addRuleInstance(new FilterProjectTransposeRule(Filter.class, Project.class, true, true, f))
            .addRuleInstance(new FilterCorrelateRule(f)).build();

    HepPlanner planner = createPlanner(program);

    planner.setRoot(root);
    root = planner.findBestExp();

    // Perform decorrelation.
    map.clear();

    final Frame frame = getInvoke(root, null);
    if (frame != null) {
        // has been rewritten; apply rules post-decorrelation
        final HepProgram program2 = HepProgram.builder()
                .addRuleInstance(new FilterJoinRule.FilterIntoJoinRule(true, f, FilterJoinRule.TRUE_PREDICATE))
                .addRuleInstance(new FilterJoinRule.JoinConditionPushRule(f, FilterJoinRule.TRUE_PREDICATE))
                .build();

        final HepPlanner planner2 = createPlanner(program2);
        final RelNode newRoot = frame.r;
        planner2.setRoot(newRoot);
        return planner2.findBestExp();
    }

    return root;
}
 
Example #3
Source File: RelDecorrelator.java    From flink with Apache License 2.0 4 votes vote down vote up
private RelNode decorrelate(RelNode root) {
  // first adjust count() expression if any
  final RelBuilderFactory f = relBuilderFactory();
  HepProgram program = HepProgram.builder()
      .addRuleInstance(new AdjustProjectForCountAggregateRule(false, f))
      .addRuleInstance(new AdjustProjectForCountAggregateRule(true, f))
      .addRuleInstance(
          // use FilterJoinRule instead of FlinkFilterJoinRule while CALCITE-3170 is fixed
          new FlinkFilterJoinRule.FlinkFilterIntoJoinRule(true, f,
              FlinkFilterJoinRule.TRUE_PREDICATE))
      .addRuleInstance(
          new FilterProjectTransposeRule(Filter.class, Project.class, true,
              true, f))
      .addRuleInstance(new FilterCorrelateRule(f))
      .build();

  HepPlanner planner = createPlanner(program);

  planner.setRoot(root);
  root = planner.findBestExp();

  // Perform decorrelation.
  map.clear();

  final Frame frame = getInvoke(root, null);
  if (frame != null) {
    // has been rewritten; apply rules post-decorrelation
    final HepProgram program2 = HepProgram.builder()
        .addRuleInstance(
            // use FilterJoinRule instead of FlinkFilterJoinRule while CALCITE-3170 is fixed
            new FlinkFilterJoinRule.FlinkFilterIntoJoinRule(
                true, f,
                FlinkFilterJoinRule.TRUE_PREDICATE))
        .addRuleInstance(
            new FlinkFilterJoinRule.FlinkJoinConditionPushRule(
                f,
                FlinkFilterJoinRule.TRUE_PREDICATE))
        .build();

    final HepPlanner planner2 = createPlanner(program2);
    final RelNode newRoot = frame.r;
    planner2.setRoot(newRoot);
    return planner2.findBestExp();
  }

  return root;
}
 
Example #4
Source File: RelDecorrelator.java    From flink with Apache License 2.0 4 votes vote down vote up
private RelNode decorrelate(RelNode root) {
  // first adjust count() expression if any
  final RelBuilderFactory f = relBuilderFactory();
  HepProgram program = HepProgram.builder()
      .addRuleInstance(new AdjustProjectForCountAggregateRule(false, f))
      .addRuleInstance(new AdjustProjectForCountAggregateRule(true, f))
      .addRuleInstance(
          // use FilterJoinRule instead of FlinkFilterJoinRule while CALCITE-3170 is fixed
          new FlinkFilterJoinRule.FlinkFilterIntoJoinRule(true, f,
              FlinkFilterJoinRule.TRUE_PREDICATE))
      .addRuleInstance(
          new FilterProjectTransposeRule(Filter.class, Project.class, true,
              true, f))
      .addRuleInstance(new FilterCorrelateRule(f))
      .build();

  HepPlanner planner = createPlanner(program);

  planner.setRoot(root);
  root = planner.findBestExp();

  // Perform decorrelation.
  map.clear();

  final Frame frame = getInvoke(root, null);
  if (frame != null) {
    // has been rewritten; apply rules post-decorrelation
    final HepProgram program2 = HepProgram.builder()
        .addRuleInstance(
            // use FilterJoinRule instead of FlinkFilterJoinRule while CALCITE-3170 is fixed
            new FlinkFilterJoinRule.FlinkFilterIntoJoinRule(
                true, f,
                FlinkFilterJoinRule.TRUE_PREDICATE))
        .addRuleInstance(
            new FlinkFilterJoinRule.FlinkJoinConditionPushRule(
                f,
                FlinkFilterJoinRule.TRUE_PREDICATE))
        .build();

    final HepPlanner planner2 = createPlanner(program2);
    final RelNode newRoot = frame.r;
    planner2.setRoot(newRoot);
    return planner2.findBestExp();
  }

  return root;
}
 
Example #5
Source File: RelDecorrelator.java    From calcite with Apache License 2.0 4 votes vote down vote up
protected RelNode decorrelate(RelNode root) {
  // first adjust count() expression if any
  final RelBuilderFactory f = relBuilderFactory();
  HepProgram program = HepProgram.builder()
      .addRuleInstance(new AdjustProjectForCountAggregateRule(false, f))
      .addRuleInstance(new AdjustProjectForCountAggregateRule(true, f))
      .addRuleInstance(
          new FilterJoinRule.FilterIntoJoinRule(true, f,
              FilterJoinRule.TRUE_PREDICATE))
      .addRuleInstance(
          new FilterProjectTransposeRule(Filter.class, Project.class, true,
              true, f))
      .addRuleInstance(new FilterCorrelateRule(f))
      .build();

  HepPlanner planner = createPlanner(program);

  planner.setRoot(root);
  root = planner.findBestExp();

  // Perform decorrelation.
  map.clear();

  final Frame frame = getInvoke(root, null);
  if (frame != null) {
    // has been rewritten; apply rules post-decorrelation
    final HepProgram program2 = HepProgram.builder()
        .addRuleInstance(
            new FilterJoinRule.FilterIntoJoinRule(
                true, f,
                FilterJoinRule.TRUE_PREDICATE))
        .addRuleInstance(
            new FilterJoinRule.JoinConditionPushRule(
                f,
                FilterJoinRule.TRUE_PREDICATE))
        .build();

    final HepPlanner planner2 = createPlanner(program2);
    final RelNode newRoot = frame.r;
    planner2.setRoot(newRoot);
    return planner2.findBestExp();
  }

  return root;
}