@Override
    public Object terminate(AggregationBuffer agg) throws HiveException {
      SumAvgStreamingState ss = (SumAvgStreamingState) agg;
      Object o = wrappedEval.terminate(ss.wrappedBuf);

      // After all the rows are processed, continue to generate results for the rows that results haven't generated.
      // For the case: X following and Y following, process first Y-X results and then insert X nulls.
      // For the case X preceding and Y following, process Y results.
      for (int i = Math.max(0, wFrameDef.getStart().getRelativeOffset()); i < wFrameDef.getEnd().getRelativeOffset(); i++) {
        if (ss.hasResultReady()) {
          ss.results.add(getNextResult(ss));
        }
        ss.numRows++;
      }
      for (int i = 0; i < wFrameDef.getStart().getRelativeOffset(); i++) {
        if (ss.hasResultReady()) {
          ss.results.add(null);
        }
        ss.numRows++;
      }

      return o;
    }
Retrieve the next stored intermediate result, i.e.,
Get S[x-1] in the computation of S[x..y] = S[y] - S[x-1].
ql/src/java/org/apache/hadoop/hive/ql/udf/generic/GenericUDAFStreamingEvaluator.java