use of org.apache.calcite.util.Permutation in project hive by apache.
the class HiveJoinCommuteRule method onMatch.
public void onMatch(final RelOptRuleCall call) {
Project topProject = call.rel(0);
Join join = call.rel(1);
// 1. We check if it is a permutation project. If it is
// not, or this is the identity, the rule will do nothing
final Permutation topPermutation = topProject.getPermutation();
if (topPermutation == null) {
return;
}
if (topPermutation.isIdentity()) {
return;
}
// 2. We swap the join
final RelNode swapped = JoinCommuteRule.swap(join, true);
if (swapped == null) {
return;
}
// bail out.
if (swapped instanceof Join) {
return;
}
// 4. We check if it is a permutation project. If it is
// not, or this is the identity, the rule will do nothing
final Project bottomProject = (Project) swapped;
final Permutation bottomPermutation = bottomProject.getPermutation();
if (bottomPermutation == null) {
return;
}
if (bottomPermutation.isIdentity()) {
return;
}
// 5. If the product of the topPermutation and bottomPermutation yields
// the identity, then we can swap the join and remove the project on
// top.
final Permutation product = topPermutation.product(bottomPermutation);
if (!product.isIdentity()) {
return;
}
// 6. Return the new join as a replacement
final Join swappedJoin = (Join) bottomProject.getInput(0);
call.transformTo(swappedJoin);
}
Aggregations