azure-data-explorer - 如何在 kusto/appinsight 连接中使用 where 条件
问题描述
我正在努力实现这些目标:
- 获取某些字段的最新数据(基于时间戳)-> 调用这个 latestRequest
- 获取这些字段的先前数据(基本上是时间戳<latestRequest.timestamp)-> 调用此previousRequest
- 计算 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), " in ")
| extend difference = toint(Mismatch[0])
, field = tostring(Mismatch[1])
, indexer = tostring(Mismatch[2])
, index = tostring(Mismatch[3])
, service = tostring(Mismatch[4])
|join (LatestRequest) on indexer, index,service
|where timestamp <LatestRequest.MaxTime
但是,我从这个查询中得到这个错误:
确保表达式:LatestRequest.MaxTime 确实是一个简单的名称
我尝试使用toDateTime(LatestRequest.MaxTime)
,但它没有任何区别。我做错了什么?
解决方案
您得到的错误是因为您不能使用点表示法引用表中的列,您应该简单地使用列名,因为连接运算符的结果是一个表,其中包含来自连接两侧的适用列。
join 的替代方法可能是使用row_number()和prev()函数。您可以通过根据键和时间戳对行进行排序来找到最后一条记录和它之前的记录,然后计算当前行和它之前的行之间的值。
这是一个例子:
datatable(timestamp:datetime, requestId:int, val:int)
[datetime(2021-02-20 10:00), 1, 5,
datetime(2021-02-20 11:00), 1, 6,
datetime(2021-02-20 12:00), 1, 8,
datetime(2021-02-20 10:00), 2, 10,
datetime(2021-02-20 11:00), 2, 20,
datetime(2021-02-20 12:00), 2, 30,
datetime(2021-02-20 13:00), 2, 40,
datetime(2021-02-20 13:00), 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
结果是:
推荐阅读
- firebase - Flutter 实时 Firebase CRUD 通知
- ios - 如何使用 Google Nearby Connections API 在范围内的 iOS 和 Android 设备之间连接和传输数据?
- css - 带有 CSS 的选项卡仅使用包含在目标 id 中的复选框 id
- c++ - 函数类型参数的模板参数推导
- bash - 如何使用 bash 将一行的最后一个 [0-9]{1,9} 单元格值移动到最后一行(.csv)
- java - 错误:不兼容的类型:推断的类型不符合推断的上限:INT#1 上限:
- tensorflow - TensorFlow SparseCategoricalCrossentropy 是如何工作的?
- javascript - css/javascript:检查触发悬停效果的图像像素
- r - tibble::add_row 到嵌套的 tibble 在 tidyr 1.0.0 下抛出错误
- php - 省略 PHP 三元和空值合并运算符中的“else”