private static boolean isSelfJoinFilterUnique(
          RelMetadataQuery mq,
          HiveLoptMultiJoin multiJoin,
          int leftFactor,
          int rightFactor,
          List<RexNode> joinFilterList) {
    RexBuilder rexBuilder =
            multiJoin.getMultiJoinRel().getCluster().getRexBuilder();
    RelNode leftRel = multiJoin.getJoinFactor(leftFactor);
    RelNode rightRel = multiJoin.getJoinFactor(rightFactor);
    RexNode joinFilters =
            RexUtil.composeConjunction(rexBuilder, joinFilterList);

    // Adjust the offsets in the filter by shifting the left factor
    // to the left and shifting the right factor to the left and then back
    // to the right by the number of fields in the left
    int [] adjustments = new int[multiJoin.getNumTotalFields()];
    int leftAdjust = multiJoin.getJoinStart(leftFactor);
    int nLeftFields = leftRel.getRowType().getFieldCount();
    for (int i = 0; i < nLeftFields; i++) {
      adjustments[leftAdjust + i] = -leftAdjust;
    }
    int rightAdjust = multiJoin.getJoinStart(rightFactor);
    for (int i = 0; i < rightRel.getRowType().getFieldCount(); i++) {
      adjustments[rightAdjust + i] = -rightAdjust + nLeftFields;
    }
    joinFilters =
            joinFilters.accept(
                    new RelOptUtil.RexInputConverter(
                            rexBuilder,
                            multiJoin.getMultiJoinFields(),
                            leftRel.getRowType().getFieldList(),
                            rightRel.getRowType().getFieldList(),
                            adjustments));

    return areSelfJoinKeysUnique(mq, leftRel, rightRel, joinFilters);
  }
Determines if the equality join filters between two factors that map to
the same table consist of unique, identical keys.

@param multiJoin join factors being optimized
@param leftFactor left factor in the join
@param rightFactor right factor in the join
@param joinFilterList list of join filters between the two factors

@return true if the criteria are met
ql/src/java/org/apache/hadoop/hive/ql/optimizer/calcite/rules/HiveLoptOptimizeJoinRule.java