1

有没有办法让 kusto 中的行为类似于 Java 中的 foreach 循环?例如,假设我有一个不同的服务列表 AF,那么对于这个不同的列表,我想为每个不同的列值取 N 行,有没有办法在单个查询中做到这一点?

我尝试了多种加入方式,但无法让它以动态方式工作。我所说的动态是指我不想编写不同的查询来指定| where service = 'A' | take 30.

ServiceLogs
| where isnotempty( service)
| distinct service
| join kind = rightouter ServiceLogs on $left.service== $right.service
| take 30

实际结果是它只为不同列表中的单个值返回 30,而不是每个值

4

1 回答 1

5

虽然没有foreach运算符,但通常有一些方法可以使用语言中的不同函数/运算符来实现目标。

在这种特定情况下,可能是使用top-nestedhttps://docs.microsoft.com/en-us/azure/kusto/query/topnestedoperator)会有所帮助,或者可能是partition运营商(https://docs.microsoft.com /en-us/azure/kusto/query/partitionoperator),取决于不同值的数量service

datatable(s:string, i:int, c:string)
[
    "a", 1, "not me",
    "b", 2, "not me",
    "c", 3, "not me",
    "d", 4, "not me",
    "a", 5, "me",
    "b", 6, "me too",
    "c", 7, "not three",
    "d", 8, "and me",
    "a", 9, "and me too",
    "b", 10, "count me in",
    "c", 11, "i",
    "d", 12, "myself",
]
| partition by s
(
    top 2 by i desc
)
于 2019-05-23T19:16:52.203 回答