public void setFactorWeights() {
    factorWeights = new int[nJoinFactors][nJoinFactors];
    factorsRefByFactor = new ImmutableBitSet[nJoinFactors];
    for (int i = 0; i < nJoinFactors; i++) {
      factorsRefByFactor[i] = ImmutableBitSet.of();
    }

    for (RexNode joinFilter : allJoinFilters) {
      ImmutableBitSet factorRefs = factorsRefByJoinFilter.get(joinFilter);

      // don't give weights to non-comparison expressions
      if (!(joinFilter instanceof RexCall)) {
        continue;
      }
      if (!joinFilter.isA(SqlKind.COMPARISON)) {
        continue;
      }

      // OR the factors referenced in this join filter into the
      // bitmaps corresponding to each of the factors; however,
      // exclude the bit corresponding to the factor itself
      for (int factor : requireNonNull(factorRefs, "factorRefs")) {
        factorsRefByFactor[factor] =
                factorsRefByFactor[factor]
                        .rebuild()
                        .addAll(factorRefs)
                        .clear(factor)
                        .build();
      }

      if (factorRefs.cardinality() == 2) {
        int leftFactor = factorRefs.nextSetBit(0);
        int rightFactor = factorRefs.nextSetBit(leftFactor + 1);

        final RexCall call = (RexCall) joinFilter;
        ImmutableBitSet leftFields = fieldBitmap(call.getOperands().get(0));
        ImmutableBitSet leftBitmap = factorBitmap(leftFields);

        // filter contains only two factor references, one on each
        // side of the operator
        int weight;
        if (leftBitmap.cardinality() == 1) {
          // give higher weight to equi-joins
          switch (joinFilter.getKind()) {
            case EQUALS:
              weight = 3;
              break;
            default:
              weight = 2;
          }
        } else {
          // cross product of two tables
          weight = 1;
        }
        setFactorWeight(weight, leftFactor, rightFactor);
      } else {
        // multiple factor references -- set a weight for each
        // combination of factors referenced within the filter
        final List<Integer> list  = ImmutableIntList.copyOf(factorRefs);
        for (int outer : list) {
          for (int inner : list) {
            if (outer != inner) {
              setFactorWeight(1, outer, inner);
            }
          }
        }
      }
    }
  }
Sets weighting for each combination of factors, depending on which join
filters reference which factors. Greater weight is given to equality
conditions. Also, sets bitmaps indicating which factors are referenced by
each factor within join filters that are comparisons.
ql/src/java/org/apache/hadoop/hive/ql/optimizer/calcite/rules/HiveLoptMultiJoin.java