【HADOOP】hadoop streaming指定不执行reducer过程

有时候,我们只需要对文件做并发处理,并不关心相同key的记录间的关系。

这时,只需要map函数处理输入数据。

如果不指定reducer选项,系统仍然会默认执行一次cat命令。

如何去了不必要的分桶排序操作呢?

方法一:

把mapred.reduce.tasks设置为零,Map/reduce框架就不会创建reducer任务,mapper任务的输出就是整个作业的最终输出。


方法二:

“-reduce None”选项,它与“-jobconf mapred.reduce.tasks=0”等价。



  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
基于Hadoop Streaming进行MapReduce实践需要遵循以下步骤: 1. 编写Mapper和Reducer代码,将其保存为可执行文件或脚本。Mapper和Reducer可以使用任何编程语言,只要它们可以在命令行上运行即可。 2. 在Hadoop集群上启动Hadoop Streaming作业,并指定Mapper和Reducer的可执行文件或脚本路径。 3. 将输入数据上传到HDFS中,并指定输入路径作为Hadoop Streaming作业的输入。 4. 指定输出路径作为Hadoop Streaming作业的输出。 5. 启动Hadoop Streaming作业,并等待作业完成。 下面是一个简单的示例,展示如何使用Hadoop Streaming进行单词计数: 1. 编写Mapper代码,将其保存为Python脚本: ```python #!/usr/bin/env python import sys for line in sys.stdin: line = line.strip() words = line.split() for word in words: print(word + '\t' + '1') ``` 2. 编写Reducer代码,将其保存为Python脚本: ```python #!/usr/bin/env python import sys current_word = None current_count = 0 word = None for line in sys.stdin: line = line.strip() word, count = line.split('\t', 1) count = int(count) if current_word == word: current_count += count else: if current_word: print(current_word + '\t' + str(current_count)) current_count = count current_word = word if current_word == word: print(current_word + '\t' + str(current_count)) ``` 3. 将Mapper和Reducer保存为可执行文件,并上传到HDFS中。 4. 将输入数据上传到HDFS中,例如: ```bash $ hadoop fs -put input.txt /input ``` 5. 启动Hadoop Streaming作业: ```bash $ hadoop jar $HADOOP_HOME/share/hadoop/tools/lib/hadoop-streaming-2.7.3.jar \ -file mapper.py -mapper mapper.py \ -file reducer.py -reducer reducer.py \ -input /input -output /output ``` 在这个命令中,我们指定Mapper和Reducer的Python脚本路径,以及输入和输出路径。Hadoop Streaming会自动将输入数据分割成小块,并将它们分配给Mapper进行处理Mapper将每个单词映射到一个计数器,并将其发送到Reducer进行聚合。最终结果被写入到输出路径中。 6. 查看输出结果: ```bash $ hadoop fs -cat /output/* ``` 这将显示单词和它们的计数器,例如: ```text hello 2 world 1 ``` 这就是基于Hadoop Streaming进行MapReduce实践的基本步骤。你可以使用不同的编程语言和算法来解决不同的问题。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值