pyspark.sql.functions.udf 可以将 .py 模块分发到工作节点吗?
Can pyspark.sql.functions.udf distribute a .py module to the worker nodes?
我使用 pyspark.sql.functions.udf
定义一个 UDF,它使用从我编写的 .py 模块导入的 class。
from czech_simple_stemmer import CzechSimpleStemmer #this is my class in my module
from pyspark.sql.functions import udf
from pyspark.sql.types import StringType
...some code here...
def clean_one_raw_doc(my_raw_doc):
... calls something from CzechSimpleStemmer ...
udf_clean_one_raw_doc = udf(clean_one_raw_doc, StringType())
当我打电话时
df = spark.sql("SELECT * FROM mytable").withColumn("output_text", udf_clean_one_raw_doc("input_text"))
我收到一条典型的巨大错误消息,其中可能是相关部分:
File "/data2/hadoop/yarn/local/usercache/ja063930/appcache/application_1472572954011_132777/container_e23_1472572954011_132777_01_000003/pyspark.zip/pyspark/serializers.py", line 431, in loads
return pickle.loads(obj, encoding=encoding)
ImportError: No module named 'czech_simple_stemmer'
我是否正确理解 pyspark 将 udf_clean_one_raw_doc
分配给所有工作节点,但 czech_simple_stemmer.py
在节点的 python 安装中丢失(仅存在于边缘节点上)我在哪里 运行 火花驱动程序)?
如果是,有什么方法可以告诉 pyspark 也分发此模块吗?我想我可能可以手动复制 czech_simple_stemmer.py
到所有节点的 pythons 但 1) 我没有节点的管理员访问权限,以及 2) 即使我请求管理员把它在那里他做了,如果我需要对模块本身做一些调整,他可能会杀了我。
来自火花提交 documentation
For Python, you can use the --py-files argument of spark-submit to add
.py, .zip or .egg files to be distributed with your application. If
you depend on multiple Python files we recommend packaging them into a
.zip or .egg.
SparkContext.addPyFile("my_module.py") 会做到的。
我使用 pyspark.sql.functions.udf
定义一个 UDF,它使用从我编写的 .py 模块导入的 class。
from czech_simple_stemmer import CzechSimpleStemmer #this is my class in my module
from pyspark.sql.functions import udf
from pyspark.sql.types import StringType
...some code here...
def clean_one_raw_doc(my_raw_doc):
... calls something from CzechSimpleStemmer ...
udf_clean_one_raw_doc = udf(clean_one_raw_doc, StringType())
当我打电话时
df = spark.sql("SELECT * FROM mytable").withColumn("output_text", udf_clean_one_raw_doc("input_text"))
我收到一条典型的巨大错误消息,其中可能是相关部分:
File "/data2/hadoop/yarn/local/usercache/ja063930/appcache/application_1472572954011_132777/container_e23_1472572954011_132777_01_000003/pyspark.zip/pyspark/serializers.py", line 431, in loads
return pickle.loads(obj, encoding=encoding)
ImportError: No module named 'czech_simple_stemmer'
我是否正确理解 pyspark 将 udf_clean_one_raw_doc
分配给所有工作节点,但 czech_simple_stemmer.py
在节点的 python 安装中丢失(仅存在于边缘节点上)我在哪里 运行 火花驱动程序)?
如果是,有什么方法可以告诉 pyspark 也分发此模块吗?我想我可能可以手动复制 czech_simple_stemmer.py
到所有节点的 pythons 但 1) 我没有节点的管理员访问权限,以及 2) 即使我请求管理员把它在那里他做了,如果我需要对模块本身做一些调整,他可能会杀了我。
来自火花提交 documentation
For Python, you can use the --py-files argument of spark-submit to add .py, .zip or .egg files to be distributed with your application. If you depend on multiple Python files we recommend packaging them into a .zip or .egg.
SparkContext.addPyFile("my_module.py") 会做到的。