hdfs-dfs-getmerge命令做什么?

6kkfgxo0  于 2021-06-04  发布在  Hadoop
关注(0)|答案(2)|浏览(496)

作为一个配置单元查询的结果,我得到了多个输出文件(按排序方式分发),现在我想合并它们以生成单个文件。所以我尝试了hdfs-dfs-getmerge命令。现在我想了解-getmerge是在连接之前对文件进行排序,还是只是连接?

zmeyuzjn

zmeyuzjn1#

以下是文档(针对hadoop 2.7.1):https://hadoop.apache.org/docs/r2.7.1/hadoop-project-dist/hadoop-common/filesystemshell.html#getmerge
基本上:1-将文件连接到一个2-可以在连接的文件之间插入新行(-nl)。
例如:$hadoop fs-getmerge[-nl]src1[src2[src3]]

bxjv4tth

bxjv4tth2#

  1. public static boolean More ...copyMerge(FileSystem srcFS, Path srcDir,
  2. 277 FileSystem dstFS, Path dstFile,
  3. 278 boolean deleteSource,
  4. 279 Configuration conf, String addString) throws IOException {
  5. 280 dstFile = checkDest(srcDir.getName(), dstFS, dstFile, false);
  6. 281
  7. 282 if (!srcFS.getFileStatus(srcDir).isDirectory())
  8. 283 return false;
  9. 284
  10. 285 OutputStream out = dstFS.create(dstFile);
  11. 286
  12. 287 try {
  13. 288 FileStatus contents[] = srcFS.listStatus(srcDir);
  14. 289 Arrays.sort(contents);
  15. 290 for (int i = 0; i < contents.length; i++) {
  16. 291 if (contents[i].isFile()) {
  17. 292 InputStream in = srcFS.open(contents[i].getPath());
  18. 293 try {
  19. 294 IOUtils.copyBytes(in, out, conf, false);
  20. 295 if (addString!=null)
  21. 296 out.write(addString.getBytes("UTF-8"));
  22. 297
  23. 298 } finally {
  24. 299 in.close();
  25. 300 }
  26. 301 }
  27. 302 }
  28. 303 } finally {
  29. 304 out.close();
  30. 305 }
  31. 306
  32. 307
  33. 308 if (deleteSource) {
  34. 309 return srcFS.delete(srcDir, true);
  35. 310 } else {
  36. 311 return true;
  37. 312 }
  38. 313 }

它对文件数组进行排序(默认升序),源代码hadoop 0.23

展开查看全部

相关问题