spark collect获取所有元素

from pyspark import SparkConf, SparkContext
conf = SparkConf().setMaster("local").setAppName("My App")
sc = SparkContext(conf = conf)
lines = sc.textFile("/var/log/syslog")
LinesError = lines.filter(lambda line: "error" in line)
LinesWarn = lines.filter(lambda line: "warn" in line)
print "----output----------------------"
print lines.count()
print LinesError.count()
print LinesWarn.count()
#通过spark的action操作函数:collect函数可以提取出所有rdd里的数据项
re = LinesWarn.collect()
i = 0
for x in re:
        print i, x
        i += 1
sc.stop()

通过spark的action操作函数:collect函数可以提取出所有rdd里的数据项!

posted @ 2016-11-06 10:03  bonelee  阅读(6776)  评论(0编辑  收藏  举报