如何在hdfs中识别新文件

hgncfbus  于 2021-05-30  发布在  Hadoop
关注(0)|答案(2)|浏览(355)

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

brjng4g3

brjng4g31#

要做到这一点,您需要编写一个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.

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

m1m5dgzv

m1m5dgzv2#

如果它是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

相关问题