相关疑难解决方法(0)

pyspark 中的转换 DStream 在调用 pprint 时出错

我正在通过 PySpark 探索 Spark Streaming,当我尝试将transform函数与take.

我可以成功地使用sortByDStreamtransformpprint结果。

author_counts_sorted_dstream = author_counts_dstream.transform\
  (lambda foo:foo\
   .sortBy(lambda x:x[0].lower())\
   .sortBy(lambda x:x[1],ascending=False))
author_counts_sorted_dstream.pprint()
Run Code Online (Sandbox Code Playgroud)

但是如果我使用take以下相同的模式并尝试pprint它:

top_five = author_counts_sorted_dstream.transform\
  (lambda rdd:rdd.take(5))
top_five.pprint()
Run Code Online (Sandbox Code Playgroud)

工作失败

Py4JJavaError: An error occurred while calling o25.awaitTermination.
: org.apache.spark.SparkException: An exception was raised by Python:
Traceback (most recent call last):
  File "/usr/local/spark/python/pyspark/streaming/util.py", line 67, in call
    return r._jrdd
AttributeError: 'list' object has no attribute '_jrdd'
Run Code Online (Sandbox Code Playgroud)

您可以在此处查看笔记本中的完整代码和输出。

我究竟做错了什么?

apache-spark spark-streaming dstream pyspark

4
推荐指数
1
解决办法
3261
查看次数

标签 统计

apache-spark ×1

dstream ×1

pyspark ×1

spark-streaming ×1