@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]);
    if (decimalColVector.isRepeating) {

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

        // We have a repeated value.  The sum increases by value * batch.size.
        temp.setFromLong(batch.size);
        if (isGroupResultNull) {

          // First aggregation calculation for group.
          sum.set(decimalColVector.vector[0]);
          sum.mutateMultiply(temp);
          isGroupResultNull = false;
        } else {
          temp.mutateMultiply(decimalColVector.vector[0]);
          sum.mutateAdd(temp);
        }
        nonNullGroupCount += size;
      }
    } else if (decimalColVector.noNulls) {
      HiveDecimalWritable[] vector = decimalColVector.vector;
      if (isGroupResultNull) {

        // First aggregation calculation for group.
        sum.set(vector[0]);
        isGroupResultNull = false;
      } else {
        sum.mutateAdd(vector[0]);
      }
      for (int i = 1; i < size; i++) {
        sum.mutateAdd(vector[i]);
      }
      nonNullGroupCount += size;
    } else {
      boolean[] batchIsNull = decimalColVector.isNull;
      int i = 0;
      while (batchIsNull[i]) {
        if (++i >= size) {
          return;
        }
      }
      HiveDecimalWritable[] vector = decimalColVector.vector;
      if (isGroupResultNull) {

        // First aggregation calculation for group.
        sum.set(vector[i++]);
        isGroupResultNull = false;
      } else {
        sum.mutateAdd(vector[i++]);
      }
      nonNullGroupCount++;
      for (; i < size; i++) {
        if (!batchIsNull[i]) {
          sum.mutateAdd(vector[i]);
          nonNullGroupCount++;
        }
      }
    }
  }
This class evaluates HiveDecimal avg() for a PTF group.

Sum up non-null column values; group result is sum / non-null count.
ql/src/java/org/apache/hadoop/hive/ql/exec/vector/ptf/VectorPTFEvaluatorDecimalAvg.java