使用Stream Analytics

时间:2016-06-16 07:00:14

标签: azure-stream-analytics

是否可以从Stream Analytics中的单个选项中动态输出多个记录?

例如,我按以下格式接收事件:

{
    "value": 600,
    "duration": 300
}

持续时间以秒为单位

如何使用持续时间的平均值输出每秒的记录?像下面这样的东西,只有300次?

SELECT 
    value / duration AS value
    1 AS duration
FROM Input

我认为返回数组记录也没问题,因为可以使用CROSS APPLY GetArrayElements将其转换为单独的事件

1 个答案:

答案 0 :(得分:0)

目前在Streaming Analytics查询语言中无法直接实现这一点 - 请继续关注即将推出的可扩展性改进。

您可以使用HoppingWindow生成常规事件(例如每秒),然后使用您的流加入以每秒生成事件,条件是它们不会超过传入事件之前的[持续时间]秒。

这样的事情:

WITH
InputWithTimestamp AS
(
    SELECT 
        System.Timestamp as timestamp, [value], [duration]
    FROM input 
),
RegularEvents AS
(
    SELECT
        System.Timestamp as timestamp, 
        count()
    FROM InputWithTimestamp
    GROUP BY HoppingWindow(second, 1000, 1) -- assuming at least one event arrives evry 1000 seconds
)

SELECT 
    RegularEvents.timestamp,
    InputWithTimestamp.value/InputWithTimestamp.[duration] as [value]

 FROM
    RegularEvents
JOIN
    InputWithTimestamp
ON DATEDIFF(second, RegularEvents, InputWithTimestamp) BETWEEN 0 AND 1000 -- assuming 1000 is max possible duration
AND DATEDIFF(second, RegularEvents.timestamp, InputWithTimestamp.timestamp) BETWEEN 0 AND InputWithTimestamp.[duration]