[英]how to handle empty results in KQL query?
trying to write KQL query counting resources in Azure subscriptions.尝试在 Azure 订阅中编写 KQL 查询计数资源。 I'm having problem with subs with no resources since nothing is return.我在没有资源的潜艇上遇到问题,因为没有任何回报。 so i want to merge [left] all subscription with [right] all resources:所以我想将[左]所有订阅与[右]所有资源合并:
$queryAllOuter = "resourceContainers
| where type =~ 'microsoft.resources/subscriptions'
| project subscriptionId, subName=name
| join kind=leftouter resources on subscriptionId
| summarize nrOfResources=count() by subscriptionId,subName
| sort by nrOfResources asc"
the problem is that empty subs are summarized as having 1 resource.问题是空潜艇被总结为有 1 个资源。 when i checked the records before summarize, such empty record looks like that:当我在总结之前检查记录时,这样的空记录看起来像这样:
subscriptionId: xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx subName: Visual Studio Professional Subscription subscriptionId1: name: id: type: tenantId: kind: location: resourceGroup: managedBy: sku: plan: properties: tags: identity: zones: extendedLocation: ResourceId: subscriptionId:xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx subName:Visual Studio Professional 订阅 subscriptionId1:名称:id:类型:tenantId:种类:位置:resourceGroup:managedBy:sku:计划:属性:标签:身份:区域:extendedLocation:ResourceId :
how to produce some output on null returns?如何在 null 回报上产生一些 output?
tried different combinations of using iff, isnull, extend - but it's IMHO deeper issue... no idea how to approach it尝试使用 iff、isnull、extend 的不同组合 - 但恕我直言,这是更深层次的问题......不知道如何处理它
My preferred way would be to first count and then join.我的首选方法是先计数然后加入。
resourceContainers
| where type =~ 'microsoft.resources/subscriptions'
| project subscriptionId, subName=name
| join kind=leftouter
(
resources
| summarize nrOfResources = count() by subscriptionId
) on subscriptionId
| extend nrOfResources = coalesce(nrOfResources, 0)
| sort by nrOfResources asc
You can also join and then count those rows where the subscriptionId from the right side is not empty.您还可以加入,然后统计右侧 subscriptionId 不为空的那些行。
resourceContainers
| where type =~ 'microsoft.resources/subscriptions'
| project subscriptionId, subName=name
| join kind=leftouter resources on subscriptionId
| summarize nrOfResources=countif(isnotempty(subscriptionId1)) by subscriptionId,subName
| sort by nrOfResources asc
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.