private RexNode adjustSemiJoinCondition(
      HiveLoptMultiJoin multiJoin,
      int leftAdjustment,
      RexNode semiJoinCondition,
      int leftIdx,
      int rightIdx) {
    // adjust the semijoin condition to reflect the fact that the
    // RHS is now the second factor into the semijoin and the LHS
    // is the first
    int rightAdjustment = 0;
    for (int i = 0; i < rightIdx; i++) {
      rightAdjustment -= multiJoin.getNumFieldsInJoinFactor(i);
    }
    int rightStart = -rightAdjustment;
    int numFieldsLeftIdx = multiJoin.getNumFieldsInJoinFactor(leftIdx);
    int numFieldsRightIdx = multiJoin.getNumFieldsInJoinFactor(rightIdx);
    rightAdjustment += numFieldsLeftIdx;

    // only adjust the filter if adjustments are required
    if ((leftAdjustment != 0) || (rightAdjustment != 0)) {
      int [] adjustments = new int[multiJoin.getNumTotalFields()];
      if (leftAdjustment != 0) {
        for (int i = -leftAdjustment;
            i < (-leftAdjustment + numFieldsLeftIdx);
            i++) {
          adjustments[i] = leftAdjustment;
        }
      }
      if (rightAdjustment != 0) {
        for (int i = rightStart;
            i < (rightStart + numFieldsRightIdx);
            i++) {
          adjustments[i] = rightAdjustment;
        }
      }
      return semiJoinCondition.accept(
          new RelOptUtil.RexInputConverter(
              rexBuilder,
              multiJoin.getMultiJoinFields(),
              adjustments));
    }

    return semiJoinCondition;
  }
Modifies the semijoin condition to reflect the fact that the RHS is now
the second factor into a join and the LHS is the first.

@param multiJoin join factors being optimized
@param leftAdjustment amount the left RexInputRefs need to be adjusted by
@param semiJoinCondition condition to be adjusted
@param leftIdx index of the join factor corresponding to the LHS of the
semijoin,
@param rightIdx index of the join factor corresponding to the RHS of the
semijoin

@return modified semijoin condition
ql/src/java/org/apache/hadoop/hive/ql/optimizer/calcite/rules/HiveLoptSemiJoinOptimizer.java