You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何从Kusto表的docString属性自动填充Microsoft Purview资产描述?

自动同步Kusto表docString到Microsoft Purview资产描述

目前Purview原生不支持直接从Kusto表的docString属性自动同步资产描述,但可以通过PowerShell结合Kusto管理API和Purview Catalog API实现这一需求,以下是具体实现方案:

实现步骤

1. 前置准备

  • 安装Azure PowerShell模块:Install-Module -Name Az -AllowClobber -Scope CurrentUser
  • 确保执行脚本的账户拥有以下权限:
    • Kusto集群的数据库读取权限
    • Microsoft Purview账户的数据目录贡献者权限

2. PowerShell脚本实现

# 配置参数(替换为实际值)
$tenantId = "你的Azure租户ID"
$kustoClusterUri = "https://<集群名称>.<区域>.kusto.windows.net"
$kustoDatabaseName = "目标Kusto数据库名称"
$purviewAccountName = "你的Purview账户名称"
$subscriptionId = "Azure订阅ID"
$resourceGroupName = "Kusto集群所在资源组名称"

# 登录Azure并获取访问令牌
Connect-AzAccount -Tenant $tenantId
$purviewToken = Get-AzAccessToken -ResourceUrl "https://purview.azure.net"
$kustoToken = Get-AzAccessToken -ResourceUrl $kustoClusterUri

# 查询Kusto表及其docString属性
$kustoQuery = @"
.show database $kustoDatabaseName tables with(docstring)
| project TableName = Name, Description = DocString
"@

$kustoResponse = Invoke-RestMethod -Uri "$kustoClusterUri/v1/rest/mgmt" -Method Post `
    -Headers @{
        "Authorization" = "Bearer $($kustoToken.Token)"
        "Content-Type" = "application/json"
    } `
    -Body (@{ db = $kustoDatabaseName; csl = $kustoQuery } | ConvertTo-Json)

# 格式化查询结果为对象列表
$tableList = $kustoResponse.Tables[0].Rows | ForEach-Object {
    [PSCustomObject]@{
        TableName = $_[0]
        Description = $_[1]
    }
}

# 遍历表,同步描述到Purview
foreach ($table in $tableList) {
    if (-not [string]::IsNullOrWhiteSpace($table.Description)) {
        # 构建Purview资产的qualifiedName
        $qualifiedName = "azure_kusto_table://subscriptions/$subscriptionId/resourceGroups/$resourceGroupName/providers/Microsoft.Kusto/clusters/$($kustoClusterUri.Split('/')[2].Split('.')[0])/databases/$kustoDatabaseName/tables/$($table.TableName)"
        
        # 查询Purview中对应的资产
        $assetQueryBody = @{
            uniqueAttributes = @{
                qualifiedName = $qualifiedName
            }
        } | ConvertTo-Json
        
        $assetDetails = Invoke-RestMethod -Uri "https://$purviewAccountName.purview.azure.com/catalog/api/atlas/v2/entity/uniqueAttribute/type/azure_kusto_table" `
            -Method Get `
            -Headers @{
                "Authorization" = "Bearer $($purviewToken.Token)"
                "Content-Type" = "application/json"
            } `
            -Body $assetQueryBody
        
        if ($assetDetails.entity) {
            # 更新资产描述
            $assetDetails.entity.attributes.description = $table.Description
            
            # 提交更新请求
            Invoke-RestMethod -Uri "https://$purviewAccountName.purview.azure.com/catalog/api/atlas/v2/entity" `
                -Method Put `
                -Headers @{
                    "Authorization" = "Bearer $($purviewToken.Token)"
                    "Content-Type" = "application/json"
                } `
                -Body ($assetDetails | ConvertTo-Json -Depth 10)
            
            Write-Host "已同步表 [$($table.TableName)] 的描述到Purview"
        } else {
            Write-Warning "Purview中未找到资产: $qualifiedName"
        }
    }
}

3. 注意事项

  • 务必替换脚本中所有占位符为实际环境的值
  • 若需要定期同步,可将脚本配置为Azure自动化Runbook或Windows任务计划
  • 若Kusto表较多,可添加批量处理逻辑或限流措施,避免API请求频率超限

内容的提问来源于stack exchange,提问作者Guilherme Matheus

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.14 00:20:11