ImportError: cannot import name 'HiveContext' from 'pyspark.sql'

ImportError: cannot import name 'HiveContext' from 'pyspark.sql'

我的 PC 中 运行 pyspark (windows 10) 但我无法导入 HiveContext:

from pyspark.sql import HiveContext
---------------------------------------------------------------------------
ImportError                               Traceback (most recent call last)
<ipython-input-25-e3ae767de910> in <module>
----> 1 from pyspark.sql import HiveContext

ImportError: cannot import name 'HiveContext' from 'pyspark.sql' (C:\spark\spark-3.0.0-preview-bin-hadoop2.7\python\pyspark\sql\__init__.py)

我该如何着手解决?

您正在使用 Spark 3.0 的预览版。根据release notes,你应该使用SparkSession.builder.enableHiveSupport().

In Spark 3.0, the deprecated HiveContext class has been removed. Use SparkSession.builder.enableHiveSupport() instead.