Search in sources :

Example 1 with Permutation

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);
}
Also used : Project(org.apache.calcite.rel.core.Project) HiveProject(org.apache.hadoop.hive.ql.optimizer.calcite.reloperators.HiveProject) RelNode(org.apache.calcite.rel.RelNode) Permutation(org.apache.calcite.util.Permutation) HiveJoin(org.apache.hadoop.hive.ql.optimizer.calcite.reloperators.HiveJoin) Join(org.apache.calcite.rel.core.Join)

Aggregations

RelNode (org.apache.calcite.rel.RelNode)1 Join (org.apache.calcite.rel.core.Join)1 Project (org.apache.calcite.rel.core.Project)1 Permutation (org.apache.calcite.util.Permutation)1 HiveJoin (org.apache.hadoop.hive.ql.optimizer.calcite.reloperators.HiveJoin)1 HiveProject (org.apache.hadoop.hive.ql.optimizer.calcite.reloperators.HiveProject)1