【问题标题】:Why is pySpark failing to run udf functions only?为什么 pySpark 无法仅运行 udf 函数?
【发布时间】:2019-10-02 07:14:34
【问题描述】:

我在 EC2 机器上设置了 pyspark,有 2 个节点。我正在使用命令运行 pyspark

 pyspark --master spark://10.0.1.13:7077 --driver-memory 5G --executor-memory 12G --total-executor-cores 10

我的 python 脚本仅在运行 UDF 函数时失败。我无法调试为什么只有 udf 而不是脚本的任何其他部分,或者为什么不能调试完整的脚本?

路径:

(base) [ec2-user@ip-10-0-1-13 ~]$ which pyspark
~/anaconda2/bin/pyspark
(base) [ec2-user@ip-10-0-1-13 ~]$ which python
~/anaconda2/bin/python

Python 脚本:

def getDateObjectYear(dateString):
    dateString=dateString.strip()
    return dateString

dateObjectUDFYear = udf(getDateObjectYear)

checkin_date_yelp_df=checkin_date_yelp_df.withColumn('year', dateObjectUDFYear(checkin_date_yelp_df.date))

在运行checkin_date_yelp_df.show(5) '我得到这个错误

Py4JJavaError: An error occurred while calling o98.showString.
: org.apache.spark.SparkException: Job aborted due to stage failure: Task 0 in stage 14.0 failed 4 times, most recent failure: Lost task 0.3 in stage 14.0 (TID 230, 10.0.1.13, executor 0): java.io.IOException: Cannot run program "~/anaconda2/bin/python": error=2, No such file or directory
..
..
..
..
Caused by: java.io.IOException: error=2, No such file or directory
    at java.lang.UNIXProcess.forkAndExec(Native Method)
    at java.lang.UNIXProcess.<init>(UNIXProcess.java:247)
    at java.lang.ProcessImpl.start(ProcessImpl.java:134)
at java.lang.ProcessBuilder.start(ProcessBuilder.java:1029)

【问题讨论】:

  • 你能不能在本地[*]模式下运行这段代码并检查问题是否仍然存在。
  • 是的,刚刚尝试过。同样的错误

标签: python apache-spark pyspark apache-spark-sql user-defined-functions


【解决方案1】:

原来我在.bashrc 中错误配置了 2 个路径

正确方法:

export PYTHONPATH=/home/ec2-user/anaconda/bin/python
export PYSPARK_PYTHON=/home/ec2-user/anaconda/bin/python

【讨论】:

    猜你喜欢
    • 2021-09-30
    • 2020-10-06
    • 2021-06-11
    • 2019-11-15
    • 1970-01-01
    • 1970-01-01
    • 2021-08-18
    • 1970-01-01
    • 2013-11-21
    相关资源
    最近更新 更多