Application Insights 分析中的聚合被视为标量

Aggregations in Application Insights analytics treated as scalars

我在应用程序洞察分析中有这个查询

let total = exceptions 
| where timestamp >= ago(7d)
| where problemId contains "Microsoft.ServiceBus"
| summarize sum(itemCount);

let nullContext = exceptions 
| where timestamp >= ago(7d) 
| where problemId contains "Microsoft.ServiceBus" 
| where customDimensions.["SpecificTelemetry.Message"] == "HttpContext.Current is null" 
| summarize sum(itemCount); 

let result = iff(total == nullContext, "same", "different");
result

但是我收到这个错误

Invalid relational operator

我对昨天相同的代码感到惊讶(据我所知)我收到了一个不同的错误,说支票的两边都需要是标量,但我的理解是聚合即使它显示一个值(在 sum_countItem 下)它不是标量。但找不到改造它的方法或现在摆脱这项工作。

谢谢

几个问题。 首先 - 无效的关系运算符可能是由于 let 语句之间的空行造成的。 AI Analytics 允许您在同一个 window 中编写多个查询,并使用空行分隔这些查询。因此,为了 运行 所有语句作为单个查询,您需要消除空行。

关于 "Left and right side of the relational operator must be scalars" 的错误 - "summarize" 运算符的结果是 table 而不是标量。它可以包含一个 line/column 或其中的多个(想一想如果您在摘要中添加一个 "by" 子句会发生什么)。 要实现您想要执行的操作,您可能需要使用如下单个查询:

exceptions 
| where timestamp >= ago(7d)
| where problemId contains "Microsoft.ServiceBus"
| extend nullContext = customDimensions.["SpecificTelemetry.Message"] == "HttpContext.Current is null"
| summarize sum(itemCount) by nullContext