public RelNode align(Project rel, List<RelFieldCollation> collations) {
    // 1) We extract the collations indices
    boolean containsWindowing = false;
    for (RexNode childExp : rel.getProjects()) {
      if (childExp instanceof RexOver) {
        // TODO: support propagation for partitioning/ordering in windowing
        containsWindowing = true;
        break;
      }
    }
    ImmutableList.Builder<RelFieldCollation> propagateCollations = ImmutableList.builder();
    if (!containsWindowing) {
      for (RelFieldCollation c : collations) {
        RexNode rexNode = rel.getProjects().get(c.getFieldIndex());
        if (rexNode instanceof RexInputRef) {
          int newIdx = ((RexInputRef) rexNode).getIndex();
          propagateCollations.add(c.copy((newIdx)));
        }
      }
    }
    // 2) We propagate
    final RelNode child = dispatchAlign(rel.getInput(), propagateCollations.build());
    // 3) Return new Project
    return rel.copy(rel.getTraitSet(), ImmutableList.of(child));
  }
Execute the logic in this class. In particular, make a top-down traversal of the tree
and annotate and recreate appropriate operators.
ql/src/java/org/apache/hadoop/hive/ql/optimizer/calcite/rules/HiveRelColumnsAlignment.java