@Override
    public void onMatch(RelOptRuleCall call) {
      final LogicalCorrelate correlate = call.rel(0);
      final RelNode left = call.rel(1);
      final Project aggOutputProject;
      final Aggregate aggregate;
      if (flavor) {
        aggOutputProject = call.rel(2);
        aggregate = call.rel(3);
      } else {
        aggregate = call.rel(2);

        // Create identity projection
        final List<Pair<RexNode, String>> projects = Lists.newArrayList();
        final List<RelDataTypeField> fields =
                aggregate.getRowType().getFieldList();
        for (int i = 0; i < fields.size(); i++) {
          projects.add(RexInputRef.of2(projects.size(), fields));
        }
        aggOutputProject = (Project) RelOptUtil.createProject(
            aggregate, Pair.left(projects), Pair.right(projects), false, relBuilder);
      }
      onMatch2(call, correlate, left, aggOutputProject, aggregate);
    }
Planner rule that adjusts projects when counts are added.
ql/src/java/org/apache/hadoop/hive/ql/optimizer/calcite/rules/HiveRelDecorrelator.java