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);
}
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);
}
};
}
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);
}
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);
}
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;
}
Aggregations