我正在使用 mrjob 编写 map 函数。我的输入将来自 HDFS 目录中的文件。文件名包含文件中不存在的小但重要的信息。有没有办法了解(在映射函数内)给定键值对来自的输入文件的名称?
我正在寻找与此 Java 代码等效的代码:
FileSplit fileSplit = (FileSplit)reporter.getInputSplit();
String fileName = fileSplit.getPath().getName();
提前致谢!
最佳答案
map.input.file
属性将给出输入文件名。
根据Hadoop - The Definitive Guide
The properties can be accessed from the job’s configuration, obtained in the old MapReduce API by providing an implementation of the configure() method for Mapper or Reducer, where the configuration is passed in as an argument. In the new API, these properties can be accessed from the context object passed to all methods of the Mapper or Reducer.
关于python - 如何在MRjob中获取输入文件的名称,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11434850/