在Python中是否可以广播RDD?
我正在阅读《Spark高级分析:大规模数据学习模式》一书,第三章需要广播一个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() 得到的映射版本。
谢谢!