在不在 Kusto 中序列化数据的情况下在物化视图中按用户名和时间戳查找下一条记录
Finding next record by username and timestamp in a materialized view without serializing data in Kusto
我在 Azure 数据资源管理器中有一个 table,其中包含用户名、时间戳和状态。我要计算同一用户名的每个状态的持续时间,并将结果存储在物化视图中。
下面的示例查询显示了预期的结果,但物化视图不支持数据序列化(例如排序语句)。
是否有巧妙的方法来解决实体化视图中的这一限制?
示例查询:
let data=datatable (Username:string, Timestamp:datetime, Status:int)
[
"Jimmy", datetime(2021-10-01 12:30:00), 1,
"Joan", datetime(2021-10-01 12:34:56), 1,
"Joan", datetime(2021-10-01 13:34:56), 2,
"Jimmy", datetime(2021-10-01 14:34:56), 2,
"Jimmy", datetime(2021-10-01 16:34:56), 1,
"Joan", datetime(2021-10-01 18:34:34), 1,
"Joan", datetime(2021-10-01 18:38:20), 2,
"Joan", datetime(2021-10-01 18:45:16), 1,
];
data
| sort by Username, Timestamp asc
| extend NextUsername = next(Username)
| extend NextTimestamp = iif(Username == NextUsername, next(Timestamp), datetime(null))
| extend Duration = (NextTimestamp - Timestamp)
| project Username, Start = Timestamp, End = NextTimestamp, Status, Duration
示例结果:
Username Start End Status Duration
Joan 2021-10-01 12:34:56.0000000 2021-10-01 13:34:56.0000000 1 01:00:00
Joan 2021-10-01 13:34:56.0000000 2021-10-01 18:34:34.0000000 2 04:59:38
Joan 2021-10-01 18:34:34.0000000 2021-10-01 18:38:20.0000000 1 00:03:46
Joan 2021-10-01 18:38:20.0000000 2021-10-01 18:45:16.0000000 2 00:06:56
Joan 2021-10-01 18:45:16.0000000 1
Jimmy 2021-10-01 12:30:00.0000000 2021-10-01 14:34:56.0000000 1 02:04:56
Jimmy 2021-10-01 14:34:56.0000000 2021-10-01 16:34:56.0000000 2 02:00:00
Jimmy 2021-10-01 16:34:56.0000000 1
不,物化视图仅支持为您提供重复数据删除、最新记录或定时分箱聚合的汇总。对于此计算,如果您想提高性能,您应该创建自己的计划进程来执行此逻辑并将结果存储在 table.
中
我在 Azure 数据资源管理器中有一个 table,其中包含用户名、时间戳和状态。我要计算同一用户名的每个状态的持续时间,并将结果存储在物化视图中。
下面的示例查询显示了预期的结果,但物化视图不支持数据序列化(例如排序语句)。
是否有巧妙的方法来解决实体化视图中的这一限制?
示例查询:
let data=datatable (Username:string, Timestamp:datetime, Status:int)
[
"Jimmy", datetime(2021-10-01 12:30:00), 1,
"Joan", datetime(2021-10-01 12:34:56), 1,
"Joan", datetime(2021-10-01 13:34:56), 2,
"Jimmy", datetime(2021-10-01 14:34:56), 2,
"Jimmy", datetime(2021-10-01 16:34:56), 1,
"Joan", datetime(2021-10-01 18:34:34), 1,
"Joan", datetime(2021-10-01 18:38:20), 2,
"Joan", datetime(2021-10-01 18:45:16), 1,
];
data
| sort by Username, Timestamp asc
| extend NextUsername = next(Username)
| extend NextTimestamp = iif(Username == NextUsername, next(Timestamp), datetime(null))
| extend Duration = (NextTimestamp - Timestamp)
| project Username, Start = Timestamp, End = NextTimestamp, Status, Duration
示例结果:
Username Start End Status Duration
Joan 2021-10-01 12:34:56.0000000 2021-10-01 13:34:56.0000000 1 01:00:00
Joan 2021-10-01 13:34:56.0000000 2021-10-01 18:34:34.0000000 2 04:59:38
Joan 2021-10-01 18:34:34.0000000 2021-10-01 18:38:20.0000000 1 00:03:46
Joan 2021-10-01 18:38:20.0000000 2021-10-01 18:45:16.0000000 2 00:06:56
Joan 2021-10-01 18:45:16.0000000 1
Jimmy 2021-10-01 12:30:00.0000000 2021-10-01 14:34:56.0000000 1 02:04:56
Jimmy 2021-10-01 14:34:56.0000000 2021-10-01 16:34:56.0000000 2 02:00:00
Jimmy 2021-10-01 16:34:56.0000000 1
不,物化视图仅支持为您提供重复数据删除、最新记录或定时分箱聚合的汇总。对于此计算,如果您想提高性能,您应该创建自己的计划进程来执行此逻辑并将结果存储在 table.
中