作为一个配置单元查询的结果,我得到了多个输出文件(按排序方式分发),现在我想合并它们以生成单个文件。所以我尝试了hdfs-dfs-getmerge命令。现在我想了解-getmerge是在连接之前对文件进行排序,还是只是连接?
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]]
bxjv4tth2#
public static boolean More ...copyMerge(FileSystem srcFS, Path srcDir, 277 FileSystem dstFS, Path dstFile, 278 boolean deleteSource, 279 Configuration conf, String addString) throws IOException { 280 dstFile = checkDest(srcDir.getName(), dstFS, dstFile, false); 281 282 if (!srcFS.getFileStatus(srcDir).isDirectory()) 283 return false; 284 285 OutputStream out = dstFS.create(dstFile); 286 287 try { 288 FileStatus contents[] = srcFS.listStatus(srcDir); 289 Arrays.sort(contents); 290 for (int i = 0; i < contents.length; i++) { 291 if (contents[i].isFile()) { 292 InputStream in = srcFS.open(contents[i].getPath()); 293 try { 294 IOUtils.copyBytes(in, out, conf, false); 295 if (addString!=null) 296 out.write(addString.getBytes("UTF-8")); 297 298 } finally { 299 in.close(); 300 } 301 } 302 } 303 } finally { 304 out.close(); 305 } 306 307 308 if (deleteSource) { 309 return srcFS.delete(srcDir, true); 310 } else { 311 return true; 312 } 313 }
它对文件数组进行排序(默认升序),源代码hadoop 0.23
2条答案
按热度按时间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]]
bxjv4tth2#
它对文件数组进行排序(默认升序),源代码hadoop 0.23