Search in sources :

Example 1 with FilterCorrelateRule

use of org.apache.calcite.rel.rules.FilterCorrelateRule in project calcite by apache.

the class RelDecorrelator method decorrelate.

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;
}
Also used : RelBuilderFactory(org.apache.calcite.tools.RelBuilderFactory) HepProgram(org.apache.calcite.plan.hep.HepProgram) FilterCorrelateRule(org.apache.calcite.rel.rules.FilterCorrelateRule) FilterJoinRule(org.apache.calcite.rel.rules.FilterJoinRule) HepPlanner(org.apache.calcite.plan.hep.HepPlanner) Project(org.apache.calcite.rel.core.Project) LogicalProject(org.apache.calcite.rel.logical.LogicalProject) FilterProjectTransposeRule(org.apache.calcite.rel.rules.FilterProjectTransposeRule) RelNode(org.apache.calcite.rel.RelNode) Filter(org.apache.calcite.rel.core.Filter) LogicalFilter(org.apache.calcite.rel.logical.LogicalFilter)

Aggregations

HepPlanner (org.apache.calcite.plan.hep.HepPlanner)1 HepProgram (org.apache.calcite.plan.hep.HepProgram)1 RelNode (org.apache.calcite.rel.RelNode)1 Filter (org.apache.calcite.rel.core.Filter)1 Project (org.apache.calcite.rel.core.Project)1 LogicalFilter (org.apache.calcite.rel.logical.LogicalFilter)1 LogicalProject (org.apache.calcite.rel.logical.LogicalProject)1 FilterCorrelateRule (org.apache.calcite.rel.rules.FilterCorrelateRule)1 FilterJoinRule (org.apache.calcite.rel.rules.FilterJoinRule)1 FilterProjectTransposeRule (org.apache.calcite.rel.rules.FilterProjectTransposeRule)1 RelBuilderFactory (org.apache.calcite.tools.RelBuilderFactory)1