@Override
  public void onMatch(RelOptRuleCall call) {
    Project project = call.rel(0);

    List<RexNode> newExprs = new ArrayList<>();
    LastValueRewriteRexShuttle lastValueRewrite = new LastValueRewriteRexShuttle(
        project.getCluster().getRexBuilder());
    boolean modified = false;
    for (RexNode expr : project.getProjects()) {
      RexNode newExpr = lastValueRewrite.apply(expr);
      newExprs.add(newExpr);
      modified |= (newExpr != expr);
    }
    if (modified) {
      RelNode newProject = project.copy(
          project.getTraitSet(), project.getInput(), newExprs, project.getRowType());
      call.transformTo(newProject);
    }
  }
Rule to rewrite a window function containing a last value clause.
ql/src/java/org/apache/hadoop/hive/ql/optimizer/calcite/rules/HiveWindowingLastValueRewrite.java