0

我无法配置 Spark SQL,以便我可以访问 Spark Thrift Server 中的 Hive 表(不使用 JDBC,但本机来自 Spark)

conf/hive-site.xml我为 Spark Thrift Server 和 Spark SQL使用单个配置文件。我将javax.jdo.option.ConnectionURL属性设置为jdbc:derby:;databaseName=/home/user/spark-2.4.0-bin-hadoop2.7/metastore_db;create=true. 我还将spark.sql.warehouse.dir属性设置为指向spark-warehouse目录的绝对路径。我运行 Thrift 服务器,./start-thriftserver.sh我可以观察到嵌入式 Derby 数据库是使用metastore_db目录创建的。我可以连接beeline,创建一个表并查看spark-warehouse使用表的子目录创建的目录。所以在这个阶段它很好。

我在启用 Hive 支持的情况下启动 pyspark shell ./bin/pyspark --conf spark.sql.catalogImplementation=hive,并尝试使用以下命令访问 Hive 表:

from pyspark.sql import HiveContext
hc = HiveContext(sc)
hc.sql('show tables')

我收到如下错误:

错误 XJ040:无法使用类加载器 sun.misc.Launcher$AppClassLoader@1b4fb997 启动数据库“/home/user/spark-2.4.0-bin-hadoop2.7/metastore_db”

错误 XSDB6:另一个 Derby 实例可能已经启动了数据库 /home/user/spark-2.4.0-bin-hadoop2.7/metastore_db

pyspark.sql.utils.AnalysisException:u'java.lang.RuntimeException:java.lang.RuntimeException:无法实例化org.apache.hadoop.hive.ql.metadata.SessionHiveMetaStoreClient;

显然 Spark 正在尝试创建新的 Derby 数据库,而不是使用我放在配置文件中的 Metastore。如果我停止 Thrift Server 并只运行 spark,一切都很好。我该如何解决?

嵌入式 Derby Metastore 数据库是否可以让 Thrift Server 和 Spark 访问一个 Hive,或者我需要使用 MySQL?我没有集群并且在本地做所有事情。

4

1 回答 1

0

嵌入式 Derby Metastore 数据库可以在本地使用,但对于生产环境,建议使用任何其他 Metastore 数据库。是的,您绝对可以使用 MYSQL 作为元存储。为此,您必须在hive-site.xml.

您可以按照Use MySQL for the Hive Metastore中的配置指南了解详细信息。

于 2019-11-01T16:12:46.877 回答