【发布时间】:2017-05-27 12:05:48
【问题描述】:
是否可以在 Python 中广播 RDD?
我正在关注“使用 Spark 进行高级分析:从大规模数据中学习的模式”一书,在第 3 章中需要广播 RDD。我正在尝试使用 Python 而不是 Scala 来遵循示例。
无论如何,即使是这个简单的例子,我也有一个错误:
my_list = ["a", "d", "c", "b"]
my_list_rdd = sc.parallelize(my_list)
sc.broadcast(my_list_rdd)
错误是:
"It appears that you are attempting to broadcast an RDD or reference an RDD from an "
Exception: It appears that you are attempting to broadcast an RDD or reference an RDD from an
action or transformation. RDD transformations and actions can only be invoked by the driver, n
ot inside of other transformations; for example, rdd1.map(lambda x: rdd2.values.count() * x) i
s invalid because the values transformation and count action cannot be performed inside of the
rdd1.map transformation. For more information, see SPARK-5063.
我真的不明白错误所指的“动作或转换”是什么。
我正在使用spark-2.1.1-hadoop2.7。
重要编辑:这本书是正确的。我只是没有读到它不是正在广播的 RDD,而是使用 collectAsMap() 获得的地图版本。
谢谢!
【问题讨论】:
标签: python-3.x apache-spark pyspark