Azure Databricks 外部 Hive Metastore

Azure Databricks external Hive Metastore

我查看了关于 Azure Databricks 外部 Hive Metastore(Azure SQL 数据库)用法的[文档][1]。

我能够下载 jar 并将它们放入 /dbfs/hive_metastore_jar

我的下一步是 运行 使用 Init 文件进行集群:

# Hive-specific configuration options.
# spark.hadoop prefix is added to make sure these Hive specific options propagate to the metastore client.
# JDBC connect string for a JDBC metastore
spark.hadoop.javax.jdo.option.ConnectionURL jdbc:sqlserver://<host>.database.windows.net:1433;database=<database> #should I add more parameters?

# Username to use against metastore database
spark.hadoop.javax.jdo.option.ConnectionUserName admin

# Password to use against metastore database
spark.hadoop.javax.jdo.option.ConnectionPassword p@ssword

# Driver class name for a JDBC metastore
spark.hadoop.javax.jdo.option.ConnectionDriverName com.microsoft.sqlserver.jdbc.SQLServerDriver

# Spark specific configuration options
spark.sql.hive.metastore.version 2.7.3 #I am not sure about this
# Skip this one if <hive-version> is 0.13.x.
spark.sql.hive.metastore.jars /dbfs/hive_metastore_jar 

我已将 ini 文件上传到 DBMS 并启动集群。读取 ini 失败。有问题.. [1]: https://docs.microsoft.com/en-us/azure/databricks/data/metastores/external-hive-metastore

我暂时解决了这个问题。我遇到的问题:

  1. 我没有将 Hive jar 复制到本地集群。这很重要,我无法引用 DBMS,应该引用 spark.sql.hive.metastore.jars 到 Hive 的本地副本。使用 INI 脚本我可以复制它们。
  2. 连接很好。我也用了Azure template with Vnet,比较可取。然后,我允许使用数据块从我的 Vnet 访问 Azure SQL。
  3. 上一期 - 我必须在通过复制和 运行 DDL 从 Git 和 Hive 版本 1.2 启动数据块之前创建 Hive 模式 我将它部署到 Azure SQL 数据库中,然后我很高兴。

有一个有用的笔记本,其中包含 download jars 的步骤。它正在下载 jars 到 tmp 然后我们应该将它复制到自己的文件夹。最后,在集群创建中,我们应该参考具有所有参数的 INI 脚本。它有将 jar 从 DBFS 复制到集群本地文件系统的步骤。

// This example is for an init script named `external-metastore_hive121.sh`.
dbutils.fs.put(
    "dbfs:/databricks/scripts/external-metastore_hive121.sh",
    """#!/bin/sh
      |# A temporary workaround to make sure /dbfs is available.
      |sleep 10
      |# Copy metastore jars from DBFS to the local FileSystem of every node.
      |cp -r /dbfs/metastore_jars/hive-v1_2/* /databricks/hive_1_2_1_metastore_jars
      |# Loads environment variables to determine the correct JDBC driver to use.
      |source /etc/environment
      |# Quoting the label (i.e. EOF) with single quotes to disable variable interpolation.
      |cat << 'EOF' > /databricks/driver/conf/00-custom-spark.conf
      |[driver] {
      |    # Hive specific configuration options.
      |    # spark.hadoop prefix is added to make sure these Hive specific options will propagate to the metastore client.
      |    # JDBC connect string for a JDBC metastore
      |    "spark.hadoop.javax.jdo.option.ConnectionURL" = "jdbc:sqlserver://host--name.database.windows.net:1433;database=tcdatabricksmetastore_dev;encrypt=true;trustServerCertificate=false;hostNameInCertificate=*.database.windows.net"
      |
      |    # Username to use against metastore database
      |    "spark.hadoop.javax.jdo.option.ConnectionUserName" = "admin"
      |
      |    # Password to use against metastore database
      |    "spark.hadoop.javax.jdo.option.ConnectionPassword" = "P@ssword"
      |
      |    # Driver class name for a JDBC metastore
      |    "spark.hadoop.javax.jdo.option.ConnectionDriverName" = "com.microsoft.sqlserver.jdbc.SQLServerDriver"
      |
      |    # Spark specific configuration options
      |    "spark.sql.hive.metastore.version" = "1.2.1"
      |    # Skip this one if ${hive-version} is 0.13.x.
      |    "spark.sql.hive.metastore.jars" = "/databricks/hive_1_2_1_metastore_jars/*"
      |}
      |EOF
      |""".stripMargin,
    overwrite = true)

该命令将在 DBFS 中创建一个文件,我们将使用它作为集群创建的参考。

根据文档,我们应该使用配置:

datanucleus.autoCreateSchema true
datanucleus.fixedDatastore false 

为了创建 Hive DDL。它对我不起作用,这就是我使用 git 并自己创建模式和表的原因。

您可以使用以下命令测试所有功能:

%sql show databases