【发布时间】:2016-04-06 04:30:15
【问题描述】:
我正在尝试预处理 XML 文件以在放入 mapreduce 之前提取某些节点。我有以下代码:
from mrjob.compat import jobconf_from_env
from mrjob.job import MRJob
from mrjob.util import cmd_line, bash_wrap
class MRCountLinesByFile(MRJob):
def configure_options(self):
super(MRCountLinesByFile, self).configure_options()
self.add_file_option('--filter')
def mapper_cmd(self):
cmd = cmd_line([self.options.filter, jobconf_from_env('mapreduce.map.input.file'])
return cmd
if __name__ == '__main__':
MRCountLinesByFile.run()
然后在命令行中输入:
python3 test_job_conf.py --filter ./filter.py -r local < test.txt
test.txt 是一个普通的 XML 文件,例如 here。而filter.py 是一个查找所有标题信息的脚本。
但是,我收到以下错误:
Creating temp directory /tmp/test_job_conf.vagrant.20160406.042648.689625
Running step 1 of 1...
Traceback (most recent call last):
File "./filter.py", line 8, in <module>
with open(filename) as f:
FileNotFoundError: [Errno 2] No such file or directory: 'None'
Step 1 of 1 failed: Command '['./filter.py', 'None']' returned non-zero exit status 1
在这种情况下,它看起来像 mapreduce.map.input.file 渲染 None。如何让mapper_cmd 函数读取mrjob 当前正在读取的文件?
【问题讨论】:
标签: python hadoop mrjob bigdata