Search in sources :

Example 1 with HepProgram

use of org.apache.calcite.plan.hep.HepProgram in project flink by apache.

the class FlinkRelDecorrelator method decorrelate.

private RelNode decorrelate(RelNode root) {
    // first adjust count() expression if any
    HepProgram program = HepProgram.builder().addRuleInstance(new AdjustProjectForCountAggregateRule(false)).addRuleInstance(new AdjustProjectForCountAggregateRule(true)).addRuleInstance(FilterJoinRule.FILTER_ON_JOIN).addRuleInstance(FilterProjectTransposeRule.INSTANCE).addRuleInstance(FilterCorrelateRule.INSTANCE).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(FilterJoinRule.FILTER_ON_JOIN).addRuleInstance(FilterJoinRule.JOIN).build();
        final HepPlanner planner2 = createPlanner(program2);
        final RelNode newRoot = frame.r;
        planner2.setRoot(newRoot);
        return planner2.findBestExp();
    }
    return root;
}
Also used : HepProgram(org.apache.calcite.plan.hep.HepProgram) RelNode(org.apache.calcite.rel.RelNode) HepPlanner(org.apache.calcite.plan.hep.HepPlanner)

Example 2 with HepProgram

use of org.apache.calcite.plan.hep.HepProgram in project hive by apache.

the class HiveRelDecorrelator method decorrelate.

private RelNode decorrelate(RelNode root) {
    // first adjust count() expression if any
    HepProgram program = HepProgram.builder().addRuleInstance(new AdjustProjectForCountAggregateRule(false)).addRuleInstance(new AdjustProjectForCountAggregateRule(true)).addRuleInstance(FilterJoinRule.FILTER_ON_JOIN).addRuleInstance(FilterProjectTransposeRule.INSTANCE).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(FilterJoinRule.FILTER_ON_JOIN).addRuleInstance(FilterJoinRule.JOIN).build();
        final HepPlanner planner2 = createPlanner(program2);
        final RelNode newRoot = frame.r;
        planner2.setRoot(newRoot);
        return planner2.findBestExp();
    }
    assert (valueGen.isEmpty());
    return root;
}
Also used : HepProgram(org.apache.calcite.plan.hep.HepProgram) HiveRelNode(org.apache.hadoop.hive.ql.optimizer.calcite.reloperators.HiveRelNode) RelNode(org.apache.calcite.rel.RelNode) HepPlanner(org.apache.calcite.plan.hep.HepPlanner)

Example 3 with HepProgram

use of org.apache.calcite.plan.hep.HepProgram in project hive by apache.

the class HiveRelDecorrelator method removeCorrelationViaRule.

public RelNode removeCorrelationViaRule(RelNode root) {
    HepProgram program = HepProgram.builder().addRuleInstance(new RemoveSingleAggregateRule()).addRuleInstance(new RemoveCorrelationForScalarProjectRule()).addRuleInstance(new RemoveCorrelationForScalarAggregateRule()).build();
    HepPlanner planner = createPlanner(program);
    planner.setRoot(root);
    return planner.findBestExp();
}
Also used : HepProgram(org.apache.calcite.plan.hep.HepProgram) HepPlanner(org.apache.calcite.plan.hep.HepPlanner)

Example 4 with HepProgram

use of org.apache.calcite.plan.hep.HepProgram in project calcite by apache.

the class RelDecorrelator method removeCorrelationViaRule.

public RelNode removeCorrelationViaRule(RelNode root) {
    final RelBuilderFactory f = relBuilderFactory();
    HepProgram program = HepProgram.builder().addRuleInstance(new RemoveSingleAggregateRule(f)).addRuleInstance(new RemoveCorrelationForScalarProjectRule(f)).addRuleInstance(new RemoveCorrelationForScalarAggregateRule(f)).build();
    HepPlanner planner = createPlanner(program);
    planner.setRoot(root);
    return planner.findBestExp();
}
Also used : RelBuilderFactory(org.apache.calcite.tools.RelBuilderFactory) HepProgram(org.apache.calcite.plan.hep.HepProgram) HepPlanner(org.apache.calcite.plan.hep.HepPlanner)

Example 5 with HepProgram

use of org.apache.calcite.plan.hep.HepProgram 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

HepProgram (org.apache.calcite.plan.hep.HepProgram)190 Test (org.junit.Test)171 HepProgramBuilder (org.apache.calcite.plan.hep.HepProgramBuilder)142 HepPlanner (org.apache.calcite.plan.hep.HepPlanner)55 RelNode (org.apache.calcite.rel.RelNode)9 AggregateExtractProjectRule (org.apache.calcite.rel.rules.AggregateExtractProjectRule)4 RelBuilderFactory (org.apache.calcite.tools.RelBuilderFactory)4 Ignore (org.junit.Ignore)4 ImmutableList (com.google.common.collect.ImmutableList)3 List (java.util.List)3 Context (org.apache.calcite.plan.Context)3 RelDataType (org.apache.calcite.rel.type.RelDataType)3 RelDataTypeFactory (org.apache.calcite.rel.type.RelDataTypeFactory)3 Properties (java.util.Properties)2 CalciteConnectionConfigImpl (org.apache.calcite.config.CalciteConnectionConfigImpl)2 Project (org.apache.calcite.rel.core.Project)2 LogicalProject (org.apache.calcite.rel.logical.LogicalProject)2 FilterJoinRule (org.apache.calcite.rel.rules.FilterJoinRule)2 RelBuilder (org.apache.calcite.tools.RelBuilder)2 ImmutableMap (com.google.common.collect.ImmutableMap)1