use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.plan.RelTraitSet in project calcite by apache.
the class EnumerableJoinRule method convert.
@Override
public RelNode convert(RelNode rel) {
LogicalJoin join = (LogicalJoin) rel;
List<RelNode> newInputs = new ArrayList<>();
for (RelNode input : join.getInputs()) {
if (!(input.getConvention() instanceof EnumerableConvention)) {
input = convert(input, input.getTraitSet().replace(EnumerableConvention.INSTANCE));
}
newInputs.add(input);
}
final RelOptCluster cluster = join.getCluster();
final RelTraitSet traitSet = join.getTraitSet().replace(EnumerableConvention.INSTANCE);
final RelNode left = newInputs.get(0);
final RelNode right = newInputs.get(1);
final JoinInfo info = JoinInfo.of(left, right, join.getCondition());
if (!info.isEqui() && join.getJoinType() != JoinRelType.INNER) {
// if it is an inner join.
try {
return new EnumerableThetaJoin(cluster, traitSet, left, right, join.getCondition(), join.getVariablesSet(), join.getJoinType());
} catch (InvalidRelException e) {
EnumerableRules.LOGGER.debug(e.toString());
return null;
}
}
RelNode newRel;
try {
newRel = new EnumerableJoin(cluster, join.getTraitSet().replace(EnumerableConvention.INSTANCE), left, right, info.getEquiCondition(left, right, cluster.getRexBuilder()), info.leftKeys, info.rightKeys, join.getVariablesSet(), join.getJoinType());
} catch (InvalidRelException e) {
EnumerableRules.LOGGER.debug(e.toString());
return null;
}
if (!info.isEqui()) {
newRel = new EnumerableFilter(cluster, newRel.getTraitSet(), newRel, info.getRemaining(cluster.getRexBuilder()));
}
return newRel;
}
use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.plan.RelTraitSet in project calcite by apache.
the class EnumerableLimitRule method onMatch.
@Override
public void onMatch(RelOptRuleCall call) {
final Sort sort = call.rel(0);
if (sort.offset == null && sort.fetch == null) {
return;
}
final RelTraitSet traitSet = sort.getTraitSet().replace(EnumerableConvention.INSTANCE);
RelNode input = sort.getInput();
if (!sort.getCollation().getFieldCollations().isEmpty()) {
// Create a sort with the same sort key, but no offset or fetch.
input = sort.copy(sort.getTraitSet(), input, sort.getCollation(), null, null);
}
RelNode x = convert(input, input.getTraitSet().replace(EnumerableConvention.INSTANCE));
call.transformTo(new EnumerableLimit(sort.getCluster(), traitSet, x, sort.offset, sort.fetch));
}
use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.plan.RelTraitSet in project calcite by apache.
the class EnumerableProject method create.
/**
* Creates an EnumerableProject, specifying row type rather than field
* names.
*/
public static EnumerableProject create(final RelNode input, final List<? extends RexNode> projects, RelDataType rowType) {
final RelOptCluster cluster = input.getCluster();
final RelMetadataQuery mq = cluster.getMetadataQuery();
final RelTraitSet traitSet = cluster.traitSet().replace(EnumerableConvention.INSTANCE).replaceIfs(RelCollationTraitDef.INSTANCE, new Supplier<List<RelCollation>>() {
public List<RelCollation> get() {
return RelMdCollation.project(mq, input, projects);
}
});
return new EnumerableProject(cluster, traitSet, input, projects, rowType);
}
use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.plan.RelTraitSet in project calcite by apache.
the class EnumerableCorrelateRule method convert.
public RelNode convert(RelNode rel) {
final LogicalCorrelate c = (LogicalCorrelate) rel;
final RelTraitSet traitSet = c.getTraitSet().replace(EnumerableConvention.INSTANCE);
return new EnumerableCorrelate(rel.getCluster(), traitSet, convert(c.getLeft(), c.getLeft().getTraitSet().replace(EnumerableConvention.INSTANCE)), convert(c.getRight(), c.getRight().getTraitSet().replace(EnumerableConvention.INSTANCE)), c.getCorrelationId(), c.getRequiredColumns(), c.getJoinType());
}
use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.plan.RelTraitSet 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);
}
};
}
Aggregations