Leo*_*ese 1 kql azure-data-explorer
有没有办法在 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
Run Code Online (Sandbox Code Playgroud)
实际结果是它只为不同列表中的单个值返回 30,而不是每个值
虽然没有foreach运算符,但通常可以通过使用语言中的不同函数/运算符来实现目标。
在这种特定情况下,使用top-nested(https://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
)
Run Code Online (Sandbox Code Playgroud)