- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我使用 spark 1.3.1 和 Python 2.7
这是我第一次使用 Spark Streaming。
我尝试使用 spark 流从文件中读取数据的代码示例。
这是示例链接: https://github.com/apache/spark/blob/master/examples/src/main/python/streaming/hdfs_wordcount.py
我的代码如下:
conf = (SparkConf()
.setMaster("本地")
.setAppName("我的应用程序")
.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(λ x: (x, 1))\
.reduceByKey(lambda a, b: a+b)
计数.pprint()
ssc.start()
ssc.awaitTermination()
2.txt文件内容如下:
a1 b1 c1 d1 e1 f1 g1a2 b2 c2 d2 e2 f2 g2a3 b3 c3 d3 e3 f3 g3
我希望与文件内容相关的内容会出现在控制台中,但什么也没有。除了每秒这样的文本之外,什么都没有:
-------------------------------------------Time: 2015-09-03 15:08:18-------------------------------------------
和 Spark 的日志。
我做错了什么吗?否则为什么它不起作用?
最佳答案
我遇到了类似的问题,但我意识到,一旦我设置了 Streaming 运行,streamingcontext 就会从新文件中获取数据。一旦流式传输开始,它只会摄取新放置在源目录中的数据。
实际上,pyspark 文档非常明确:
文本文件流(目录)
Create an input stream that monitors a Hadoop-compatible file system for new files and reads them as text files. Files must be wrriten to the monitored directory by “moving” them from another location within the same file system. File names starting with . are ignored.
关于带有 textFileStream 的 Python Spark Streaming 示例不起作用。为什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32375398/
我正在尝试使用 eclipse(使用 maven conf)和 2 个 worker 执行以下代码,每个都有 2 个核心,或者也尝试使用 spark-submit。 public class Stre
我正在尝试监视 HDFS 中的存储库以读取和处理复制到它的文件中的数据(将文件从本地系统复制到 HDFS 我使用 hdfs dfs -put ),有时它会产生问题:Spark Streaming:ja
我设置了一个简单的测试来从 S3 流式传输文本文件,并在我尝试类似的操作时让它工作 val input = ssc.textFileStream("s3n://mybucket/2015/04/03/
我正在使用 Spark 流处理放置在 HDFS 中的文件。具体使用 JavaStreamingContext 类的 textFileStream 方法。 由于方法名称包含“文本”,我认为这只会读取文本
我使用 spark 1.3.1 和 Python 2.7 这是我第一次使用 Spark Streaming。 我尝试使用 spark 流从文件中读取数据的代码示例。 这是示例链接: https://g
我是 Apache Spark 和 Apache Spark 流编程的初学者, 我使用 Hadoop 连接器将 Azure 数据湖配置为 Apache Spark link它连接正确并且 我可以使用
我是一名优秀的程序员,十分优秀!