public static RelNode stripHepVertices(RelNode rel) {
    if (rel instanceof HepRelVertex) {
      rel = ((HepRelVertex) rel).getCurrentRel();
    }
    List<RelNode> oldInputs = rel.getInputs();
    List<RelNode> newInputs = new ArrayList<>();
    for (RelNode oldInput : oldInputs) {
      newInputs.add(stripHepVertices(oldInput));
    }
    if (oldInputs.equals(newInputs)) {
      return rel;
    } else {
      return rel.copy(rel.getTraitSet(), newInputs);
    }
  }
Extracts inputs referenced by aggregate operator.
ql/src/java/org/apache/hadoop/hive/ql/optimizer/calcite/HiveCalciteUtil.java