首页 > 解决方案 > Pyspark 不显示 hive 数据库

问题描述

我尝试通过 pyspark 连接到 hive 数据库,但看不到我的数据库(仅默认)

Welcome to
      ____              __
     / __/__  ___ _____/ /__
    _\ \/ _ \/ _ `/ __/  '_/
   /__ / .__/\_,_/_/ /_/\_\   version 2.4.5
      /_/

Using Python version 3.7.4 (default, Aug 13 2019 20:35:49)
SparkSession available as 'spark'.
>>> spark.sql('show databases')
DataFrame[databaseName: string]
>>> spark.sql('show databases').show()
+------------+
|databaseName|
+------------+
|     default|
+------------+

但是,如果我使用 hive 执行此命令,则会得到以下信息:

hive> show databases;
OK
signals
default
test
Time taken: 0.973 seconds, Fetched: 3 row(s)
hive> 

我应该怎么做才能连接到我的配置单元实例?

标签: apache-sparkhadoophive

解决方案


请检查您是否已将 spark 配置为使用 hive 元存储。

SPARK_HOME/conf/hive-site.xml
并检查以下属性,如果不存在则添加。

<configuration>
  <property>
  <name>hive.metastore.uris</name>
    <!-- hostname must point to the Hive metastore URI in your cluster -->
    <value>thrift://hostname:port</value>
    <description>URI for client to contact metastore server</description>
  </property>
</configuration>

注意:如果您不知道 Metastore 的主机名和端口,请转到HIVE_HOME/conf/hive-site.xml. 你可以在那里找到那些财产


推荐阅读