【原创】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

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