private static RelNode getRelNode(RelNode rel) {
    if (rel != null && rel instanceof HepRelVertex) {
      rel = ((HepRelVertex) rel).getCurrentRel();
    } else if (rel != null && rel instanceof RelSubset) {
      rel = Util.first(((RelSubset)rel).getBest(), ((RelSubset) rel).getOriginal());
    }
    return rel;
  }
EstimateUniqueKeys provides an ability to estimate unique keys based on statistics.
ql/src/java/org/apache/hadoop/hive/ql/optimizer/calcite/stats/EstimateUniqueKeys.java