简体   繁体   English

如何处理KQL查询中的空结果?

[英]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.

相关问题 如何在第二个查询中使用第一个 KQL 查询的结果来过滤结果? - How to use result of first KQL query in the second query to filter results? 是否可以在 Azure 警报中显示 KQL 查询结果? - Is it possible to show KQL query results in an Azure alert? KQL - KQL 查询的逻辑处理 - KQL - logical processing of an KQL query App Insights REST 调用使用 KQL 查询返回空 - App Insights REST call using KQL query returns empty 如何使用 AZURE KQL 编写查询以获取自定义 output 作为结果? - How to write a query to get the custom output as a result using AZURE KQL? 如何在 LogicApps 中使用 KQL 查询构建嵌套的 HTML 表? - How to build up a nested HTML Table using a KQL query in LogicApps? KQL 查询中忽略白名单 - Whitelist is being ignored in KQL Query KQL 查询中的多个日期 - Multiple dates within KQL query 如何使用 Azure Kusto 查询语言 (KQL) 查询 Jmeter Graph,例如 Active Threads Over times - How to use Azure Kusto Query Language (KQL) to query Jmeter Graph such as Active Threads Over times KQL如何根据与匹配值位于同一行的项目在查询中查找匹配值和原始值 - KQL how to find matching values in query and the original value based on an item in the same row as the matched value
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM