public void mergeFiles(List<Reader> readers, Path outPath) throws IOException {
    Writer writer = null;
    try {
      for (Reader reader : readers) {
        if (writer == null) {
          writer = setupWriter(reader, outPath);
        }
        VectorizedRowBatch batch = reader.getSchema().createRowBatchV2();
        RecordReader rows = reader.rows();
        while (rows.nextBatch(batch)) {
          if (batch != null) {
            writer.addRowBatch(batch);
          }
        }
        rows.close();
      }
    } finally {
      if (writer != null) {
        writer.close();
      }
    }
  }
Merge orc files into a single file
@param readers list of orc file paths to be merged
@param outPath the path of output orc file
@throws IOException error happened during file operations
ql/src/java/org/apache/hadoop/hive/ql/txn/compactor/OrcFileMerger.java