首页 > 解决方案 > Kustos bag_unpack 没有解压我的 json 字典字符串

问题描述

我有以下数据,我想在 Kusto 中将其拆分为几列,以访问字典条目的值:

在此处输入图像描述

这是我用来从图片中获取表格的代码:

let latestVersionAndroid = toscalar(customEvents
| where client_OS contains "Android"
| summarize max(application_Version));
let releaseDateLatestAndroid = toscalar(customEvents
| where client_OS contains "Android" and application_Version contains latestVersionAndroid
| summarize min(timestamp));
customEvents
| where timestamp > releaseDateLatestAndroid
    and name == 'Login'
    and client_OS contains 'Android'
    and application_Version == latestVersionAndroid
| project properties = customDimensions.Properties, application_Version
| evaluate bag_unpack(properties)

我认为最后一行将展开属性的内容并从中创建一个新表。但正如您在图像中看到的那样,它只是显示与没有评估线相同的结果。是因为键中有空格可用作列名吗?但是,如果 kusto 因此无法完成操作,我会抛出异常吗?是否有另一种方法可以在 Kusto 中提取数据以访问键的值?

非常感谢,特立独行

标签: azureazure-log-analyticsazure-data-explorerazure-monitoring

解决方案


这可能是因为看起来像 json 的“属性”实际上是一个字符串。如果是这种情况,您应该尝试将 json 解析为字符串,然后执行 bag_unpack。例如更改此行:

| project properties = customDimensions.Properties, application_Version

对此:

| project properties = parse_json(tostring(customDimensions.Properties)), application_Version

为了使用空格访问列,您需要将它们放入方括号中,如下所示

| summarize count()
    by application_Version, ["DW version"]

推荐阅读