ADX Kusto找到了多个ID元组的最新行

发布于 2025-02-07 17:03:27 字数 1521 浏览 3 评论 0原文

鉴于我有具有ID的设备,并且每个设备都有不同的遥测方面,这些方面存储在ADX表中。这些方面中的每一个都通过telemetryid识别。 DeviceID是唯一的,但是telemetryid不是。该设备 - 元件元组作为ADX中的单个行存储。因此表看起来像:

|DeviceId|TelemetryId|Value|TimeStamp|
|--------|-----------|-----|----------------------------|
|1       | 1         | 10  | 2022-06-15 08:50:42.016496 |
|1       | 2         | 20  | 2022-06-15 08:50:41.072425 |
|1       | 3         | 30  | 2022-06-15 08:50:40.199198 |
|2       | 1         | 11  | 2022-06-15 08:50:39.366868 |
|2       | 2         | 22  | 2022-06-15 08:50:38.536320 |
|2       | 3         | 33  | 2022-06-15 08:50:37.602781 |
|2       | 4         | 44  | 2022-06-15 08:50:36.702367 |
|2       | 5         | 55  | 2022-06-15 08:50:35.677494 |
|1       | 1         | 12  | 2022-06-15 08:50:34.750020 |
|1       | 2         | 22  | 2022-06-15 08:50:33.752211 |

现在我需要有关最新数据的信息,其中包含特定deviceID的所有远程数据数据。从查询消费者的角度来看,我知道系统中存在哪个deviceId,哪个telemetryid分配给每个device> deviced。因此,我可以使用此信息来构建查询。

因此,例如,如果我要查询deviceID == 1我会期望这个结果:

|DeviceId|TelemetryId|Value|TimeStamp|
|--------|-----------|-----|----------------------------|
|1       | 1         | 10  | 2022-06-15 08:50:42.016496 |
|1       | 2         | 20  | 2022-06-15 08:50:41.072425 |
|1       | 3         | 30  | 2022-06-15 08:50:40.199198 |

但是我不确定是否可以使用单个kusto查询来实现这一点? (我知道如何使用多个ADX查询(对于每个设备 - 特里元组的一个查询),但我想知道是否可以使用一个查询来完成它)。

Given I have Devices with an ID and each Device has different telemetry aspects which are stored to an ADX table. Each of these aspects is identified by a TelemetryId. The DeviceId is unique, but the TelemetryId is not. This Device-Telemery tuples are stored as individual rows in ADX. So the table looks like:

|DeviceId|TelemetryId|Value|TimeStamp|
|--------|-----------|-----|----------------------------|
|1       | 1         | 10  | 2022-06-15 08:50:42.016496 |
|1       | 2         | 20  | 2022-06-15 08:50:41.072425 |
|1       | 3         | 30  | 2022-06-15 08:50:40.199198 |
|2       | 1         | 11  | 2022-06-15 08:50:39.366868 |
|2       | 2         | 22  | 2022-06-15 08:50:38.536320 |
|2       | 3         | 33  | 2022-06-15 08:50:37.602781 |
|2       | 4         | 44  | 2022-06-15 08:50:36.702367 |
|2       | 5         | 55  | 2022-06-15 08:50:35.677494 |
|1       | 1         | 12  | 2022-06-15 08:50:34.750020 |
|1       | 2         | 22  | 2022-06-15 08:50:33.752211 |

Now I need the information about the most recent data containing all Telementry data for a specific DeviceId. From the query consumer perspective, I know which DeviceId exist in the system and which TelemetryId are assigned to each DeviceId. So I can use this information to build the query.

So for example, if I would query for DeviceId == 1 I would expect this result:

|DeviceId|TelemetryId|Value|TimeStamp|
|--------|-----------|-----|----------------------------|
|1       | 1         | 10  | 2022-06-15 08:50:42.016496 |
|1       | 2         | 20  | 2022-06-15 08:50:41.072425 |
|1       | 3         | 30  | 2022-06-15 08:50:40.199198 |

But I’m not sure if this can be achieved with a single Kusto Query? (I know how to do it with multiple ADX queries (one query for each Device-Telemetry tuple) but I am wondering if it is possible to get it done with one Query).

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

百变从容 2025-02-14 17:03:27

arg_max(

)绩效原因,您应该考虑在应用聚合之前通过时间戳缩小数据集,例如仅查询最后一周/天/小时,取决于您的数据摄入行为。

datatable (DeviceId:int, TelemetryId:int, Value:int, TimeStamp:datetime)
[
     1 ,1 ,10 ,"2022-06-15 08:50:42.016496"
    ,1 ,2 ,20 ,"2022-06-15 08:50:41.072425"
    ,1 ,3 ,30 ,"2022-06-15 08:50:40.199198"
    ,2 ,1 ,11 ,"2022-06-15 08:50:39.366868"
    ,2 ,2 ,22 ,"2022-06-15 08:50:38.536320"
    ,2 ,3 ,33 ,"2022-06-15 08:50:37.602781"
    ,2 ,4 ,44 ,"2022-06-15 08:50:36.702367"
    ,2 ,5 ,55 ,"2022-06-15 08:50:35.677494"
    ,1 ,1 ,12 ,"2022-06-15 08:50:34.750020"
    ,1 ,2 ,22 ,"2022-06-15 08:50:33.752211"
]
| summarize arg_max(TimeStamp, *) by DeviceId, TelemetryId
deviceID遥测时间戳
252022-06-15T08:50:35.677494Z55
242022-06-15T08:50:36.702367Z44
232022-06-158:50:50:50:50:37.602781Z3333 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33
33 33220222-151515151525T :50:38.53632Z22
212022-06-15T08:50:39.366868Z11
132022-06-15T08:50:40.199198Z30
122022-2022-06-15T08:50:50:40:41.07255Z20
20 11 20222222222222222222222222222222222222222222222222221724255Z 20222222222222222转-15T08:50:42.016496Z10

arg_max()

For performance reasons, you should consider narrowing the dataset by TimeStamp before applying the aggregation, E.g. querying only the last week/day/hour, depends on your data ingestion behaviour.

datatable (DeviceId:int, TelemetryId:int, Value:int, TimeStamp:datetime)
[
     1 ,1 ,10 ,"2022-06-15 08:50:42.016496"
    ,1 ,2 ,20 ,"2022-06-15 08:50:41.072425"
    ,1 ,3 ,30 ,"2022-06-15 08:50:40.199198"
    ,2 ,1 ,11 ,"2022-06-15 08:50:39.366868"
    ,2 ,2 ,22 ,"2022-06-15 08:50:38.536320"
    ,2 ,3 ,33 ,"2022-06-15 08:50:37.602781"
    ,2 ,4 ,44 ,"2022-06-15 08:50:36.702367"
    ,2 ,5 ,55 ,"2022-06-15 08:50:35.677494"
    ,1 ,1 ,12 ,"2022-06-15 08:50:34.750020"
    ,1 ,2 ,22 ,"2022-06-15 08:50:33.752211"
]
| summarize arg_max(TimeStamp, *) by DeviceId, TelemetryId
DeviceIdTelemetryIdTimeStampValue
252022-06-15T08:50:35.677494Z55
242022-06-15T08:50:36.702367Z44
232022-06-15T08:50:37.602781Z33
222022-06-15T08:50:38.53632Z22
212022-06-15T08:50:39.366868Z11
132022-06-15T08:50:40.199198Z30
122022-06-15T08:50:41.072425Z20
112022-06-15T08:50:42.016496Z10

Fiddle

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文