如何在 kusto/appinsight 连接中使用 where 条件

问题描述

我正在努力实现这些目标:

  1. 获取某些字段的最新数据(基于时间戳)-> 调用此 latestRequest
  2. 获取这些字段以前的数据(基本上是时间戳调用这个prevIoUsRequest
  3. 计算 latestRequest 和 prevIoUsRequest 之间的差异

这就是我现在带来的:

let LatestRequest=requests
| where operation_Name == "SearchServiceFieldMonitor"
| extend Mismatch = split(tostring(customDimensions.IndexerMismatch)," in ")
| extend    difference = toint(Mismatch[0]),field = tostring(Mismatch[1]),indexer = tostring(Mismatch[2]),index = tostring(Mismatch[3]),service = tostring(Mismatch[4])
| summarize MaxTime=todatetime(max(timestamp)) by service,index,indexer;    



let prevIoUsRequest = requests
| where operation_Name == "SearchServiceFieldMonitor"
| extend Mismatch = split(tostring(customDimensions.IndexerMismatch),service = tostring(Mismatch[4])
|join (LatestRequest) on indexer,service
|where timestamp <LatestRequest.MaxTime

但是,我从这个查询中得到这个错误

确保表达式:LatestRequest.MaxTime 确实是一个简单的名称

我尝试使用 toDateTime(LatestRequest.MaxTime) 但它没有任何区别。我做错了什么?

解决方法

你得到的错误是因为你不能使用点表示法引用表中的列,你应该简单地使用列名,因为连接运算符的结果是一个表,其中包含来自两边的适用列加入。

加入的替代方法可能是使用 row_number()prev() 函数。您可以根据键和时间戳对行进行排序,然后计算当前行与其前一行之间的值,从而找到最后一条和前一条记录。

这是一个例子:

datatable(timestamp:datetime,requestId:int,val:int) 
    [datetime(2021-02-20 10:00),1,5,datetime(2021-02-20 11:00),6,datetime(2021-02-20 12:00),8,datetime(2021-02-20 10:00),2,10,20,30,datetime(2021-02-20 13:00),40,3,100
]
| order by requestId asc,timestamp desc
| extend rn = row_number(0,requestId !=prev(requestId))
| where rn <= 1
| order by requestId,rn desc 
| extend diff = iif(prev(rn) == 1,val - prev(val),val)
| where rn == 0
| project-away rn

结果是:

enter image description here