问题描述
我尝试在天蓝色的流分析中绕过跳跃窗口。 我将从Azure事件中心获取以下数据:
[
{
"Id": "1","SensorData": [
{
"Timestamp": 1603112431,"Type": "LineCrossing","Direction": "forward"
},{
"Timestamp": 1603112431,"Direction": "forward"
}
],"EventProcessedUtcTime": "2020-10-20T06:35:48.5890814Z","PartitionId": 1,"EventEnqueuedUtcTime": "2020-10-20T06:35:48.3540000Z"
},{
"Id": "1","SensorData": [
{
"Timestamp": 1603112430,"Direction": "backward"
}
],"PartitionId": 0,"EventEnqueuedUtcTime": "2020-10-20T06:35:48.2140000Z"
}
]
我的查询如下:
SELECT s.Id,COUNT(data.ArrayValue.Direction) as Count
FROM [customers] s TIMESTAMP BY EventEnqueuedUtcTime
CROSS APPLY GetArrayElements(s.SensorData) AS data
WHERE data.ArrayValue.Type = 'LineCrossing'
AND data.ArrayValue.Direction = 'forward'
GROUP BY s.Id,HoppingWindow(second,3600,5)
我使用跳窗来获取每5秒的最后一天的所有事件。 我对给定dto的期望是:一行包含Id1和Count 2,但是我收到的是:包含Id1的720行(所以3600除以5)具有Count 2。
HoppingWindow函数不应该汇总那些事件吗?
解决方法
我按如下所示组织了查询:
with inputValues as (Select input.*,message.ArrayValue as Data from input CROSS APPLY GetArrayElements(input.SensorData) as message)
select inputValues.Id,count(Data.Direction) as Count
into output
from inputValues
where Data.Type = 'LineCrossing' and Data.Direction='forward'
GROUP BY inputValues.Id,HoppingWindow(second,3600,5)
我已经将输入设置为事件中心,并且在Visual Studio中,我已经开始使用云输入进行查询。
我使用Windows Client application将消息传递到Event Hub(下图2.),并观察到事件每5秒(下图1.和下图3)到来。 )。
也许只是更改我共享的查询以反映正确的时间戳记,但结果应该与预期的一样-对于最后一小时内到达的所有事件,每5秒钟将根据定义的条件计入输出HoppingWindow函数)。