Search in sources :

Example 1 with RelBuilderFactory

use of org.apache.calcite.tools.RelBuilderFactory 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 2 with RelBuilderFactory

use of org.apache.calcite.tools.RelBuilderFactory 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)

Example 3 with RelBuilderFactory

use of org.apache.calcite.tools.RelBuilderFactory in project calcite by apache.

the class PigRelBuilderStyleTest method getVolcanoPlanner.

private RelOptPlanner getVolcanoPlanner(RelNode root) {
    final RelBuilderFactory builderFactory = RelBuilder.proto(PigRelFactories.ALL_PIG_REL_FACTORIES);
    // VolcanoPlanner
    final RelOptPlanner planner = root.getCluster().getPlanner();
    for (RelOptRule r : PigRules.ALL_PIG_OPT_RULES) {
        planner.addRule(r);
    }
    planner.removeRule(FilterAggregateTransposeRule.INSTANCE);
    planner.removeRule(FilterJoinRule.FILTER_ON_JOIN);
    planner.addRule(new FilterAggregateTransposeRule(PigFilter.class, builderFactory, PigAggregate.class));
    planner.addRule(new FilterIntoJoinRule(true, builderFactory, TRUE_PREDICATE));
    planner.setRoot(root);
    return planner;
}
Also used : RelBuilderFactory(org.apache.calcite.tools.RelBuilderFactory) PigAggregate(org.apache.calcite.adapter.pig.PigAggregate) FilterIntoJoinRule(org.apache.calcite.rel.rules.FilterJoinRule.FilterIntoJoinRule) FilterAggregateTransposeRule(org.apache.calcite.rel.rules.FilterAggregateTransposeRule) PigFilter(org.apache.calcite.adapter.pig.PigFilter) RelOptPlanner(org.apache.calcite.plan.RelOptPlanner) RelOptRule(org.apache.calcite.plan.RelOptRule)

Example 4 with RelBuilderFactory

use of org.apache.calcite.tools.RelBuilderFactory in project flink by apache.

the class RelDecorrelator method decorrelate.

