使用外部 Hive metastore 数据库

重要

AKS 上的 Azure HDInsight 已于 2025 年 1 月 31 日停用。 了解更多信息 请参见此公告

需要将工作负荷迁移到 Microsoft Fabric 或等效的 Azure 产品,以避免工作负荷突然终止。

重要

此功能目前以预览版提供。 Microsoft Azure 预览版补充使用条款 包括适用于 Beta 版、预览版或尚未正式发布的 Azure 功能的更多法律条款。 有关此特定预览的信息,请参阅 AKS 上的 Azure HDInsight 预览信息。 有关问题或功能建议,请在 AskHDInsight 上提交请求,提供详细信息,关注我们以获取 Azure HDInsight 社区 的更多更新。

Hive 元存储用作存储有关数据的元数据的中央存储库。 本文介绍如何使用 AKS 上的 HDInsight 将 Hive 元存储数据库添加到 Trino 群集。 有两种方法:

  • 可以在创建 Trino 群集 期间添加 Hive 目录并将其链接到外部 Hive 元存储数据库。

  • 可以使用 ARM 模板更新添加 Hive 目录并将外部 Hive 元存储数据库附加到群集。

以下示例介绍如何使用 ARM 模板将 Hive 目录和元存储数据库添加到群集。

先决条件

注意

  • 目前,我们支持 Azure SQL 数据库作为内置元存储。
  • 由于 Hive 限制,不支持元存储数据库名称中的“-”(连字符)字符。
  • 仅支持单个元存储数据库连接,clusterProfile.trinoProfile.catalogOptions.hive 节中列出的所有目录都将配置为使用最先指定的同一数据库参数。

添加外部 Hive 元存储数据库

有几个重要部分需要添加到你的群集 ARM 模板中,以配置 Hive 目录和 Hive 元存储数据库:

元存储配置

config.properties 文件中配置外部 Hive 元存储数据库:

{
    "fileName": "config.properties",
    "values": {
        "hive.metastore.hdi.metastoreDbConnectionURL": "jdbc:sqlserver://server-name.database.windows.net;database=myhmsdb1;encrypt=true;trustServerCertificate=true;create=false;loginTimeout=30",
        "hive.metastore.hdi.metastoreDbConnectionUserName": "trinoadmin",
        "hive.metastore.hdi.metastoreDbConnectionPasswordSecret": "hms-db-pwd",
        "hive.metastore.hdi.metastoreWarehouseDir": "abfs://container1@myadlsgen2account1.dfs.core.windows.net/hive/warehouse"
    }
}
财产 描述
hive.metastore.hdi.metastoreDbConnectionURL JDBC 到数据库的连接字符串。 jdbc:sqlserver://server-name.database.windows.net;database=myhmsdb1;encrypt=true;trustServerCertificate=true;create=false;loginTimeout=30
hive.metastore.hdi.metastoreDbConnectionUserName 要连接到数据库的 SQL 用户名。 trinoadmin
hive.metastore.hdi.metastoreDbConnectionPasswordSecret 密钥 referenceName 在 secretsProfile 中使用密码进行了配置。 hms-db-pwd
hive.metastore.hdi.metastoreWarehouseDir ABFS URI 到用于存储数据的存储位置。 abfs://container1@myadlsgen2account1.dfs.core.windows.net/hive/warehouse

Metastore认证

为指定 Azure Key Vault 机密的外部 Hive 元存储数据库配置身份验证。

注意

referenceName 应匹配 hive.metastore.hdi.metastoreDbConnectionPasswordSecret 中提供的值

"secretsProfile": {
    "keyVaultResourceId": "/subscriptions/{USER_SUBSCRIPTION_ID}/resourceGroups/{USER_RESOURCE_GROUP}/providers/Microsoft.KeyVault/vaults/{USER_KEYVAULT_NAME}",
    "secrets": [
        {
            "referenceName": "hms-db-pwd",
            "type": "Secret",
            "keyVaultObjectName": "hms-db-pwd"
        }                        ]
},
财产 描述
secretsProfile.keyVaultResourceId Azure 资源 ID 字符串到 Azure Key Vault,其中存储了 Hive 元存储的机密。 /subscriptions/0000000-0000-0000-0000-000000000000/resourceGroups/trino-rg/providers/Microsoft.KeyVault/vaults/trinoakv
secretsProfile.secrets[*].referenceName 要在 clusterProfile 中稍后使用的机密的唯一引用名称。 Secret1_ref
secretsProfile.secrets[*].type Azure Key Vault 中的对象类型,仅支持“机密”。 秘密
secretsProfile.secrets[*].keyVaultObjectName 包含实际机密值的 Azure Key Vault 中的机密对象的名称。 secret1

目录配置

为了让 Trino 目录能使用外部 Hive 元数据存储,需要指定 hive.metastore=hdi 属性。 详情请查看 将目录添加到现有群集

{
    "fileName": "hive1.properties",
    "values": {
        "connector.name": "hive",
        "hive.metastore": "hdi"
    }
}

完整示例

若要将外部 Hive 元存储配置为现有的 Trino 群集,请通过引用以下示例在群集 ARM 模板中添加所需的部分:

