【完美解決】Spark-SQL、Hive多 Metastore、多后端、多庫
【完美解決】Spark-SQL、Hive多 Metastore、多后端、多庫
SparkSQL 支持同時連接多種 Metastore,包括Atlas2(PB),Hive 0.12+幾種格式。用戶可以在一條SQL語句中操作來自多個 Metastore 的表。
配置 Metastore
按照正常的使用方式配置 conf/hive-site.xml
比如配置訪問 mysql:
|
執行 spark-sql:
|
可以看到已經可以正常訪問 mysql 了。
添加一個 Metastore
添加一個新的 metastore 需要在 conf/ 中新增加一個配置文件,比如 hive-site2.xml(文件名無限制),里邊配置新的metastore,實例內容如下:
|
然后啟動 spark-sql 客戶端:
|
費元星的hive-site.xml 配置:
<configuration>
<!--如果沒有配置說明,等於耍流氓 by feiyuanxing-->
<property>
<name>hive.metastore.warehouse.dir</name>
<value>hdfs://IP:prot/app/ns/df</value>
<description>location of default database for the warehouse</description>
</property>
<property>
<name>hive.exec.scratchdir</name>
<value>hdfs://IP:prot/app/ns/df/tmp/hive-${user.name}</value>
<description>Scratch space for Hive jobs</description>
</property>
<property>
<name>hive.security.authorization.enabled</name>
<value>false</value>
</property>
<!-- -->
<property>
<name>hive.metastore.client.connect.retry.delay</name>
<value>-1</value>
</property>
<property>
<name>hive.cli.print.current.db</name>
<value>true</value>
</property>
<property>
<name>hive.metastore.thrift.framed.transport.enabled</name>
<value>true</value>
</property>
<property>
<name>hive.metastore.use.combined</name>
<value>true</value>
</property>
<!-- 連接mysql -->
<property>
<name>metaclient.config.mysql</name>
<value>hive-site-mysql.xml</value>
</property>
<property>
<name>metaclient.alias.mysql</name>
<value>mysql.mysql</value>
</property>
<property>
<name>metaclient.config.hive</name>
<value>hive-site-hive.xml</value>
</property>
<property>
<name>metaclient.alias.hive</name>
<value>hive.hive</value>
</property>
</configuration>
跨 Metastore 操作
經過上邊兩步配置,當前系統中一共存在兩個 metastore: mysql 和 hive2. 而且我們通過為 hive2 中的 default 數據指定別名為 default2 避免了命名沖突的問題,那么現在就可以同時操作兩個數據庫中的表了。比如:
|