Pyspark:远程Hive仓库位置

我需要从Pyspark读取/写入存储在远程Hive Server中的表。 我所知道的这个远程Hive是在Docker下运行的。 从Hadoop色调我find了两个网站的iris表,我尝试从中select一些数据:

我有一个表metastoreurl:

 http://xxx.yyy.net:8888/metastore/table/mytest/iris 

和表位置url:

 hdfs://quickstart.cloudera:8020/user/hive/warehouse/mytest.db/iris 

我不知道为什么最后的url包含quickstart.cloudera:8020 。 也许这是因为Hive在Docker下运行?

讨论访问Hive表Pyspark教程写道:

https://spark.apache.org/docs/latest/sql-programming-guide.html#hive-tables

使用Hive时,必须使用Hive支持实例化SparkSession,包括连接到持久性Hive Metastore,支持Hive serdes和Hive用户定义的函数。 没有现有Hive部署的用户仍然可以启用Hive支持。 当未由hive-site.xmlconfiguration时,上下文自动在当前目录中创buildmetastore_db,并创build一个由spark.sql.warehouse.dirconfiguration的目录,该目录默认为Spark应用程序当前目录中的spark-warehouse目录开始。 请注意,自从Spark 2.0.0以来,hive-site.xml中的hive.metastore.warehouse.dir属性已被弃用。 而是使用spark.sql.warehouse.dir来指定仓库中数据库的默认位置。 您可能需要向启动Spark应用程序的用户授予写权限。

在我的情况下,我设法得到hive-site.xml既没有hive.metastore.warehouse.dir也没有spark.sql.warehouse.dir属性。

Spark教程build议使用下面的代码来访问远程Hive表:

 from os.path import expanduser, join, abspath from pyspark.sql import SparkSession from pyspark.sql import Row // warehouseLocation points to the default location for managed databases and tables val warehouseLocation = new File("spark-warehouse").getAbsolutePath spark = SparkSession \ .builder \ .appName("Python Spark SQL Hive integration example") \ .config("spark.sql.warehouse.dir", warehouse_location) \ .enableHiveSupport() \ .getOrCreate() 

在我的情况下,运行类似于上面的代码,但与warehouseLocation正确的价值之后,我想我可以这样做:

 spark.sql("use mytest") spark.sql("SELECT * FROM iris").show() 

那么我在哪里可以find远程Hive仓库位置? 如何使Pyspark与远程Hive表一起工作?

更新

hive-site.xml具有以下属性:

 ... ... ... <property> <name>javax.jdo.option.ConnectionURL</name> <value>jdbc:mysql://127.0.0.1/metastore?createDatabaseIfNotExist=true</value> <description>JDBC connect string for a JDBC metastore</description> </property> ... ... ... <property> <name>hive.metastore.uris</name> <value>thrift://127.0.0.1:9083</value> <description>IP address (or fully-qualified domain name) and port of the metastore host</description> </property> 

所以看起来像127.0.0.1是运行Clouder docker应用程序的Docker localhost。 根本无助于到达Hive仓库。

当Cloudera Hive作为Docker应用运行时,如何访问Hive仓库?

这里https://www.cloudera.com/documentation/enterprise/5-6-x/topics/cdh_ig_hive_metastore_configure.html在“远程模式”中,您会发现您&#x7684;Hive metastore运行自己的JVM进程,其他进程HiveServer2, HCatalog, Cloudera Impala通过Thrift APIhive-site.xml中的属性hive.metastore.uri进行通信:

 <property> <name>hive.metastore.uris</name> <value>thrift://xxx.yyy.net:8888</value> </property> 

(不知道你必须指定地址的方式)

也许这个属性:

 <property> <name>javax.jdo.option.ConnectionURL</name> <value>jdbc:mysql://xxx.yyy.net/hive</value> </property>