【问题标题】:Why does pyspark fail with "Error while instantiating 'org.apache.spark.sql.hive.HiveSessionStateBuilder'"?为什么 pyspark 失败并显示“实例化 'org.apache.spark.sql.hive.HiveSessionStateBuilder' 时出错”?
【发布时间】:2021-02-10 04:03:13
【问题描述】:

对于我的生活,我无法弄清楚我的 PySpark 安装有什么问题。我已经安装了所有依赖项,包括 Hadoop,但 PySpark 找不到它——我的诊断正确吗?

查看下面的完整错误消息,但它最终在 PySpark SQL 上失败

pyspark.sql.utils.IllegalArgumentException: u"Error while instantiating 'org.apache.spark.sql.hive.HiveSessionStateBuilder':"

nickeleres@Nicks-MBP:~$ pyspark
Python 2.7.10 (default, Feb  7 2017, 00:08:15) 
[GCC 4.2.1 Compatible Apple LLVM 8.0.0 (clang-800.0.34)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
Using Spark's default log4j profile: org/apache/spark/log4j-defaults.properties
Setting default log level to "WARN".
To adjust logging level use sc.setLogLevel(newLevel). For SparkR, use setLogLevel(newLevel).
WARNING: An illegal reflective access operation has occurred
WARNING: Illegal reflective access by org.apache.hadoop.security.authentication.util.KerberosUtil (file:/opt/spark-2.2.0/jars/hadoop-auth-2.7.3.jar) to method sun.security.krb5.Config.getInstance()
WARNING: Please consider reporting this to the maintainers of org.apache.hadoop.security.authentication.util.KerberosUtil
WARNING: Use --illegal-access=warn to enable warnings of further illegal reflective access operations
WARNING: All illegal access operations will be denied in a future release
17/10/24 21:21:58 WARN NativeCodeLoader: Unable to load native-hadoop library for your platform... using builtin-java classes where applicable
17/10/24 21:21:59 WARN Utils: Service 'SparkUI' could not bind on port 4040. Attempting port 4041.
17/10/24 21:21:59 WARN Utils: Service 'SparkUI' could not bind on port 4041. Attempting port 4042.
17/10/24 21:21:59 WARN Utils: Service 'SparkUI' could not bind on port 4042. Attempting port 4043.
Traceback (most recent call last):
  File "/opt/spark/python/pyspark/shell.py", line 45, in <module>
    spark = SparkSession.builder\
  File "/opt/spark/python/pyspark/sql/session.py", line 179, in getOrCreate
    session._jsparkSession.sessionState().conf().setConfString(key, value)
  File "/opt/spark/python/lib/py4j-0.10.4-src.zip/py4j/java_gateway.py", line 1133, in __call__
  File "/opt/spark/python/pyspark/sql/utils.py", line 79, in deco
    raise IllegalArgumentException(s.split(': ', 1)[1], stackTrace)
pyspark.sql.utils.IllegalArgumentException: u"Error while instantiating 'org.apache.spark.sql.hive.HiveSessionStateBuilder':"
>>> 

【问题讨论】:

    标签: apache-spark pyspark


    【解决方案1】:

    tl;dr 关闭所有其他 Spark 进程并重新开始。

    以下 WARN 消息表明存在另一个进程(或多个进程)持有端口。

    我确定进程是 Spark 进程,例如pyspark 会话或 Spark 应用程序。

    17/10/24 21:21:59 WARN Utils: Service 'SparkUI' could not bind on port 4040. Attempting port 4041.
    17/10/24 21:21:59 WARN Utils: Service 'SparkUI' could not bind on port 4041. Attempting port 4042.
    17/10/24 21:21:59 WARN Utils: Service 'SparkUI' could not bind on port 4042. Attempting port 4043.
    

    这就是为什么在 Spark/pyspark 发现端口 4044 可以免费用于 Web UI 之后,它尝试实例化 HiveSessionStateBuilder 并失败了。

    pyspark 失败,因为您不能启动并运行多个使用同一本地 Hive 元存储的 Spark 应用程序。

    【讨论】:

      【解决方案2】:

      为什么会这样?

      因为我们不止一次尝试创建新会话!在 jupyter notebook 浏览器的不同选项卡上。

      解决方案:

      在 JUPYTER 笔记本的单个选项卡上开始新会话,并避免在不同的选项卡上创建新会话

      from pyspark.sql import SparkSession
      spark = SparkSession.builder.appName('EXAMPLE').getOrCreate()
      

      【讨论】:

        【解决方案3】:

        另一个可能的原因是 spark 应用程序由于没有满足最低机器要求而无法启动。

        在应用程序历史选项卡中:

        Diagnostics:Uncaught exception: org.apache.hadoop.yarn.exceptions.InvalidResourceRequestException: Invalid resource request, requested virtual cores < 0, or requested virtual cores > max configured, requestedVirtualCores=5, maxVirtualCores=4
        

        插图:

        【讨论】:

          【解决方案4】:

          我们在尝试使用 Jupyter 笔记本创建 Spark 会话时收到了同样的错误。 我们注意到,在我们的案例中,用户没有权限来触发临时目录,即针对以下 spark 属性值“spark.local.dir”使用的目录。我们更改了目录的权限,以便用户拥有对此的完全访问权限并解决了问题。通常,此目录位于 "/tmp/user" 之类的位置。

          请注意,根据spark documentation spark 暂存目录是用于 Spark 中“暂存”空间的“目录”,包括存储在磁盘上的地图输出文件和 RDD。这应该在一个快速的本地磁盘上您的系统。它也可以是不同磁盘上多个目录的逗号分隔列表。

          【讨论】:

            猜你喜欢
            • 2020-02-22
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 2021-02-17
            • 1970-01-01
            • 2021-05-08
            • 1970-01-01
            • 1970-01-01
            相关资源
            最近更新 更多