【问题标题】:Azure Stream Analytic SQL TumblingWindow expected Window is not returned未返回 Azure Stream Analytic SQL TumblingWindow 预期窗口
【发布时间】:2021-08-01 14:18:01
【问题描述】:

在 Azure Stream Analytic (IoT Hub) 中,无论我指定什么时间窗口,TumblingWindow 函数都无法比较时间并且不会返回我需要的窗口。我正在尝试使用下面的 SQL 代码块向我返回一个 2 秒的窗口,但输出包括所有事件。由于Stream Analytic中没有pivot函数,我使用的是@Joe-Zhang建议的方法

在这种情况下,每 2 秒有一个 IoT 读取事件,我预计只会返回一个事件 -


with tempone as (
    
    select 
    cast(dataArr.ArrayValue.SourceTimestamp as datetime) as SourceTimestamp, 
    cast(valuesArr.ArrayValue.Address as bigint) as Address2, 
    max(cast(valuesArr.ArrayValue.Value as float)) as Value2

from iotinput i
cross apply GetArrayElements(i.Content) as contentArr
cross apply GetArrayElements(contentArr.ArrayValue.Data) as dataArr
cross apply GetArrayElements(dataArr.ArrayValue.[Values]) as valuesArr

WHERE cast(valuesArr.ArrayValue.Address as bigint) = 30002

GROUP BY cast(dataArr.ArrayValue.SourceTimestamp as datetime), 
    cast(valuesArr.ArrayValue.Address as bigint),
    TumblingWindow(second, 2)
),

temptwo AS ( 

    select 
    cast(dataArr.ArrayValue.SourceTimestamp as datetime) as SourceTimestamp, 
    cast(valuesArr.ArrayValue.Address as bigint) as Address3, 
    max(cast(valuesArr.ArrayValue.Value as float)) as Value3


from iotinput i
cross apply GetArrayElements(i.Content) as contentArr
cross apply GetArrayElements(contentArr.ArrayValue.Data) as dataArr
cross apply GetArrayElements(dataArr.ArrayValue.[Values]) as valuesArr

WHERE cast(valuesArr.ArrayValue.Address as bigint) = 30003

GROUP BY cast(dataArr.ArrayValue.SourceTimestamp as datetime), 
    cast(valuesArr.ArrayValue.Address as bigint),
    TumblingWindow(second, 2)
 )

select tempone.SourceTimestamp, tempone.Value2 as Temperature, temptwo.Value3 as Humidity from tempone
join temptwo on tempone.SourceTimestamp = temptwo.SourceTimestamp
and DATEDIFF(second,tempone, temptwo) BETWEEN 0 AND 2

返回值 -

【问题讨论】:

    标签: azure-stream-analytics


    【解决方案1】:

    如果不使用TIMESTAMP BY,时间逻辑将基于摄取时间。

    在这里,您似乎希望在 SourceTimestamp 上完成时间处理,但您没有对其进行 TIMESTAMP BY。

    【讨论】:

    • 嗨,我在 azure event-hub 主题中的消息的日期字段上使用带有时间戳的 tumblingWindow(Duration(hour, 1)) 并存储 min(topic.date) 和 max (topic.date) 在数据库中。在大多数情况下,它可以工作,但有时存储的 max(topic.date) - min(topic.date) 超过 1 小时(有时甚至会在几个小时内重叠 2 天)。知道这是怎么发生的吗?
    • 能否请您创建一个专门针对该问题的问题?带有查询和数据示例?谢谢!
    • 我找到了解决方案:在 Azure 流分析 Web 界面中的事件排序中:将重试策略设置为 drop
    • 好收获!如果您选择调整,延迟事件和乱序策略将更改时间戳(系统属性),但不会更改有效负载中的字段,因此您可以保留原始数据。
    猜你喜欢
    • 2017-09-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-01-20
    • 2015-05-02
    相关资源
    最近更新 更多