@Override
        public Pair<S, Long> call(AggregateService instance) throws IOException {
          RpcController controller = new AggregationClientRpcController();
          CoprocessorRpcUtils.BlockingRpcCallback<AggregateResponse> rpcCallback =
            new CoprocessorRpcUtils.BlockingRpcCallback<>();
          instance.getAvg(controller, requestArg, rpcCallback);
          AggregateResponse response = rpcCallback.get();
          if (controller.failed()) {
            throw new IOException(controller.errorText());
          }
          Pair<S, Long> pair = new Pair<>(null, 0L);
          if (response.getFirstPartCount() == 0) {
            return pair;
          }
          ByteString b = response.getFirstPart(0);
          T t = getParsedGenericInstance(ci.getClass(), 4, b);
          S s = ci.getPromotedValueFromProto(t);
          pair.setFirst(s);
          ByteBuffer bb =
            ByteBuffer.allocate(8).put(getBytesFromResponse(response.getSecondPart()));
          bb.rewind();
          pair.setSecond(bb.getLong());
          return pair;
        }
It computes average while fetching sum and row count from all the corresponding regions.
Approach is to compute a global sum of region level sum and rowcount and then compute the
average.
@param table table to scan.
@param scan  the HBase scan object to use to read data from HBase
@throws Throwable The caller is supposed to handle the exception as they are thrown &amp;
                  propagated to it.
hbase-endpoint/src/main/java/org/apache/hadoop/hbase/client/coprocessor/AggregationClient.java