Search in sources :

Example 1 with RelOptRule

use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.plan.RelOptRule in project calcite by apache.

the class JdbcConvention method register.

@Override
public void register(RelOptPlanner planner) {
    for (RelOptRule rule : JdbcRules.rules(this)) {
        planner.addRule(rule);
    }
    planner.addRule(FilterSetOpTransposeRule.INSTANCE);
    planner.addRule(ProjectRemoveRule.INSTANCE);
}
Also used : RelOptRule(org.apache.calcite.plan.RelOptRule)

Example 2 with RelOptRule

use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.plan.RelOptRule in project calcite by apache.

the class Programs method heuristicJoinOrder.

/**
 * 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 new Program() {

        public RelNode run(RelOptPlanner planner, RelNode rel, RelTraitSet requiredOutputTraits, List<RelOptMaterialization> materializations, List<RelOptLattice> 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);
        }
    };
}
Also used : HepProgram(org.apache.calcite.plan.hep.HepProgram) HepProgram(org.apache.calcite.plan.hep.HepProgram) RelNode(org.apache.calcite.rel.RelNode) HepProgramBuilder(org.apache.calcite.plan.hep.HepProgramBuilder) List(java.util.List) ImmutableList(com.google.common.collect.ImmutableList) RelTraitSet(org.apache.calcite.plan.RelTraitSet) RelOptPlanner(org.apache.calcite.plan.RelOptPlanner) RelOptRule(org.apache.calcite.plan.RelOptRule)

Example 3 with RelOptRule

use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.plan.RelOptRule in project calcite by apache.

the class PigTableScan method register.

@Override
public void register(RelOptPlanner planner) {
    planner.addRule(PigToEnumerableConverterRule.INSTANCE);
    for (RelOptRule rule : PigRules.ALL_PIG_OPT_RULES) {
        planner.addRule(rule);
    }
    // Don't move Aggregates around, otherwise PigAggregate.implement() won't
    // know how to correctly procuce Pig Latin
    planner.removeRule(AggregateExpandDistinctAggregatesRule.INSTANCE);
    // Make sure planner picks PigJoin over EnumerableJoin. Should there be
    // a rule for this instead for removing ENUMERABLE_JOIN_RULE here?
    planner.removeRule(EnumerableRules.ENUMERABLE_JOIN_RULE);
}
Also used : RelOptRule(org.apache.calcite.plan.RelOptRule)

Example 4 with RelOptRule

use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.plan.RelOptRule in project calcite by apache.

the class HepPlanner method executeInstruction.

void executeInstruction(HepInstruction.RuleClass<?> instruction) {
    if (skippingGroup()) {
        return;
    }
    LOGGER.trace("Applying rule class {}", instruction.ruleClass);
    if (instruction.ruleSet == null) {
        instruction.ruleSet = new LinkedHashSet<>();
        for (RelOptRule rule : allRules) {
            if (instruction.ruleClass.isInstance(rule)) {
                instruction.ruleSet.add(rule);
            }
        }
    }
    applyRules(instruction.ruleSet, true);
}
Also used : RelOptRule(org.apache.calcite.plan.RelOptRule)

Example 5 with RelOptRule

use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.plan.RelOptRule in project calcite by apache.

the class CalcitePrepareImpl method createPlanner.

/**
 * Creates a query planner and initializes it with a default set of
 * rules.
 */
