我正在尝试为谷歌图书的ngrams构建一个mapreduce作业。我的映射器在本地测试时工作正常,但化简器不返回任何值。减速器如下所示:
#! /usr/bin/env python
import sys
current_word = ''
word_in_progress = ''
target_year_count = 0
prior_year_count = 0
target_year = 1999
for line in sys.stdin:
line = line.strip().split('t')
if len(line) !=3:
continue
current_word, year, occurances = line
if current_word != word_in_progress:
if target_year_count > 0:
if prior_year_count ==0:
print '%st%s' % (word_in_progress, target_year_count)
try:
year = int(year)
except ValueError:
continue
try:
occurances = int(occurances)
except ValueError:
continue
if year == target_year:
target_year_count += occurances
if year < target_year:
prior_year_count += occurances
print '%st%s' % (word_in_progress, target_year_count)
if target_year_count > 0:
if prior_year_count ==0:
print '%st%s' % (word_in_progress, target_year_count)
当我在 Ubuntu 命令行中键入以下命令时:
hduser@bharti-desktop:~/hadoop$ cat /home/hduser/Documents/test1.1.txt | /home/hduser /hadoop/mapper-ngram.py | sort -k1,1 | /home/hduser/hadoop/reducerngram1.py| sort -k2,2n
我一无所获。有人可以告诉我我做错了什么吗?
我要检查的第一件事:
cat /home/hduser/Documents/test1.1.txt | /home/hduser /hadoop/mapper-ngram.py | sort -k1,1 | /home/hduser/hadoop/reducerngram1.py| sort -k2,2n
^ # Is this space a typo?
这个空间是你帖子中的错字,还是你真的以这种方式运行命令? 如果这是您的命令的准确表示,我猜输入实际上并没有到达您的映射器(因此不会到达您的化简器(。