gpt4 book ai didi

apache-spark - 如何删除或覆盖添加到 pyspark 作业的文件?

转载 作者:行者123 更新时间:2023-12-03 18:02:59 31 4
gpt4 key购买 nike

我通过使用向 pyspark 上下文添加了一个 egg 文件

sc.addPyFile('/path/to/my_file.egg')

但是,如果我进行了一些更改并重建了我的 egg 文件。我无法再次添加它。 Spark 说文件已经存在,我无法再次添加。这是堆栈跟踪
org.apache.spark.SparkException: File /tmp/spark-ddfc2b0f-2897-4fac-8cf3-d7ccee04700c/userFiles-44152f58-835a-4d9f-acd6-f841468fa2cb/my_file.egg exists and does not match contents of file:///path/to/my_file.egg
at org.apache.spark.util.Utils$.copyFile(Utils.scala:489)
at org.apache.spark.util.Utils$.doFetchFile(Utils.scala:595)
at org.apache.spark.util.Utils$.fetchFile(Utils.scala:394)
at org.apache.spark.SparkContext.addFile(SparkContext.scala:1409)

有没有办法告诉 Spark 覆盖它?

谢谢,

最佳答案

这可能取决于您的用例,但这并非万无一失!

spark = SparkSession.builder.appName('file_test').config("spark.files.overwrite", "true").getOrCreate()
# Adding spark.files.overwrite is actually letting Spark know that files added via sparkContext can be overwritten.
# user_file_path is where your file resides on the file system
spark.sparkContext.addPyFile(user_file_path)
# change the file and add again
spark.sparkContext.addPyFile(user_file_path)

尽管这在大多数情况下有效,但我有时会遇到这种方法的问题。我正在动态添加 Python 文件来测试一些 UDF,我需要自动生成一些 Python 方法。当我使用同一个文件覆盖内容并添加到 Spark Py 文件时,我遇到了一些问题,看起来 Spark 在传播到所有执行程序之前会进行某种内容更改检查,并且似乎存在一些问题。我通过每次内容更改时创建一个新文件来解决这个问题,它对我有用,因为我不关心我添加了多少文件。

关于apache-spark - 如何删除或覆盖添加到 pyspark 作业的文件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40515287/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com