protected RelNode decorrelate(RelNode root) {
    // first adjust count() expression if any
    final RelBuilderFactory f = relBuilderFactory();
    HepProgram program = HepProgram.builder().addRuleInstance(AdjustProjectForCountAggregateRule.config(false, this, f).toRule()).addRuleInstance(AdjustProjectForCountAggregateRule.config(true, this, f).toRule()).addRuleInstance(FilterJoinRule.FilterIntoJoinRule.Config.DEFAULT.withRelBuilderFactory(f).withOperandSupplier(b0 -> b0.operand(Filter.class).oneInput(b1 -> b1.operand(Join.class).anyInputs())).withDescription("FilterJoinRule:filter").as(FilterJoinRule.FilterIntoJoinRule.Config.class).withSmart(true).withPredicate((join, joinType, exp) -> true).as(FilterJoinRule.FilterIntoJoinRule.Config.class).toRule()).addRuleInstance(CoreRules.FILTER_PROJECT_TRANSPOSE.config.withRelBuilderFactory(f).as(FilterProjectTransposeRule.Config.class).withOperandFor(Filter.class, filter -> !RexUtil.containsCorrelation(filter.getCondition()), Project.class, project -> true).withCopyFilter(true).withCopyProject(true).toRule()).addRuleInstance(FilterCorrelateRule.Config.DEFAULT.withRelBuilderFactory(f).toRule()).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(CoreRules.FILTER_INTO_JOIN.config.withRelBuilderFactory(f).toRule()).addRuleInstance(CoreRules.JOIN_CONDITION_PUSH.config.withRelBuilderFactory(f).toRule()).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) Values(org.apache.calcite.rel.core.Values) Mappings(org.apache.calcite.util.mapping.Mappings) MultimapBuilder(com.google.common.collect.MultimapBuilder) BigDecimal(java.math.BigDecimal) CorrelationId(org.apache.calcite.rel.core.CorrelationId) Map(java.util.Map) ImmutableBitSet(org.apache.calcite.util.ImmutableBitSet) ImmutableBeans(org.apache.calcite.util.ImmutableBeans) Function2(org.apache.calcite.linq4j.function.Function2) SqlKind(org.apache.calcite.sql.SqlKind) RexVisitorImpl(org.apache.calcite.rex.RexVisitorImpl) SqlCountAggFunction(org.apache.calcite.sql.fun.SqlCountAggFunction) Set(java.util.Set) SqlExplainLevel(org.apache.calcite.sql.SqlExplainLevel) RelMetadataQuery(org.apache.calcite.rel.metadata.RelMetadataQuery) SqlStdOperatorTable(org.apache.calcite.sql.fun.SqlStdOperatorTable) RelCollation(org.apache.calcite.rel.RelCollation) RexCorrelVariable(org.apache.calcite.rex.RexCorrelVariable) HepRelVertex(org.apache.calcite.plan.hep.HepRelVertex) RexCall(org.apache.calcite.rex.RexCall) Iterables(com.google.common.collect.Iterables) Holder(org.apache.calcite.util.Holder) Correlate(org.apache.calcite.rel.core.Correlate) Ord(org.apache.calcite.linq4j.Ord) Filter(org.apache.calcite.rel.core.Filter) Join(org.apache.calcite.rel.core.Join) ArrayList(java.util.ArrayList) LogicalCorrelate(org.apache.calcite.rel.logical.LogicalCorrelate) ReflectiveVisitor(org.apache.calcite.util.ReflectiveVisitor) ImmutableSortedMap(com.google.common.collect.ImmutableSortedMap) ImmutableSortedSet(com.google.common.collect.ImmutableSortedSet) RelDataType(org.apache.calcite.rel.type.RelDataType) BiRel(org.apache.calcite.rel.BiRel) FilterProjectTransposeRule(org.apache.calcite.rel.rules.FilterProjectTransposeRule) RelRule(org.apache.calcite.plan.RelRule) Aggregate(org.apache.calcite.rel.core.Aggregate) RelHomogeneousShuttle(org.apache.calcite.rel.RelHomogeneousShuttle) LogicalAggregate(org.apache.calcite.rel.logical.LogicalAggregate) SqlFunction(org.apache.calcite.sql.SqlFunction) TreeMap(java.util.TreeMap) CalciteTrace(org.apache.calcite.util.trace.CalciteTrace) JoinRelType(org.apache.calcite.rel.core.JoinRelType) AggregateCall(org.apache.calcite.rel.core.AggregateCall) RelDataTypeFactory(org.apache.calcite.rel.type.RelDataTypeFactory) LogicalFilter(org.apache.calcite.rel.logical.LogicalFilter) RelFactories(org.apache.calcite.rel.core.RelFactories) RelOptCostImpl(org.apache.calcite.plan.RelOptCostImpl) LogicalTableFunctionScan(org.apache.calcite.rel.logical.LogicalTableFunctionScan) RelMdUtil(org.apache.calcite.rel.metadata.RelMdUtil) RexUtil(org.apache.calcite.rex.RexUtil) LogicalJoin(org.apache.calcite.rel.logical.LogicalJoin) RexNode(org.apache.calcite.rex.RexNode) RelBuilder(org.apache.calcite.tools.RelBuilder) HepProgram(org.apache.calcite.plan.hep.HepProgram) RelOptCluster(org.apache.calcite.plan.RelOptCluster) Litmus(org.apache.calcite.util.Litmus) ImmutableSet(com.google.common.collect.ImmutableSet) SortedSetMultimap(com.google.common.collect.SortedSetMultimap) ImmutableMap(com.google.common.collect.ImmutableMap) RexLiteral(org.apache.calcite.rex.RexLiteral) Collection(java.util.Collection) Context(org.apache.calcite.plan.Context) NavigableMap(java.util.NavigableMap) Collectors(java.util.stream.Collectors) Sets(com.google.common.collect.Sets) RexInputRef(org.apache.calcite.rex.RexInputRef) Objects(java.util.Objects) List(java.util.List) FilterJoinRule(org.apache.calcite.rel.rules.FilterJoinRule) Sort(org.apache.calcite.rel.core.Sort) RelDataTypeField(org.apache.calcite.rel.type.RelDataTypeField) SqlExplainFormat(org.apache.calcite.sql.SqlExplainFormat) SortedMap(java.util.SortedMap) Project(org.apache.calcite.rel.core.Project) RexFieldAccess(org.apache.calcite.rex.RexFieldAccess) HashMap(java.util.HashMap) Multimap(com.google.common.collect.Multimap) RelOptUtil(org.apache.calcite.plan.RelOptUtil) SqlSingleValueAggFunction(org.apache.calcite.sql.fun.SqlSingleValueAggFunction) HashSet(java.util.HashSet) ImmutableList(com.google.common.collect.ImmutableList) LogicalSnapshot(org.apache.calcite.rel.logical.LogicalSnapshot) Pair(org.apache.calcite.util.Pair) RelBuilderFactory(org.apache.calcite.tools.RelBuilderFactory) SqlOperator(org.apache.calcite.sql.SqlOperator) Nonnull(javax.annotation.Nonnull) Logger(org.slf4j.Logger) LogicalProject(org.apache.calcite.rel.logical.LogicalProject) RexBuilder(org.apache.calcite.rex.RexBuilder) RexSubQuery(org.apache.calcite.rex.RexSubQuery) HepPlanner(org.apache.calcite.plan.hep.HepPlanner) RelNode(org.apache.calcite.rel.RelNode) RelOptRuleCall(org.apache.calcite.plan.RelOptRuleCall) ReflectUtil(org.apache.calcite.util.ReflectUtil) CoreRules(org.apache.calcite.rel.rules.CoreRules) FilterCorrelateRule(org.apache.calcite.rel.rules.FilterCorrelateRule) RexShuttle(org.apache.calcite.rex.RexShuttle) Util(org.apache.calcite.util.Util) Collections(java.util.Collections) HepProgram(org.apache.calcite.plan.hep.HepProgram) RelNode(org.apache.calcite.rel.RelNode) Join(org.apache.calcite.rel.core.Join) LogicalJoin(org.apache.calcite.rel.logical.LogicalJoin) FilterJoinRule(org.apache.calcite.rel.rules.FilterJoinRule) HepPlanner(org.apache.calcite.plan.hep.HepPlanner)

