gpt4 book ai didi

python - 如何让我的 Hadoop python 映射器工作?

转载 作者:可可西里 更新时间:2023-11-01 14:58:22 25 4
gpt4 key购买 nike

我想尝试为 Hadoop MapReduce 编写 python 映射器函数(作为一个完全的初学者)。我已经尝试了下面的代码,虽然它运行它返回“终止-步骤完成但有错误”。我使用了默认的聚合缩减函数。

import sys

keywords = ["bear", "bears"]
for line in sys.stin:
words = line.split()
for key in keywords:
if key in words[1:]:
ans = words[words.index(key)-1]
print("%s\t%d" % (ans, 1))

(提前致谢)

最佳答案

for line in sys.stin:

应该是

for line in sys.stdin:

一般来说,您应该在 hadoop map-reduce 上运行脚本之前测试它:

cat test_file.txt | python your_mapper.py | sort | python your_reducer.py

然后你就会看到 AttributeError。

关于python - 如何让我的 Hadoop python 映射器工作?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30008288/

25 4 0
文章推荐: hadoop - 什么是适合我索引和处理大数据的工具?
文章推荐: css - 三列