python - 如何在MRjob中获取输入文件的名称

标签 python hadoop hadoop-streaming mrjob

我正在使用 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/

相关文章:

python - 在 hadoop 上的一个流作业中使用多个映射器输入?

python - Hadoop MapReduce(使用 Python)在 Pandas DataFrame 上启动 KeyError

python - matplotlib:如何更改颜色、留出小空间和编辑图例

python - Python 中的正则表达式查找遵循模式 : vowel, 辅音、元音、辅音的单词

python - 如何在 CentOS 7 中将 IDLE 3.6.2 与 Python 3.6.2 关联

xml - 当我要格式化 namenode 时,我收到错误提示 org.xml.sax.SAXParseException

python - 如何在读取的 HTML 文档中翻译/转换 unicode 转义 < 和 >?

hadoop - 无法识别配置单元中的列名称或主键或外键中 'user' 'STRUCT' '<' 附近的输入

hadoop - 导入NLTK不适用于Hadoop Streaming

hadoop - 如何解决 java.lang.RuntimeException : PipeMapRed. waitOutputThreads() : subprocess failed with code 2?