protected RelOptPlanner createPlanner(final CalcitePrepare.Context prepareContext, org.apache.calcite.plan.Context externalContext, RelOptCostFactory costFactory) {
    if (externalContext == null) {
        externalContext = Contexts.of(prepareContext.config());
    }
    final VolcanoPlanner planner = new VolcanoPlanner(costFactory, externalContext);
    planner.addRelTraitDef(ConventionTraitDef.INSTANCE);
    if (ENABLE_COLLATION_TRAIT) {
        planner.addRelTraitDef(RelCollationTraitDef.INSTANCE);
        planner.registerAbstractRelationalRules();
    }
    RelOptUtil.registerAbstractRels(planner);
    for (RelOptRule rule : DEFAULT_RULES) {
        planner.addRule(rule);
    }
    if (prepareContext.config().materializationsEnabled()) {
        planner.addRule(MaterializedViewFilterScanRule.INSTANCE);
        planner.addRule(AbstractMaterializedViewRule.INSTANCE_PROJECT_FILTER);
        planner.addRule(AbstractMaterializedViewRule.INSTANCE_FILTER);
        planner.addRule(AbstractMaterializedViewRule.INSTANCE_PROJECT_JOIN);
        planner.addRule(AbstractMaterializedViewRule.INSTANCE_JOIN);
        planner.addRule(AbstractMaterializedViewRule.INSTANCE_PROJECT_AGGREGATE);
        planner.addRule(AbstractMaterializedViewRule.INSTANCE_AGGREGATE);
    }
    if (enableBindable) {
        for (RelOptRule rule : Bindables.RULES) {
            planner.addRule(rule);
        }
    }
    planner.addRule(Bindables.BINDABLE_TABLE_SCAN_RULE);
    planner.addRule(ProjectTableScanRule.INSTANCE);
    planner.addRule(ProjectTableScanRule.INTERPRETER);
    if (ENABLE_ENUMERABLE) {
        for (RelOptRule rule : ENUMERABLE_RULES) {
            planner.addRule(rule);
        }
        planner.addRule(EnumerableInterpreterRule.INSTANCE);
    }
    if (enableBindable && ENABLE_ENUMERABLE) {
        planner.addRule(EnumerableBindable.EnumerableToBindableConverterRule.INSTANCE);
    }
    if (ENABLE_STREAM) {
        for (RelOptRule rule : StreamRules.RULES) {
            planner.addRule(rule);
        }
    }
    // Change the below to enable constant-reduction.
    if (false) {
        for (RelOptRule rule : CONSTANT_REDUCTION_RULES) {
            planner.addRule(rule);
        }
    }
    final SparkHandler spark = prepareContext.spark();
    if (spark.enabled()) {
        spark.registerRules(new SparkHandler.RuleSetBuilder() {

            public void addRule(RelOptRule rule) {
            // TODO:
            }

            public void removeRule(RelOptRule rule) {
            // TODO:
            }
        });
    }
    // allow test to add or remove rules
    Hook.PLANNER.run(planner);
    return planner;
}
Also used : VolcanoPlanner(org.apache.calcite.plan.volcano.VolcanoPlanner) RelOptRule(org.apache.calcite.plan.RelOptRule)

Aggregations

RelOptRule (org.apache.calcite.plan.RelOptRule)19 Test (org.junit.Test)7 RuleSet (org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.tools.RuleSet)6 RelOptPlanner (org.apache.calcite.plan.RelOptPlanner)6 BeamRelNode (org.apache.beam.sdk.extensions.sql.impl.rel.BeamRelNode)5 RelNode (org.apache.calcite.rel.RelNode)5 RelNode (org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.rel.RelNode)4 HepProgramBuilder (org.apache.calcite.plan.hep.HepProgramBuilder)4 ArrayList (java.util.ArrayList)3 RelOptRule (org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.plan.RelOptRule)3 RelTraitSet (org.apache.calcite.plan.RelTraitSet)3 VolcanoPlanner (org.apache.calcite.plan.volcano.VolcanoPlanner)3 ImmutableList (com.google.common.collect.ImmutableList)2 Connection (java.sql.Connection)2 List (java.util.List)2 JoinCommuteRule (org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.rel.rules.JoinCommuteRule)2 HepPlanner (org.apache.calcite.plan.hep.HepPlanner)2 JaninoRelMetadataProvider (org.apache.calcite.rel.metadata.JaninoRelMetadataProvider)2 Program (org.apache.calcite.tools.Program)2 RuleSet (org.apache.calcite.tools.RuleSet)2