【问题标题】:Kusto query analysis based on Key-Value telemetry data - flatten dataset基于 Key-Value 遥测数据的 Kusto 查询分析——展平数据集
【发布时间】:2022-11-12 21:26:24
【问题描述】:

我有一个包含遥测数据的 kusto 表,如下所示:

Timestamp Key Value
2022-11-10 10:00:01 Position 87.3
2022-11-10 10:00:13 Temperature 10.2
2022-11-10 10:00:55 Temperature 10.4
2022-11-10 10:01:25 Position 81.3
2022-11-10 10:01:42 Temperature 12.2
2022-11-10 10:02:13 Temperature 12.8
2022-11-10 10:02:44 Position 74.3
2022-11-10 10:03:01 Temperature 18.6
2022-11-10 10:03:19 Position 87.3
2022-11-10 10:03:38 Temperature 10.6
2022-11-10 10:04:00 Temperature 10.7
2022-11-10 10:04:00 Temperature 10.1
2022-11-10 10:04:25 Position 80.3
2022-11-10 10:04:59 Temperature 12.6

我想进行一些分析,计算某个区域的平均温度;在5分钟的桶中。 因此,我想对发送的最新位置的所有温度进行平均,直到位置更新:

我想要如下的东西

Timestamp Area Temperature
2022-11-10 10:00:00 1 10.4
2022-11-10 10:00:00 2 12,53
2022-11-10 10:00:00 3 18.6

我尝试使用基于键值的区域和温度列来扩展表:

Timestamp Key Value Area Temperature
2022-11-10 10:00:01 Position 87.3 1
2022-11-10 10:00:13 Temperature 10.2 10.2
2022-11-10 10:00:55 Temperature 10.4 10.4
2022-11-10 10:01:25 Position 81.3 2
2022-11-10 10:01:42 Temperature 12.2 12.2
2022-11-10 10:02:13 Temperature 12.8 12.8
2022-11-10 10:02:44 Position 74.3 3
2022-11-10 10:03:01 Temperature 18.6 18.6
2022-11-10 10:03:19 Position 87.3 1
2022-11-10 10:03:38 Temperature 10.6 10.6
2022-11-10 10:04:00 Temperature 10.7 10.7
2022-11-10 10:04:00 Temperature 10.1 10.1
2022-11-10 10:04:25 Position 80.3 2
2022-11-10 10:04:59 Temperature 12.6 12.6

然后我尝试用找到的前一个非空值和一个聚合来填充空值,但是 prev() 函数不允许找到以前的非空值。

目前我对如何实现我的目标没有任何想法。

【问题讨论】:

  • 您的示例数据中没有“区域”。它是从哪里冒出来的?要求的结果是什么?转型逻辑是什么?

标签: azure-data-explorer kql telemetry kusto-explorer


【解决方案1】:

您可以使用scan operator 来分析序列。这是一个可能的解决方案,但没有区号和 4 个不同的位置。

datatable (Timestamp: datetime, Key: string, Value: real) [
    datetime(2022-11-10 10:00:01), "Position", 87.3,
    datetime(2022-11-10 10:00:13), "Temperature", 10.2,
    datetime(2022-11-10 10:00:55), "Temperature", 10.4,
    datetime(2022-11-10 10:01:25), "Position", 81.3,
    datetime(2022-11-10 10:01:42), "Temperature", 12.2,
    datetime(2022-11-10 10:02:13), "Temperature", 12.8,
    datetime(2022-11-10 10:02:44), "Position", 74.3,
    datetime(2022-11-10 10:03:01), "Temperature", 18.6,
    datetime(2022-11-10 10:03:19), "Position", 87.3,
    datetime(2022-11-10 10:03:38), "Temperature", 10.6,
    datetime(2022-11-10 10:04:00), "Temperature", 10.7,
    datetime(2022-11-10 10:04:00), "Temperature", 10.1,
    datetime(2022-11-10 10:04:25), "Position", 80.3,
    datetime(2022-11-10 10:04:59), "Temperature", 12.6,
]
| sort by Timestamp asc
| scan declare (Position: real) with (
    step Pos output= none: Key == "Position";
    step Temp: Key == "Temperature" => Position= Pos.Value;
)
| summarize round(avg(Value), 2) by Position

结果:

Position avg_Value
87.3 10.4
81.3 12.5
74.3 18.6
80.3 12.6

【讨论】:

    猜你喜欢
    • 2016-10-25
    • 2021-05-23
    • 2022-10-20
    • 2021-09-12
    • 2016-01-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多