hadoop - 将输出文件添加到 Mapreduce 中的现有输出目录

标签 hadoop mapreduce

我想在每次运行作业时通过在文件名末尾附加时间戳来将 MapReduce 程序的输出文件添加到同一目录。

目前我可以在文件输出文件的末尾附加时间戳,但我无法找到如何将文件添加到同一输出目录而不是每次都覆盖它。

最佳答案

您可以在临时文件夹中写入输出文件,并在作业结束后将它们移动到目标文件夹。将所有文件从一个文件夹移动到另一个文件夹的方法示例:

public static void moveFiles(Path from, Path to, Configuration conf) throws IOException {
    FileSystem fs = from.getFileSystem(conf); // get file system
    for (FileStatus status : fs.listStatus(from)) { // list all files in 'from' folder
        Path file = status.getPath(); // get path to file in 'from' folder
        Path dst = new Path(to, file.getName()); // create new file name
        fs.rename(file, dst); // move file from 'from' folder to 'to' folder
    }
}

关于hadoop - 将输出文件添加到 Mapreduce 中的现有输出目录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25622738/

相关文章:

hadoop - 容器运行超出物理内存限制

java - HBase MapReduce

hadoop - 在Shark Hive中创建连接两个现有表的表

hadoop - 多个reducer如何在Hadoop中只输出一个部分文件?

facebook - 如何将 Facebook 评论和提要拉到 hadoop?

hadoop - 在 docker swarm 外部访问 hdfs

hadoop - 如何在Apache Spark中在集群类型之间切换

java - 为什么我在 hadoop 的 mapreduce 中得到 3xx 重复项?

java - Cloudera MapReduce计数器getValue错误

amazon-web-services - 如何将 Spark jar 提交到 EMR 集群?