private static boolean needsAdjustment(
          HiveLoptMultiJoin multiJoin,
          int[] adjustments,
          HiveLoptJoinTree joinTree,
          HiveLoptJoinTree otherTree,
          boolean selfJoin) {
    boolean needAdjustment = false;

    final List<Integer> joinOrder = new ArrayList<>();
    joinTree.getTreeOrder(joinOrder);
    if (otherTree != null) {
      otherTree.getTreeOrder(joinOrder);
    }

    int nFields = 0;
    for (int newPos = 0; newPos < joinOrder.size(); newPos++) {
      int origPos = joinOrder.get(newPos);
      int joinStart = multiJoin.getJoinStart(origPos);

      // Determine the adjustments needed for join references.  Note
      // that if the adjustment is being done for a self-join filter,
      // we always use the default adjustment value rather than
      // remapping the right factor to reference the left factor.
      // Otherwise, we have no way of later identifying that the join is
      // self-join.
      if (remapJoinReferences(
              multiJoin,
              origPos,
              joinOrder,
              newPos,
              adjustments,
              joinStart,
              nFields,
              selfJoin)) {
        needAdjustment = true;
      }
      nFields += multiJoin.getNumFieldsInJoinFactor(origPos);
    }

    return needAdjustment;
  }
Sets an array indicating how much each factor in a join tree needs to be
adjusted to reflect the tree's join ordering.

@param multiJoin join factors being optimized
@param adjustments array to be filled out
@param joinTree join tree
@param otherTree null unless joinTree only represents the left side of
the join tree
@param selfJoin true if no adjustments need to be made for self-joins

@return true if some adjustment is required; false otherwise
ql/src/java/org/apache/hadoop/hive/ql/optimizer/calcite/rules/HiveLoptOptimizeJoinRule.java