如何在不下载配置单元的情况下连接到远程配置单元服务器?

l5tcr1uw  于 2021-06-24  发布在  Hive
关注(0)|答案(1)|浏览(383)

我正在尝试访问一个没有在我的计算机上下载配置单元的配置单元群集。我在这里读到,我只需要一个jdbc客户端就可以了。我有配置单元群集的url、用户名和密码。我试过用这些来创建hive-site.xml,也试过用编程的方式来实现,尽管这个方法似乎没有输入用户名和密码的地方。不管我做什么,似乎以下错误阻止我访问配置单元:无法示例化org.apache.hadoop.hive.ql.metadata.sessionhivemetastoreclient
我觉得这是因为我没有在我的电脑上下载Hive从网上这个错误的答案。我到底需要在这里做什么才能在没有hive下载的情况下访问它,或者我真的必须下载它吗?以下是我的代码供参考:

spark = SparkSession \
.builder \
.appName("interfacing spark sql to hive metastore without 
configuration file") \
.config("hive.metastore.uris", "https://prod-fmhdinsight- 
eu.azurehdinsight.net") \
.enableHiveSupport() \
.getOrCreate()

data = [('First', 1), ('Second', 2), ('Third', 3), ('Fourth', 4), 
('Fifth', 5)]
df = spark.createDataFrame(data)

# see the frame created

df.show()

# write the frame

df.write.mode("overwrite").saveAsTable("t4")

以及hive-site.xml:

<configuration>

<property> 
    <name>hive.metastore.uris</name> 

    <value>https://prod-fmhdinsight-eu.azurehdinsight.net</value>
</property>
<!--
<property>
    <name>hive.metastore.local</name>
    <value>true</value>
</property>
<-->
<property>
    <name>javax.jdo.option.ConnectionURL</name>
    <value>https://prod-fmhdinsight-eu.azurehdinsight.net</value>
    <description>metadata is stored in a MySQL server</description>
</property>

<property>
    <name>javax.jdo.option.ConnectionDriverName</name>
    <value>com.mysql.jdbc.Driver</value>
    <description>MySQL JDBC driver class</description>
</property>

<property>
    <name>javax.jdo.option.ConnectionUserName</name>
    <value>username</value>
    <description>user name for connecting to mysql server 
</description>
</property>
<property>
    <name>javax.jdo.option.ConnectionPassword</name>
    <value>password</value>
    <description>password for connecting to mysql server 
</description>
</property>
5sxhfpxr

5sxhfpxr1#

热释光;dr使用 spark.sql.hive.metastore.jars 具有的配置属性 maven 让sparksql下载所需的jar。
其他的选择是 builtin (它只是假设hive1.2.1)和hivejar的类路径(例如。 spark.sql.hive.metastore.jars="/Users/jacek/dev/apps/hive/lib/*" ).
如果您的配置单元元存储通过thrift协议远程可用,您可能需要创建 $SPARK_HOME/conf/hive-site.xml 具体如下:

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<?xml-stylesheet type="text/xsl" href="configuration.xsl"?>
<configuration>
  <property>
    <name>hive.metastore.uris</name>
    <value>thrift://localhost:9083</value>
  </property>
</configuration>

hive的一个很好的特性是将配置属性定义为系统属性,因此上面的内容如下所示:

$SPARK_HOME/bin/spark-shell \
  --driver-java-options="-Dhive.metastore.uris=thrift://localhost:9083"

您可能需要将以下内容添加到 conf/log4j.properties 对于更低级的日志记录:

log4j.logger.org.apache.spark.sql.hive.HiveUtils$=ALL
log4j.logger.org.apache.spark.sql.internal.SharedState=ALL

相关问题