public static <I, R> List<R> runBatched(
      final int batchSize,
      List<I> input,
      Batchable<I, R> runnable) throws MetaException {
    if (input == null || input.isEmpty()) {
      return Collections.emptyList();
    }
    try {
      if (batchSize == NO_BATCHING || batchSize >= input.size()) {
        return runnable.run(input);
      }
      List<R> result = new ArrayList<>(input.size());
      for (int fromIndex = 0, toIndex = 0; toIndex < input.size(); fromIndex = toIndex) {
        toIndex = Math.min(fromIndex + batchSize, input.size());
        List<I> batchedInput = input.subList(fromIndex, toIndex);
        List<R> batchedOutput = runnable.run(batchedInput);
        if (batchedOutput != null) {
          result.addAll(batchedOutput);
        }
      }
      return result;
    } catch (Exception e) {
      throw ExceptionHandler.newMetaException(e);
    }
  }
Base class to add the batch process for DirectSQL or RawStore queries.
 1. Provide the implementation of run() to process one batch
 2. Call Batchable.runBatched() to process the whole dataset

 I: input type, R: result type
standalone-metastore/metastore-server/src/main/java/org/apache/hadoop/hive/metastore/Batchable.java