如何在KQL中从JSONMap列名和值?

rhfm7lfc  于 2022-12-15  发布在  其他
关注(0)|答案(1)|浏览(119)

我在KQL中有以下“SetOfSignals”(使用mv-expand):

"SetOfSignals": {
    "name": "CompanyName",
    "signals": [
        {
            "name": "AmbientAirTemperature",
            "unit": "C",
            "dataType": "Float32",
            "values": [
                "11.5"
            ]
        },
        {
            "name": "AverageEnergyConsumption",
            "unit": "W",
            "dataType": "Float32",
            "values": [
                "780.0"
            ]
        }
}

现在我想用对应的值来投影信号名称。
我希望它看起来像这样:
| ...|环境空气温度|平均能耗|
| - ------|- ------|- ------|
| ...|十一点五|七百八十分|
但是使用类似| extend AmbientAirTemperature = signals.name的字符串是不起作用的,因为在“signals”中有多个名称为“name”的字符串。
谢谢。

gjmwrych

gjmwrych1#

datatable(SetOfSignals:dynamic)
[
    dynamic
    (
        {
            "name": "CompanyName",
            "signals": [
                {
                    "name": "AmbientAirTemperature",
                    "unit": "C",
                    "dataType": "Float32",
                    "values": [
                        "11.5"
                    ]
                },
                {
                    "name": "AverageEnergyConsumption",
                    "unit": "W",
                    "dataType": "Float32",
                    "values": [
                        "780.0"
                    ]
                }
            ]
        }
    )
]
| mv-apply signal = SetOfSignals.signals on 
  (
    summarize make_bag(bag_pack(tostring(signal.name), signal.values[0]))
  )
| project-away SetOfSignals
| evaluate bag_unpack(bag_)

| 环境空气温度|平均能耗|
| - ------|- ------|
| 11.5 |七百八十分|
Fiddle

相关问题