是否可以从某个列值中获取特定行数,类似于 Java 中的 foreach 循环?
Is it possible to take a specific number of rows from certain column value, similar to a foreach loop in Java?
有没有办法让 kusto 中的行为类似于 Java 中的 foreach 循环?例如,假设我有一个不同的服务列表 A-F,那么对于这个不同的列表,我想为每个不同的列值取 N 行,有没有办法在单个查询中执行此操作?
我尝试了多种加入方式,但无法使其以动态方式工作。我所说的动态是指我不想编写指定 | where service = 'A' | take 30
的不同查询。
ServiceLogs
| where isnotempty( service)
| distinct service
| join kind = rightouter ServiceLogs on $left.service== $right.service
| take 30
实际结果是,对于不同列表中的单个值,它只有 returns 30 个,而不是每个值
虽然没有 foreach
运算符,但通常可以使用语言中的不同 functions/operators 来实现目标。
在这种特定情况下,可能是使用 top-nested
(https://docs.microsoft.com/en-us/azure/kusto/query/topnestedoperator) would help, or perhaps the partition
operator (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
)
有没有办法让 kusto 中的行为类似于 Java 中的 foreach 循环?例如,假设我有一个不同的服务列表 A-F,那么对于这个不同的列表,我想为每个不同的列值取 N 行,有没有办法在单个查询中执行此操作?
我尝试了多种加入方式,但无法使其以动态方式工作。我所说的动态是指我不想编写指定 | where service = 'A' | take 30
的不同查询。
ServiceLogs
| where isnotempty( service)
| distinct service
| join kind = rightouter ServiceLogs on $left.service== $right.service
| take 30
实际结果是,对于不同列表中的单个值,它只有 returns 30 个,而不是每个值
虽然没有 foreach
运算符,但通常可以使用语言中的不同 functions/operators 来实现目标。
在这种特定情况下,可能是使用 top-nested
(https://docs.microsoft.com/en-us/azure/kusto/query/topnestedoperator) would help, or perhaps the partition
operator (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
)