{
    "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
    "contentVersion": "1.0.0.0",
    "parameters": {},
    "resources": [
        {
            "type": "microsoft.hdinsight/clusterpools/clusters",
            "apiVersion": "<api-version>",
            "name": "<cluster-pool-name>/<cluster-name>",
            "location": "<region, e.g. westeurope>",
            "tags": {},
            "properties": {
                "clusterType": "Trino",

                "clusterProfile": {
                    "secretsProfile": {
                        "keyVaultResourceId": "/subscriptions/{USER_SUBSCRIPTION_ID}/resourceGroups/{USER_RESOURCE_GROUP}/providers/Microsoft.KeyVault/vaults/{USER_KEYVAULT_NAME}",
                        "secrets": [
                            {
                                "referenceName": "hms-db-pwd",
                                "type": "Secret",
                                "keyVaultObjectName": "hms-db-pwd"
                            }                        ]
                    },
                    "serviceConfigsProfiles": [
                        {
                            "serviceName": "trino",
                            "configs": [
                                {
                                    "component": "common",
                                    "files": [
                                        {
                                            "fileName": "config.properties",
                                            "values": {
                                                "hive.metastore.hdi.metastoreDbConnectionURL": "jdbc:sqlserver://server-name.database.windows.net;database=myhmsdb1;encrypt=true;trustServerCertificate=true;create=false;loginTimeout=30",
                                                "hive.metastore.hdi.metastoreDbConnectionUserName": "trinoadmin",
                                                "hive.metastore.hdi.metastoreDbConnectionPasswordSecret": "hms-db-pwd",
                                                "hive.metastore.hdi.metastoreWarehouseDir": "abfs://container1@myadlsgen2account1.dfs.core.windows.net/hive/warehouse"
                                            }
                                        }
                                    ]
                                },
                                {
                                    "component": "catalogs",
                                    "files": [
                                        {
                                            "fileName": "hive1.properties",
                                            "values": {
                                                "connector.name": "hive",
                                                "hive.metastore": "hdi"
                                            }
                                        }
                                    ]
                                }
                            ]
                        }
                    ]
                }
            }
        }
    ]
}

部署更新的 ARM 模板以反映群集中的更改。 了解如何 部署 ARM 模板。 成功部署后,可以在 Trino 群集中看到“hive1”目录。

可以运行几个简单的查询来测试 Hive 目录。

检查 Hive 目录是否已成功创建。

show catalogs;

查询表(在此示例中,“hive1”是指定的 hive 目录的名称)。

create schema hive1.schema1;
create table hive1.schema1.tpchorders as select * from tpch.tiny.orders;
select * from hive1.schema1.tpchorders limit 100;

备用配置

或者,可以在 trinoProfile.catalogOptions.hive 中指定外部 Hive 元存储数据库参数以及 hive.metastore=hdi 目录属性:

财产 描述
trinoProfile.catalogOptions.hive 需要外部 Hive 元存储数据库参数的 Hive、Iceberg 或 Delta 目录列表,并且每个目录需要特定的参数。 若要使用外部元存储数据库,此列表中必须存在数据目录。
trinoProfile.catalogOptions.hive[*].catalogName serviceConfigsProfiles中配置的 Trino 目录的名称,该目录配置为使用外部 Hive 元存储数据库。 hive1
trinoProfile.catalogOptions.hive[*].metastoreDbConnectionURL JDBC 到数据库的连接字符串。 jdbc:sqlserver://server-name.database.windows.net;database=myhmsdb1;encrypt=true;trustServerCertificate=true;create=false;loginTimeout=30
trinoProfile.catalogOptions.hive[*].metastoreDbConnectionUserName 要连接到数据库的 SQL 用户名。 trinoadmin
trinoProfile.catalogOptions.hive[*].metastoreDbConnectionPasswordSecret 使用密码在 secretsProfile 中配置的机密 referenceName。 hms-db-pwd
trinoProfile.catalogOptions.hive[*].metastoreWarehouseDir ABFS URI 指向数据在存储中保存的位置。 abfs://container1@myadlsgen2account1.dfs.core.windows.net/hive/warehouse

完整示例

{
    "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
    "contentVersion": "1.0.0.0",
    "parameters": {},
    "resources": [
        {
            "type": "microsoft.hdinsight/clusterpools/clusters",
            "apiVersion": "<api-version>",
            "name": "<cluster-pool-name>/<cluster-name>",
            "location": "<region, e.g. westeurope>",
            "tags": {},
            "properties": {
                "clusterType": "Trino",

                "clusterProfile": {
                    "secretsProfile": {
                        "keyVaultResourceId": "/subscriptions/{USER_SUBSCRIPTION_ID}/resourceGroups/{USER_RESOURCE_GROUP}/providers/Microsoft.KeyVault/vaults/{USER_KEYVAULT_NAME}",
                        "secrets": [
                            {
                                "referenceName": "hms-db-pwd",
                                "type": "Secret",
                                "keyVaultObjectName": "hms-db-pwd"
                            }                        ]
                    },
                    "serviceConfigsProfiles": [
                        {
                            "serviceName": "trino",
                            "configs": [
                                {
                                    "component": "catalogs",
                                    "files": [
                                        {
                                            "fileName": "hive1.properties",
                                            "values": {
                                                "connector.name": "hive",
                                                "hive.metastore": "hdi"
                                            }
                                        }
                                    ]
                                }
                            ]
                        }
                    ],
                    "trinoProfile": {
                        "catalogOptions": {
                            "hive": [
                                {
                                    "catalogName": "hive1",
                                    "metastoreDbConnectionURL": "jdbc:sqlserver://server-name.database.windows.net;database=myhmsdb1;encrypt=true;trustServerCertificate=true;create=false;loginTimeout=30",
                                    "metastoreDbConnectionUserName": "trinoadmin",
                                    "metastoreDbConnectionPasswordSecret": "hms-db-pwd",
                                    "metastoreWarehouseDir": "abfs://container1@myadlsgen2account1.dfs.core.windows.net/hive/warehouse"
                                }
                            ]
                        }
                    }
                }
            }
        }
    ]
}