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

    evaluateInputExpr(batch);

    // Sum all non-null long 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;
    }
    LongColumnVector longColVector = ((LongColumnVector) batch.cols[inputColumnNum]);
    if (longColVector.isRepeating) {

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

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

          // First aggregation calculation for group.
          sum = longColVector.vector[0] * batch.size;
          isGroupResultNull = false;
        } else {
          sum += longColVector.vector[0] * batch.size;
        }
        nonNullGroupCount += size;
      }
    } else if (longColVector.noNulls) {
      long[] vector = longColVector.vector;
      long varSum = vector[0];
      for (int i = 1; i < size; i++) {
        varSum += vector[i];
      }
      nonNullGroupCount += size;
      if (isGroupResultNull) {

        // First aggregation calculation for group.
        sum = varSum;
        isGroupResultNull = false;
      } else {
        sum += varSum;
      }
    } else {
      boolean[] batchIsNull = longColVector.isNull;
      int i = 0;
      while (batchIsNull[i]) {
        if (++i >= size) {
          return;
        }
      }
      long[] vector = longColVector.vector;
      long varSum = vector[i++];
      nonNullGroupCount++;
      for (; i < size; i++) {
        if (!batchIsNull[i]) {
          varSum += vector[i];
          nonNullGroupCount++;
        }
      }
      if (isGroupResultNull) {

        // First aggregation calculation for group.
        sum = varSum;
        isGroupResultNull = false;
      } else {
        sum += varSum;
      }
    }
  }
This class evaluates long 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/VectorPTFEvaluatorLongAvg.java