Example 5 with RelBuilderFactory

use of org.apache.calcite.tools.RelBuilderFactory in project flink by apache.

the class RelDecorrelator method removeCorrelationViaRule.

public RelNode removeCorrelationViaRule(RelNode root) {
    final RelBuilderFactory f = relBuilderFactory();
    HepProgram program = HepProgram.builder().addRuleInstance(RemoveSingleAggregateRule.config(f).toRule()).addRuleInstance(RemoveCorrelationForScalarProjectRule.config(this, f).toRule()).addRuleInstance(RemoveCorrelationForScalarAggregateRule.config(this, f).toRule()).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)

Aggregations

RelBuilderFactory (org.apache.calcite.tools.RelBuilderFactory)5 HepPlanner (org.apache.calcite.plan.hep.HepPlanner)4 HepProgram (org.apache.calcite.plan.hep.HepProgram)4 ImmutableList (com.google.common.collect.ImmutableList)1 ImmutableMap (com.google.common.collect.ImmutableMap)1 ImmutableSet (com.google.common.collect.ImmutableSet)1 ImmutableSortedMap (com.google.common.collect.ImmutableSortedMap)1 ImmutableSortedSet (com.google.common.collect.ImmutableSortedSet)1 Iterables (com.google.common.collect.Iterables)1 Multimap (com.google.common.collect.Multimap)1 MultimapBuilder (com.google.common.collect.MultimapBuilder)1 Sets (com.google.common.collect.Sets)1 SortedSetMultimap (com.google.common.collect.SortedSetMultimap)1 BigDecimal (java.math.BigDecimal)1 ArrayList (java.util.ArrayList)1 Collection (java.util.Collection)1 Collections (java.util.Collections)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 List (java.util.List)1