gpt4 book ai didi

azure-data-explorer - Kusto 按查询分组

转载 作者:行者123 更新时间:2023-12-04 10:02:28 30 4
gpt4 key购买 nike

我有一些日志数据结构如下:

{
timestamp: mm/dd/yyy hh:mm:ss
customDimensions : {
location: "locationA",
subLocation: "subLocationB",
dataName: "dataNameB",
data: "value"
}
}

我需要按位置/子位置返回每个“dataName”的最新记录。

例如
locationA sublocationB dataName value
locationA sublocationC dataName value
locationA sublocationB dataname2 value

基本上对字段执行“分组依据”:location、sublocation 和 dataName 其中 max(timestamp)

我如何使用 Kusto 实现这一点,因为没有支持组,并且汇总函数似乎需要聚合函数?

最佳答案

您可以尝试将动态属性扩展到计算列中,然后使用 arg_max() 进行汇总。通过 timestamp 获取最新的(根据 location ) , subLocationdataName .

例如:

datatable(d:dynamic)[
dynamic({
"timestamp": "2020-05-12 20:32:08",
"customDimensions" : {
"location": "locationA",
"subLocation": "subLocationB",
"dataName": "dataNameB",
"data": "value"
}
}), dynamic({
"timestamp": "2020-05-12 20:35:08",
"customDimensions" : {
"location": "locationA",
"subLocation": "subLocationB",
"dataName": "dataNameB",
"data": "value"
}
}), dynamic({
"timestamp": "2020-05-12 20:25:08",
"customDimensions" : {
"location": "locationB",
"subLocation": "subLocationB",
"dataName": "dataNameC",
"data": "value"
}
})
]
| project timestamp = todatetime(d.timestamp),
location = tostring(d.customDimensions.location),
subLocation = tostring(d.customDimensions.subLocation),
dataName = tostring(d.customDimensions.dataName), data = tostring(d.customDimensions.data)
| summarize arg_max(timestamp, *) by location, subLocation, dataName

关于azure-data-explorer - Kusto 按查询分组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61761245/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com