【发布时间】:2015-11-29 06:35:38
【问题描述】:
我使用 spark 1.3.1 和 Python 2.7
这是我第一次使用 Spark Streaming。
我尝试使用火花流从文件中读取数据的代码示例。
这是示例的链接: https://github.com/apache/spark/blob/master/examples/src/main/python/streaming/hdfs_wordcount.py
我的代码如下:
conf = (SparkConf()
.setMaster("local")
.setAppName("My app")
.set("spark.executor.memory", "1g"))
sc = SparkContext(conf = conf)
ssc = StreamingContext(sc, 1)
lines = ssc.textFileStream('../inputs/2.txt')
counts = lines.flatMap(lambda line: line.split(" "))\
.map(lambda x: (x, 1))\
.reduceByKey(lambda a, b: a+b)
counts.pprint()
ssc.start()
ssc.awaitTermination()
2.txt文件内容如下:
a1 b1 c1 d1 e1 f1 g1 a2 b2 c2 d2 e2 f2 g2 a3 b3 c3 d3 e3 f3 g3我希望与文件内容相关的内容会出现在控制台中,但什么都没有。每秒都只有这样的文字:
------------------------------------------ 时间:2015-09-03 15:08:18 ------------------------------------------和 Spark 的日志。
我做错了什么吗?否则为什么它不起作用?
【问题讨论】:
标签: python apache-spark spark-streaming pyspark