@Override
  public void getRowNum(RpcController controller, AggregateRequest request,
    RpcCallback<AggregateResponse> done) {
    AggregateResponse response = null;
    long counter = 0L;
    List<Cell> results = new ArrayList<>();
    InternalScanner scanner = null;
    PartialResultContext partialResultContext = new PartialResultContext();
    boolean hasMoreRows = true;
    try {
      Scan scan = ProtobufUtil.toScan(request.getScan());
      byte[][] colFamilies = scan.getFamilies();
      byte[] colFamily = colFamilies != null ? colFamilies[0] : null;
      NavigableSet<byte[]> qualifiers =
        colFamilies != null ? scan.getFamilyMap().get(colFamily) : null;
      byte[] qualifier = null;
      if (qualifiers != null && !qualifiers.isEmpty()) {
        qualifier = qualifiers.pollFirst();
      }
      if (scan.getFilter() == null && qualifier == null) {
        scan.setFilter(new FirstKeyOnlyFilter());
      }
      scanner = env.getRegion().getScanner(scan);
      do {
        if (shouldBreakForThrottling(request, scan, partialResultContext)) {
          break;
        }
        hasMoreRows = scanner.next(results);
        if (!results.isEmpty()) {
          counter++;
        }
        postScanPartialResultUpdate(results, partialResultContext);
        results.clear();
      } while (hasMoreRows);
      ByteBuffer bb = ByteBuffer.allocate(8).putLong(counter);
      bb.rewind();
      response = responseBuilder(request, hasMoreRows, partialResultContext)
        .addFirstPart(ByteString.copyFrom(bb)).build();
    } catch (IOException e) {
      CoprocessorRpcUtils.setControllerException(controller, e);
    } finally {
      if (scanner != null) {
        IOUtils.closeQuietly(scanner);
      }
      closeQuota(partialResultContext);
    }
    log.debug("Row counter from this region is {}: {} (partial result: {}) (client {})",
      env.getRegion().getRegionInfo().getRegionNameAsString(), counter, hasMoreRows,
      RpcServer.getRequestUser());
    done.run(response);
  }
Gives the row count for the given column family and column qualifier, in the given row range as
defined in the Scan object.
hbase-endpoint/src/main/java/org/apache/hadoop/hbase/coprocessor/AggregateImplementation.java