@Override
  public void evaluateGroupBatch(VectorizedRowBatch batch)
      throws HiveException {

    evaluateInputExpr(batch);

    // Sum all non-null decimal column values for avg; maintain isGroupResultNull; after last row of
    // last group batch compute the group avg when sum is non-null.

    // We do not filter when PTF is in reducer.
    Preconditions.checkState(!batch.selectedInUse);

    final int size = batch.size;
    if (size == 0) {
      return;
    }
    DecimalColumnVector decimalColVector = ((DecimalColumnVector) batch.cols[inputColumnNum]);

    DecimalColumnVector outputColVector = (DecimalColumnVector) batch.cols[outputColumnNum];

    if (decimalColVector.isRepeating) {

      if (decimalColVector.noNulls || !decimalColVector.isNull[0]) {

        // We have a repeated value.
        isNull = false;
        HiveDecimalWritable repeatedValue = decimalColVector.vector[0];

        for (int i = 0; i < size; i++) {
          sum.mutateAdd(repeatedValue);
          nonNullGroupCount++;

          // Output row i AVG.
          avg.set(sum);
          temp.setFromLong(nonNullGroupCount);
          avg.mutateDivide(temp);
          outputColVector.set(i, avg);
        }
      } else {
        if (isNull) {
          outputColVector.isNull[0] = true;
          outputColVector.noNulls = false;
        } else {

          // Continue previous AVG.
          outputColVector.set(0, avg);
        }
        outputColVector.isRepeating = true;
      }
    } else if (decimalColVector.noNulls) {
      isNull = false;
      HiveDecimalWritable[] vector = decimalColVector.vector;
      for (int i = 0; i < size; i++) {
        sum.mutateAdd(vector[i]);
        nonNullGroupCount++;

        // Output row i AVG.
        avg.set(sum);
        temp.setFromLong(nonNullGroupCount);
        avg.mutateDivide(temp);
        outputColVector.set(i, avg);
      }
    } else {
      boolean[] batchIsNull = decimalColVector.isNull;
      int i = 0;
      while (batchIsNull[i]) {
        if (isNull) {
          outputColVector.isNull[i] = true;
          outputColVector.noNulls = false;
        } else {

          // Continue previous AVG.
          outputColVector.set(i, avg);
        }
        if (++i >= size) {
          return;
        }
      }

      isNull = false;
      HiveDecimalWritable[] vector = decimalColVector.vector;

      sum.mutateAdd(vector[i]);
      nonNullGroupCount++;

      // Output row i AVG.
      avg.set(sum);
      temp.setFromLong(nonNullGroupCount);
      avg.mutateDivide(temp);

      outputColVector.set(i++, avg);

      for (; i < size; i++) {
        if (!batchIsNull[i]) {
          sum.mutateAdd(vector[i]);
          nonNullGroupCount++;

          avg.set(sum);
          temp.setFromLong(nonNullGroupCount);
          avg.mutateDivide(temp);

          // Output row i AVG.
          outputColVector.set(i, avg);
        } else {

          // Continue previous AVG.
          outputColVector.set(i, avg);
        }
      }
    }
  }
This class evaluates streaming HiveDecimal avg() for a PTF group.

Stream average non-null column values and output sum / non-null count as we go along.
ql/src/java/org/apache/hadoop/hive/ql/exec/vector/ptf/VectorPTFEvaluatorStreamingDecimalAvg.java