我尝试使用Cloudera 5.5.0实现一个简单的Hadoop map reduce示例 地图&应该使用Python 2.6.6
实现reduce步骤问题:
cat join2 * .txt | ./join3_mapper.py |排序| ./join3_reducer.py
hadoop jar /usr/lib/hadoop-mapreduce/hadoop-streaming.jar -input /user/cloudera/inputTV/join2_gen*.txt -output / user / cloudera / output_tv -mapper /home/cloudera/join3_mapper.py -reducer /home/cloudera/join3_reducer.py -numReduceTasks 1
16/01/06 12:32:32 INFO mapreduce.Job: Task Id : attempt_1452069211060_0026_r_000000_0, Status : FAILED
Error: java.lang.RuntimeException: PipeMapRed.waitOutputThreads(): subprocess failed with code 1
at org.apache.hadoop.streaming.PipeMapRed.waitOutputThreads(PipeMapRed.java:325)
at org.apache.hadoop.streaming.PipeMapRed.mapRedFinished(PipeMapRed.java:538)
at org.apache.hadoop.streaming.PipeReducer.close(PipeReducer.java:134)
at org.apache.hadoop.io.IOUtils.cleanup(IOUtils.java:244)
at org.apache.hadoop.mapred.ReduceTask.runOldReducer(ReduceTask.java:459)
at org.apache.hadoop.mapred.ReduceTask.run(ReduceTask.java:392)
at org.apache.hadoop.mapred.YarnChild$2.run(YarnChild.java:163)
at java.security.AccessController.doPrivileged(Native Method)
at javax.security.auth.Subject.doAs(Subject.java:415)
at org.apache.hadoop.security.UserGroupInformation.doAs(UserGroupInformation.java:1671)
at org.apache.hadoop.mapred.YarnChild.main(YarnChild.java:158)
如果使用-numReduceTasks 0执行hadoop命令,映射器可以工作 hadoop作业只执行map步骤,成功结束,输出目录包含map步骤中的结果文件。
我猜缩小步骤肯定有问题吗?
日志上传时间:Wed Jan 06 12:33:10 -0800 2016 记录长度:222 log4j:WARN找不到logger(org.apache.hadoop.ipc.Server)的appender。 log4j:WARN请正确初始化log4j系统。 log4j:WARN有关详细信息,请参阅http://logging.apache.org/log4j/1.2/faq.html#noconfig。
脚本代码: 第一个文件:join3_mapper.py
#!/usr/bin/env python
import sys
for line in sys.stdin:
line = line.strip() #strip out carriage return
tuple2 = line.split(",") #split line, into key and value, returns a list
if len(tuple2) == 2:
key = tuple2[0]
value = tuple2[1]
if value == 'ABC':
print('%s\t%s' % (key, value) )
elif value.isdigit():
print('%s\t%s' % (key, value) )
第二个文件:join3_reducer.py
#!/usr/bin/env python
import sys
last_key = None #initialize these variables
running_total = 0
abcFound =False;
this_key = None
# -----------------------------------
# Loop the file
# --------------------------------
for input_line in sys.stdin:
input_line = input_line.strip()
# --------------------------------
# Get Next Key value pair, splitting at tab
# --------------------------------
tuple2 = input_line.split("\t")
this_key = tuple2[0]
value = tuple2[1]
if value.isdigit():
value = int(value)
# ---------------------------------
# Key Check part
# if this current key is same
# as the last one Consolidate
# otherwise Emit
# ---------------------------------
if last_key == this_key:
if value == 'ABC': # filter for only ABC in TV shows
abcFound=True;
else:
if isinstance(value, (int,long) ):
running_total += value
else:
if last_key: #if this key is different from last key, and the previous
# (ie last) key is not empy,
# then output
# the previous <key running-count>
if abcFound:
print('%s\t%s' % (last_key, running_total) )
abcFound=False;
running_total = value #reset values
last_key = this_key
if last_key == this_key:
print('%s\t%s' % (last_key, running_total) )
我尝试过各种不同的方式将输入文件声明为hadoop命令,没有区别,没有成功。
我做错了什么?提示,想法非常感谢谢谢
答案 0 :(得分:1)
这是多么幸运的一击,与那个人打了好几天,并且知道我让它运转起来了:
自本地(unix)执行
cat join2_gen*.txt | ./join2_mapper.py | sort | ./join2_reducer.py
工作正常我有想法使用1个合并的输入文件,而不是提供的6个输入文件,所以:
cat join2_gen*.txt >> mergedinputFile.txt
hdfs dfs -put mergedInputFile.txt /user/cloudera/input
然后再次执行相同的hadoop命令,将输入定向到输入文件夹中的mergedInputFile - &gt; 完美的结果,没问题,没有异常工作完成。
对我而言,它提出了一个问题:
答案 1 :(得分:1)
尝试将所有输入文本文件放在一个目录中,然后将目录作为输入传递。这样您就不必合并所有输入文件