使用“--py-files”参数将 PySpark 作业提交到集群

Submit a PySpark job to a cluster with the '--py-files' argument

我试图提交一个作业,其中包含要使用的 python 文件的 zip 的 GCS uri(通过 --py-files 参数)和 python 文件名PY_FILE 参数值。 这似乎没有用。我是否需要为 PY_FILE 值提供一些相对路径? PY_FILE 也包含在 zip 中。 例如在

gcloud beta dataproc jobs submit pyspark  --cluster clustername --py-files gcsuriofzip PY_FILE    

PY_FILE 的值应该是多少?

这是个好问题。为了回答这个问题,我将使用 PySpark wordcount example

在这种情况下,我创建了两个文件,一个名为 test.py 的文件是我要执行的文件,另一个名为 wordcount.py.zip 的文件是一个包含 modified wordcount.py 旨在模仿我要调用的模块的文件。

我的 test.py 文件如下所示:

import wordcount
import sys
if __name__ == "__main__":
    wordcount.wctest(sys.argv[1])

我修改了 wordcount.py 文件以删除主要方法并添加一个命名方法:

...
from pyspark import SparkContext

...
def wctest(path):
    sc = SparkContext(appName="PythonWordCount")
...

我可以使用以下 gcloud 命令在 Dataproc 上调用所有内容:

gcloud beta dataproc jobs submit pyspark  --cluster <cluster-name> \
--py-files gs://<bucket>/wordcount.py.zip gs://<bucket>/test.py \ 
gs://<bucket>/input/input.txt

在此示例中,<bucket> 是我的存储桶的名称(或路径),<cluster-name> 是我的 Dataproc 集群的名称。