public static List<Integer> getNewRelDistributionKeys(
          HiveProject project, RelDistribution distribution) {
    Set<Integer> needed = new HashSet<>(distribution.getKeys());
    Map<Integer, Integer> m = new HashMap<>();
    for (int projPos = 0; projPos < project.getProjects().size(); projPos++) {
      RexNode expr = project.getProjects().get(projPos);
      if (expr instanceof RexInputRef) {
        Set<Integer> positions = HiveCalciteUtil.getInputRefs(expr);
        if (positions.size() <= 1) {
          int parentPos = positions.iterator().next();
          if(needed.contains(parentPos)){
            m.put(parentPos, projPos);
            needed.remove(parentPos);
          }
        }
      }
    }
    if(!needed.isEmpty()){
      return null;
    }

    List<Integer> distributionKeys = new ArrayList<>();
    for (Integer keyIndex : distribution.getKeys()) {
      distributionKeys.add(m.get(keyIndex));
    }
    return distributionKeys;
  }
Map Exchange distribution keys to the specified Project columns.
@param project the Project
@param distribution current distribution in Exchange
@return new distribution should be used in the Exchange
ql/src/java/org/apache/hadoop/hive/ql/optimizer/calcite/HiveRelOptUtil.java