private void insertStorageDescriptorParamInBatch(Map<Long, MStorageDescriptor> sdIdToStorageDescriptor)
      throws MetaException {
    int rowCount = 0;
    for (MStorageDescriptor sd : sdIdToStorageDescriptor.values()) {
      rowCount += sd.getParameters() != null ? sd.getParameters().size() : 0;
    }
    if (rowCount == 0) {
      return;
    }
    String columns = "(\"SD_ID\",\"PARAM_KEY\",\"PARAM_VALUE\")";
    int columnCount = 3;
    BatchExecutionContext batchExecutionContext = new BatchExecutionContext() {
      final Iterator<Map.Entry<Long, MStorageDescriptor>> sdIt = sdIdToStorageDescriptor.entrySet().iterator();
      Map.Entry<Long, MStorageDescriptor> sdEntry = sdIt.next();
      Iterator<Map.Entry<String, String>> it = sdEntry.getValue().getParameters() != null ?
          sdEntry.getValue().getParameters().entrySet().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()) {
            Map.Entry<String, String> entry = it.next();
            params[paramIndex++] = sdEntry.getKey();
            params[paramIndex++] = entry.getKey();
            params[paramIndex++] = entry.getValue();
            index++;
          }
          if (index < batchRowCount) {
            sdEntry = sdIt.next(); // sdIt.next() cannot be null since it is within the row count
            it = sdEntry.getValue().getParameters() != null  ?
                sdEntry.getValue().getParameters().entrySet().iterator() : Collections.emptyIterator();
          }
        } while (index < batchRowCount);
        executeQuery(batchQueryText, params);
      }
    };
    insertInBatch("\"SD_PARAMS\"", 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