@Override
    public void onMatch(RelOptRuleCall call) {
      final Join join = call.rel(0);
      final HepRelVertex root = (HepRelVertex) call.getPlanner().getRoot();
      if (root.getCurrentRel() != join) {
        // Bail out
        return;
      }
      // The join is the root, but we should always end up with a Project operator
      // on top. We will add it.
      RelBuilder relBuilder = call.builder();
      relBuilder.push(join);
      List<RexNode> identityFields = relBuilder.fields(
          ImmutableBitSet.range(0, join.getRowType().getFieldCount()).asList());
      relBuilder.project(identityFields, ImmutableList.of(), true);
      call.transformTo(relBuilder.build());
    }
This rule adds a Project operator on top of the root operator if it is a join.
This is important to meet the requirements set by the rewriting rule with
respect to the plan returned by the input program.
ql/src/java/org/apache/hadoop/hive/ql/optimizer/calcite/rules/views/HiveMaterializedViewRule.java