【发布时间】:2021-06-21 04:48:24
【问题描述】:
我们在 Azure 数据资源管理器中有一个具有以下格式的数据集,其中时间戳为毫秒级别,数据大量流入。
| sensorid | timestamp | value |
|---|---|---|
| valve1 | 24-03-2021 | 123 |
| valve1 | 23-03-2021 | 234 |
| cylinderspeed | 23-03-2021 | 1.2 |
| productcode | 23-03-2021 | abc |
| productcode | 24-03-2021 | def |
在上述数据中,valve1和cyliderspeed传感器每秒会报告多次,但productcode会在生产线开始生产另一个产品时报告。
通过这个 Kusto 查询,我们可以将所有数值导出到可以导入 Excel 或 PowerBi 的表中
FactoryData
| where sourcetimestamp > ago(1h)
| summarize average=avg(todouble(value)) by bin(timestamp, 1s), sensorid
| evaluate pivot(sensorid, any(average))
我想更改此查询,以便在平均值上完成汇总,如上所示,如果值是数字,但如果不是数字,则在字符串上。
更新: 我感兴趣的结果是一个看起来像这样的表,其中 sensorid 值已被转换为列
| timestamp | valve1 | cylinderspeed | productcode |
|---|---|---|---|
| 23-03-2021 | 123 | 1,2 | abc |
| 24-mars | 234 | def |
对于数字数据,使用上面显示的查询很容易实现这一点。我也可以这样做:
FactoryData
| where sourcetimestamp > ago(1h)
| summarize binvalue=any(value) by bin(sourcetimestamp, 1s), sensorid
| evaluate pivot(sensorid, any(binvalue))
这将产生想要的结果,但如果传感器在一秒钟的 bin 中有多个数值,这将取 任何其中一个而不计算平均值。
所以问题是,我如何更改上述查询,以便对于数字传感器,binvalue 将是一个平均值,而对于字符串传感器,它将是 bin 中的任何值。
【问题讨论】: