@SuppressWarnings({ "unchecked", "rawtypes" })
    @Override
    public Object iterate(int currentRow, LeadLagInfo leadLagInfo) throws HiveException {
      // Currently sum(distinct) not supported in PartitionEvaluator
      if (((GenericUDAFSumEvaluator)wrappedEvaluator).isWindowingDistinct()) {
        return super.iterate(currentRow, leadLagInfo);
      }

      Range currentRange = PTFRangeUtil.getRange(winFrame, currentRow, partition, nullsLast);
      ResultType result;
      if (currentRow == 0 ||  // Reset for the new partition
          sumAgg.prevRange == null ||
          currentRange.getSize() <= currentRange.getDiff(sumAgg.prevRange)) {
        result = (ResultType)calcFunctionValue(currentRange.iterator(), leadLagInfo);
        sumAgg.prevRange = currentRange;
        sumAgg.empty = false;
        sumAgg.prevSum = result;
      } else {
        // Given the previous range and the current range, calculate the new sum
        // from the previous sum and the difference to save the computation.
        Range r1 = newRange(sumAgg.prevRange.start, currentRange.start, partition);
        Range r2 = newRange(sumAgg.prevRange.end, currentRange.end, partition);
        ResultType sum1 = (ResultType)calcFunctionValue(r1.iterator(), leadLagInfo);
        ResultType sum2 = (ResultType)calcFunctionValue(r2.iterator(), leadLagInfo);
        result = typeOperation.add(typeOperation.minus(sumAgg.prevSum, sum1), sum2);

        sumAgg.prevRange = currentRange;
        sumAgg.prevSum = result;
      }

      return result;
    }
The base type for sum operator evaluator when a partition data is available
and streaming process is not possible. Some optimization can be done for such
case.
ql/src/java/org/apache/hadoop/hive/ql/udf/ptf/BasePartitionEvaluator.java