2016-09-30 85 views
0

我是hadoop和mapreduce的新手,我正在嘗試編寫一個mapreduce來計算一個字數txt文件的前10位數字。Hadoop Streaming簡單作業失敗錯誤python

我的txt文件 'q2_result.txt' 的樣子:

yourself  268 
yourselves  73 
yoursnot  1 
youst 1 
youth 270 
youthat 1 
youthful  31 
youths 9 
youtli 1 
youwell 1 
youwondrous  1 
youyou 1 
zanies 1 
zany 1 
zeal 32 
zealous 6 
zeals 1 

映射:

#!/usr/bin/env python 

import sys 

for line in sys.stdin: 
    line = line.strip() 
    word, count = line.split() 
    print "%s\t%s" % (word, count) 

減速機:

#!usr/bin/env/ python 

import sys 

top_n = 0 
for line in sys.stdin: 
    line = line.strip() 
    word, count = line.split() 

    top_n += 1 
    if top_n == 11: 
     break 
    print '%s\t%s' % (word, count) 

我知道你可以通過一個標誌-D選項在Hadoop的jar命令,所以它對你想要的鍵進行排序(在我的情況下,計數是k2,2),在這裏我只是使用一個簡單的命令冷杉T:

hadoop jar /usr/hdp/2.5.0.0-1245/hadoop-mapreduce/hadoop-streaming-2.7.3.2.5.0.0-1245.jar -file /root/LAB3/mapper.py -mapper mapper.py -file /root/LAB3/reducer.py -reducer reducer.py -input /user/root/lab3/q2_result.txt -output /user/root/lab3/test_out 

因此,我認爲這種簡單的映射,與減速機不應該給我的錯誤,但它確實和我想不通爲什麼,這裏的錯誤:http://pastebin.com/PvY4d89c

(我使用的Horton在Ubuntu16.04上的VirtualBox上運行HDP Sandbox)

+0

請檢查了這一點http://stackoverflow.com/questions/4339788/hadoop-streaming-無法找到文件錯誤 – Rahmath

回答

0

我知道,「文件未找到錯誤」表示與「文件無法執行」完全不同的東西,在這種情況下,問題在於文件無法執行。

在Reducer.py:

錯誤:

#!usr/bin/env/ python 

正確:

#!/usr/bin/env python 
+0

我不能相信我錯過了...,你能解釋爲什麼這種差異會導致hadoop流媒體錯誤?我有點理解包括#!告訴hadoop你正在執行python文件。 – Sam

+1

env是位於/ usr/bin中的程序。編寫'usr/bin/env /'實際上你正在運行一個目錄。這個程序允許你使用python而不使用絕對路徑。使用#!你正在告訴哪個程序執行腳本,它必須存在並且可以運行。 – ozw1z5rd