private static void setJoinKey(
          ImmutableBitSet.Builder joinKeys,
          ImmutableBitSet.Builder otherJoinKeys,
          int ref1,
          int ref2,
          int firstFieldNum,
          int lastFieldNum,
          boolean swap) {
    if ((ref1 >= firstFieldNum) && (ref1 < lastFieldNum)) {
      if (!((ref2 >= firstFieldNum) && (ref2 < lastFieldNum))) {
        joinKeys.set(ref1 - firstFieldNum);
        otherJoinKeys.set(ref2);
      }
      return;
    }
    if (swap) {
      setJoinKey(
              joinKeys,
              otherJoinKeys,
              ref2,
              ref1,
              firstFieldNum,
              lastFieldNum,
              false);
    }
  }
Sets a join key if only one of the specified input references corresponds
to a specified factor as determined by its field numbers. Also keeps
track of the keys from the other factor.

@param joinKeys join keys to be set if a key is found
@param otherJoinKeys join keys for the other join factor
@param ref1 first input reference
@param ref2 second input reference
@param firstFieldNum first field number of the factor
@param lastFieldNum last field number + 1 of the factor
@param swap if true, check for the desired input reference in the second
input reference parameter if the first input reference isn't the correct
one
ql/src/java/org/apache/hadoop/hive/ql/optimizer/calcite/rules/HiveLoptOptimizeJoinRule.java