private void insertColumnV2InBatch(Map<Long, MColumnDescriptor> cdIdToColumnDescriptor) throws MetaException {
    int rowCount = 0;
    for (MColumnDescriptor cd : cdIdToColumnDescriptor.values()) {
      rowCount += cd.getCols().size();
    }
    if (rowCount == 0) {
      return;
    }
    String columns = "(\"CD_ID\",\"COMMENT\",\"COLUMN_NAME\",\"TYPE_NAME\",\"INTEGER_IDX\")";
    int columnCount = 5;
    BatchExecutionContext batchExecutionContext = new BatchExecutionContext() {
      int colIndex = 0;
      final Iterator<Map.Entry<Long, MColumnDescriptor>> cdIt = cdIdToColumnDescriptor.entrySet().iterator();
      Map.Entry<Long, MColumnDescriptor> cdEntry = cdIt.next();
      Iterator<MFieldSchema> it = cdEntry.getValue().getCols().iterator();
      @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()) {
            MFieldSchema fieldSchema = it.next();
            params[paramIndex++] = cdEntry.getKey();
            params[paramIndex++] = fieldSchema.getComment();
            params[paramIndex++] = fieldSchema.getName();
            params[paramIndex++] = fieldSchema.getType();
            params[paramIndex++] = colIndex++;
            index++;
          }
          if (index < batchRowCount) {
            colIndex = 0;
            cdEntry = cdIt.next(); // cdIt.next() cannot be null since it is within the row count
            it = cdEntry.getValue().getCols().iterator();
          }
        } while (index < batchRowCount);
        executeQuery(batchQueryText, params);
      }
    };
    insertInBatch("\"COLUMNS_V2\"", 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