Spark下使用python写wordCount
来源:互联网 发布:迅雷影音mac官方下载 编辑:程序博客网 时间:2024/06/03 12:17
安装spark就省略了,网上很多方法。
test-data.txt文件
运行程序使用spark-submit
$spark-submit /var/lib/hadoop-hdfs/spark_test/wordcount.py
查看结果
cat spark-out/part-00000
test-data.txt文件
a b caaabbbccca b ccbavi wordcount.py
#!/usr/bin/env python#-*-conding:utf-8-*-import loggingfrom operator import addfrom pyspark import SparkContextlogging.basicConfig(format='%(message)s', level=logging.INFO) #import local filetest_file_name = "file:///var/lib/hadoop-hdfs/spark_test/test-data.txt" out_file_name = "file:///var/lib/hadoop-hdfs/spark_test/spark-out"sc = SparkContext("local","wordcount app")# text_file rdd objecttext_file = sc.textFile(test_file_name)# countscounts = text_file.flatMap(lambda line: line.split(" ")).map(lambda word: (word, 1)).reduceByKey(lambda a, b: a + b)counts.saveAsTextFile(out_file_name)读取文件默认是从hdfs读取文件,也可以指定sc.textFile("路径").在路径前面加上hdfs://表示从hdfs文件系统上读
本地文件读取 sc.textFile("路径").在路径前面加上file:// 表示从本地文件系统读,如file:///home/user/spark/README.md
运行程序使用spark-submit
$spark-submit /var/lib/hadoop-hdfs/spark_test/wordcount.py
查看结果
cat spark-out/part-00000
(u'a', 3)(u'', 1)(u'c', 3)(u'b', 3)(u'aaa', 1)(u'bbb', 1)(u'ccc', 1)
参考:http://blog.csdn.net/vs412237401/article/details/51823228
0 0
- Spark下使用python写wordCount
- Spark及HDFS环境下使用python的wordcount实例
- Spark-windows 下安装和wordcount使用
- spark python wordcount
- Spark WordCount使用示例
- Spark 使用Python在pyspark中运行简单wordcount
- Spark wordcount - Python, Scala, Java
- 大数据Spark:动手写WordCount
- 【Spark大数据处理】动手写WordCount
- [Mapreduce]eclipse下写wordcount
- spark 下 wordcount 后 top k
- spark-wordcount
- Spark-wordcount
- wordcount spark...
- wordCount spark
- spark wordcount
- Spark WordCount
- spark wordcount
- [自定义控件]带有删除按钮的输入框
- HTTP通信步骤
- python requests三种带参数的请求方式
- JAVA 长度为0的数组和 null
- 关于shell的${} ## %%用法总结
- Spark下使用python写wordCount
- java Unicode 转 utf-8 汉字
- tableView右滑显示选择
- 《我的野蛮女友》
- 【NOIP模拟题】【图论】2016.11.18 第二题 心 题解
- Android 设计模式实战笔记 享元模式
- 安卓 webview ajax 跨域问题
- 【NOIP模拟题】【容斥原理】【数学归纳法】2016.11.18 第三题 题 题解
- 【OLD】在地圖上畫crosssection