@Override
  public void getSum(RpcController controller, AggregateRequest request,
    RpcCallback<AggregateResponse> done) {
    AggregateResponse response = null;
    InternalScanner scanner = null;
    PartialResultContext partialResultContext = new PartialResultContext();
    long sum = 0L;
    boolean hasMoreRows = true;
    try {
      ColumnInterpreter<T, S, P, Q, R> ci = constructColumnInterpreterFromRequest(request);
      S sumVal = null;
      T temp;
      Scan scan = ProtobufUtil.toScan(request.getScan());
      scanner = env.getRegion().getScanner(scan);
      byte[] colFamily = scan.getFamilies()[0];
      NavigableSet<byte[]> qualifiers = scan.getFamilyMap().get(colFamily);
      byte[] qualifier = null;
      if (qualifiers != null && !qualifiers.isEmpty()) {
        qualifier = qualifiers.pollFirst();
      }
      List<Cell> results = new ArrayList<>();
      do {
        if (shouldBreakForThrottling(request, scan, partialResultContext)) {
          break;
        }
        hasMoreRows = scanner.next(results);
        int listSize = results.size();
        for (int i = 0; i < listSize; i++) {
          temp = ci.getValue(colFamily, qualifier, results.get(i));
          if (temp != null) {
            sumVal = ci.add(sumVal, ci.castToReturnType(temp));
          }
        }
        postScanPartialResultUpdate(results, partialResultContext);
        results.clear();
      } while (hasMoreRows);
      response = singlePartResponse(request, hasMoreRows, partialResultContext, sumVal,
        ci::getProtoForPromotedType);
    } catch (IOException e) {
      CoprocessorRpcUtils.setControllerException(controller, e);
    } finally {
      if (scanner != null) {
        IOUtils.closeQuietly(scanner);
      }
      closeQuota(partialResultContext);
    }
    log.debug("Sum from this region is {}: {} (partial result: {}) (client {})",
      env.getRegion().getRegionInfo().getRegionNameAsString(), sum, hasMoreRows,
      RpcServer.getRequestUser());
    done.run(response);
  }
Gives the sum for a given combination of column qualifier and column family, in the given row
range as defined in the Scan object. In its current implementation, it takes one column family
and one column qualifier (if provided). In case of null column qualifier, sum for the entire
column family will be returned.
hbase-endpoint/src/main/java/org/apache/hadoop/hbase/coprocessor/AggregateImplementation.java