【问题标题】:How to use different Hive metastore for saveAsTable?如何为 saveAsTable 使用不同的 Hive Metastore?
【发布时间】:2017-10-19 20:07:49
【问题描述】:

我正在通过 PySpark 使用 Spark SQL (Spark 1.6.1),我需要从一个 Hive 元存储加载表并将数据帧的结果写入另一个 Hive 元存储。

我想知道如何为一个 spark SQL 脚本使用两个不同的元存储?

这是我的脚本的样子。

# Hive metastore 1
sc1 = SparkContext()
hiveContext1 = HiveContext(sc1)
hiveContext1.setConf("hive.metastore.warehouse.dir", "tmp/Metastore1")

#Hive metastore 2
sc2 = SparkContext()
hiveContext2 = HiveContext(sc2)
hiveContext2.setConf("hive.metastore.warehouse.dir", "tmp/Metastore2")

#Reading from a table presnt in metastore1
df_extract = hiveContext1.sql("select * from emp where emp_id =1")

# Need to write the result into a different dataframe
df_extract.saveAsTable('targetdbname.target_table',mode='append',path='maprfs:///abc/datapath...')

【问题讨论】:

    标签: apache-spark hive pyspark apache-spark-sql apache-spark-1.6


    【解决方案1】:

    TL;DR 不能使用一个 Hive 元存储(用于某些表)和另一个(用于其他表)。

    由于 Spark SQL 支持单个 Hive 元存储(在 SharedState 中),无论有多少 SparkSessions 读取和写入不同的 Hive 元存储在技术上都是不可能的。

    【讨论】:

      【解决方案2】:

      HotelsDotCom 专门为此 https://github.com/HotelsDotCom/waggle-dance 开发了一个应用程序 (WaggleDance)。使用它作为代理,您应该能够实现您想要做的事情

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2022-09-28
        • 1970-01-01
        • 2018-09-23
        • 2014-08-27
        • 1970-01-01
        相关资源
        最近更新 更多