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