【问题标题】:How to identify new files in HDFS如何识别 HDFS 中的新文件
【发布时间】:2015-03-25 09:39:36
【问题描述】:

只是想知道是否有一种方法可以识别添加到 HDFS 路径中的新文件?例如,如果某些文件已经存在一段时间。现在我今天添加了新文件。所以只想处理那些新文件。实现这一目标的最佳方法是什么。

谢谢

【问题讨论】:

  • 更多信息:将只有一个文件夹接收文件,即每天不能在主文件夹下创建子文件夹。只需要使用文件级别信息来了解文件是否被处理

标签: hadoop mapreduce hdfs hadoop-yarn hadoop2


【解决方案1】:

您需要编写一个 java 代码来执行此操作。这些步骤可能会有所帮助:

1. Before adding new files, fetch the last modified time (hadoop fs -ls /your-path). Lets say it as mTime.
2. Next upload new files into hdfs path
3. Now filter the files that are greater than mTime. These files are to be processed. Make your program to process only these files.

这只是开发代码的提示。 :)

【讨论】:

    【解决方案2】:

    如果是 Mapreduce,那么您可以每天创建附加时间戳的输出目录。

    喜欢

        FileOutputFormat.setOutputPath(job, new Path(hdfsFilePath
                + timestamp_start); // start at 12 midnight for example:  1427241600 (GMT) --you can write logic to get epoch time
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-04-06
      • 1970-01-01
      • 1970-01-01
      • 2021-11-26
      • 1970-01-01
      • 2019-06-07
      相关资源
      最近更新 更多