【原創】Databricks 更改hive metastore version

在 Databricks Runtime 7.0 及更高版本上,Hive 1.2.0 和 1.2.1 不是內置的元存儲。 如果要將 Hive 1.2.0 或 1.2.1 與 Databricks Runtime 7.0 及更高版本一起使用,請按照[下載元存儲 jar 並指向它們](https://learn.microsoft.com/zh-cn/azure/databricks/data/metastores/external-hive-metastore#download-the-metastore-jars-and-point-to-them)中所述的過程進行操作。

我自己測試10.4版本,hive設置成2.3.9是會報錯的,1.2.1就沒有問題,如下是設置爲1.2.1

第一次運行cluster的spark config設置如下,jars設置成maven主要是爲了讓他在線下載全部的jar包到臨時目錄

spark.sql.hive.metastore.version 1.2.1
spark.sql.hive.metastore.jars maven


在羣集啓動後,打開一個notebook,寫個sql,讓他啓動hive連接和下載jar包

%sql
set spark.sql.hive.metastore.version


運行一會兒後,這個看網速,我運行時候都大概需要10分鐘左右,搜索驅動程序日誌Log4j output,找到如下所示的行:Downloaded metastore jars如下部分日誌,下載完成後,就會出現Downloaded metastore jars to 臨時目錄位置

22/12/06 12:55:33 INFO HiveUtils: Initializing HiveMetastoreConnection version 1.2.1 using maven.
22/12/06 12:55:33 INFO IsolatedClientLoader: Initiating download of metastore jars from maven. This may take a while and is not recommended for production use. Please follow the instructions here: https://docs.databricks.com/user-guide/advanced/external-hive-metastore.html#spark-options on how to download the jars just once and use them in your cluster configuration. A log message beginning with 'Downloaded metastore jars' will print once the download is complete.
 ......
 ......
 ......
 22/12/06 12:59:52 INFO IsolatedClientLoader: Downloaded metastore jars to /local_disk0/tmp/hive-v1_2-06297726-c481-4e17-96d6-8eed224f56f5


把這些下載下來的jar copy到dbfs一個目錄上永久保留下來

%sh
cp -r /local_disk0/tmp/hive-v1_2-06297726-c481-4e17-96d6-8eed224f56f5 /dbfs/lib/hive_metastore_jars


創建一個init script,每次運行前把dbfs上這個jar包copy到各個node的本地目錄上,如下就是創建一個shell腳本文件。暫停10s是確保客戶端準備就緒

%python
dbutils.fs.put("/databricks/scripts/hive-metastore-init","""
#!/bin/bash
sleep 10s
 cp -r /dbfs/lib/hive_metastore_jars /databricks/hive_metastore_jars
 """, True)


把這個腳本配置到集羣的Init Scripts目錄上

image

修改spark config,把jars的maven替換成本地文件夾路徑,就是我們init腳本中的copy過來的本地目錄,每個node在執行的時候都會運行上述腳本copy

spark.sql.hive.metastore.version 1.2.1
spark.sql.hive.metastore.jars /databricks/hive_metastore_jars/*

image

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章