所有操作,假定hadoop集群已经正常部署。
Python源码
mapper.py
#!/usr/bin python
import sys
# input comes from STDIN (standard input)
for line in sys.stdin:
line = line.strip()
words = line.split()
for word in words:
print '%s\\t%s' % (word, 1)
reduce.py
#!/usr/bin python
from operator import itemgetter
import sys
word2count = {}
# input comes from STDIN
for line in sys.stdin:
line = line.strip()
word, count = line.split('\\t', 1)
try:
count = int(count)
word2count[word] = word2count.get(word, 0) + count
except ValueError:
# count was not a number, so silently
# ignore/discard this line
pass
sorted_word2count = sorted(word2count.items(), key=itemgetter(0))
for word, count in sorted_word2count:
print '%s\\t%s'% (word, count)
先后存储在/home/src下,然后,cd到此目录
在hdfs上建立测试目录:
ls
hadoop fs -ls /user/hdfs
mkdir
hadoop fs -mkdir /user/hdfs/test
从本地磁盘copy测试文件到hdfs
hadoop fs -copuFromLocal /home/src/*.txt /user/hdfs/test/
使用streaming.jar执行mapreduce任务
hadoop jar /usr/lib/hadoop-mapreduce/hadoop-streaming.jar -mapper mapper.py -reducer reducer.py -file mapper.py -file reducer.py -input /user/hdfs/test/* -output /user/hdfs/test/reducer -mapper cat -reducer aggregate
执行结果:
......
14/11/26 12:54:52 INFO mapreduce.Job: map 0% reduce 0%
14/11/26 12:54:59 INFO mapreduce.Job: map 100% reduce 0%
14/11/26 12:55:04 INFO mapreduce.Job: map 100% reduce 100%
14/11/26 12:55:04 INFO mapreduce.Job: Job job_1415798121952_0179 completed successfully
......
14/11/26 12:55:04 INFO streaming.StreamJob: Output directory: /user/hdfs/test/reducer
......
查看执行结果集文件
hadoop fs -ls /user/hdfs/test
......
drwxr-xr-x - root Hadoop 0 2014-11-26 12:55 /user/hdfs/test/reducer
......
分享到:
相关推荐
python实现mapreduce词频统计 执行方式:打开cmd命令,cd到代码所在文件夹,输入python wordcout_map.py > words.txt | sort | python wordcout_reduce.py执行
使用hadoop-streaming运行Python编写的MapReduce程序.rar
Python执行MapReduce测试,python编写map和reduce程序,并验证测试
Python手撕算法MapReduce_and_filter
使用Python开发mapreduce的简单demo的代码,大家可以将代码放到环境中,然后修改具run.sh里面的路径执行就好。
Hadoop和Python的Mapreduce 关于如何使用Python和Hadoop执行MapReduce的一小段回购。 映射器和化简器都是用Python编写的。 有关如何在Hadoop中实现这两个脚本的教程位于。
使用python写微博关注者之间,相似度最高的十个用户的mapreduce,代码有点粗糙,主要是给大家提供思路的,不同的问题是需要修改的。
本代码主要利用Python工具实现大数据与MapReduce,简单明了,易于理解
高分毕业设计 基于Python爬虫+MapReduce分析的招聘信息大数据可视化系统源码+部署文档+全部数据资料高分毕业设计 基于Python爬虫+MapReduce分析的招聘信息大数据可视化系统源码+部署文档+全部数据资料 【备注】 1、...
dpark, 在 python 中,Spark的python 克隆,一个MapReduce相似的框架 DPark DPark是Spark的python 克隆,类似于支持迭代计算的MapReduce(R) 计算框架。单词计数( wc.py )的示例:import dparkfile = dpark.textFi
Mapreduce-1:python中的MapReduce的孙子/祖父母对
利用hadoop-streaming框架运行python脚本指令
使用python实现MapReduce的wordcount实例
Python实现MapReduce的WordCount(hadoop平台)在进行大数据处理时,JAVA程序用的较多,但是,想要把深度学习算法用到MapReduce中,Python是深度学习和数据挖掘处理数据较为容易的语言,所以基于以上考虑,本文介绍...
可以作为大数据预处理的MapReduce代码的参考!!! -执行脚本文件: cd /home/hadoop/logfiles/ source format_run_2013_o5_30.sh source format_run_2013_o5_31.sh 执行我们的脚本文件,可以用source或者./
dpark:Spark的Python克隆,Python中的MapReduce相似框架
#PapJuice 通过 Python Goggles 实现 MapReduce灵感学习和实践 MapReduce(基于 Hadoop)和 MultiProcessing 的概念。计划我们将分两个阶段解决这个问题: 创建单进程解决方案。 将其转换为多进程。 步骤 1 确保我们...
Python MapReduce Python中MapReduce的多进程实现关于Google的MapReduce框架通过并行提供集群计算的编程抽象来支持Hadoop第一个版本。 但是,这种抽象也可以在单台计算机上的多处理上下文中使用。 该存储库是多进程...
mrjob:在 Hadoop 或Amazon Web Services上运行MapReduce 作业
Big Data, MapReduce, Hadoop, and Spark with Python: Master Big Data Analytics and Data Wrangling with MapReduce Fundamentals using Hadoop, Spark, and Python by LazyProgrammer English | 15 Aug 2016 | ...