private void insertBucketColInBatch(Map<Long, MStorageDescriptor> sdIdToStorageDescriptor) throws MetaException {
    int rowCount = 0;
    for (MStorageDescriptor sd : sdIdToStorageDescriptor.values()) {
      rowCount += sd.getBucketCols() != null ? sd.getBucketCols().size() : 0;
    }
    if (rowCount == 0) {
      return;
    }
    String columns = "(\"SD_ID\",\"BUCKET_COL_NAME\",\"INTEGER_IDX\")";
    int columnCount = 3;
    BatchExecutionContext batchExecutionContext = new BatchExecutionContext() {
      int colIndex = 0;
      final Iterator<Map.Entry<Long, MStorageDescriptor>> sdIt = sdIdToStorageDescriptor.entrySet().iterator();
      Map.Entry<Long, MStorageDescriptor> sdEntry = sdIt.next();
      Iterator<String> it = sdEntry.getValue().getBucketCols() != null ?
          sdEntry.getValue().getBucketCols().iterator() : Collections.emptyIterator();
      @Override
      public void execute(String batchQueryText, int batchRowCount) throws MetaException {
        Object[] params = new Object[batchRowCount * columnCount];
        int index = 0;
        int paramIndex = 0;
        do {
          while (index < batchRowCount && it.hasNext()) {
            params[paramIndex++] = sdEntry.getKey();
            params[paramIndex++] = it.next();
            params[paramIndex++] = colIndex++;
            index++;
          }
          if (index < batchRowCount) {
            colIndex = 0;
            sdEntry = sdIt.next(); // sdIt.next() cannot be null since it is within the row count
            it = sdEntry.getValue().getBucketCols() != null ?
                sdEntry.getValue().getBucketCols().iterator() : Collections.emptyIterator();
          }
        } while (index < batchRowCount);
        executeQuery(batchQueryText, params);
      }
    };
    insertInBatch("\"BUCKETING_COLS\"", columns, columnCount, rowCount, batchExecutionContext);
  }
Interface to execute multiple row insert query in batch for direct SQL
standalone-metastore/metastore-server/src/main/java/org/apache/hadoop/hive/metastore/DirectSqlInsertPart.java