2016-06-16 78 views
0

是否可以通過Stream Analytics中的單個選擇動態輸出多個記錄?通過Stream Analytics輸出單個選擇的多條記錄

例如,我收到事件的格式如下:

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

持續時間以秒爲

我怎麼能輸出每秒與持續時間的平均值的記錄?像下面的東西,只有300倍?

SELECT 
    value/duration AS value 
    1 AS duration 
FROM Input 

返回一個數組記錄將被罰款以及我想,因爲有可能使用CROSS APPLY GetArrayElements

回答

0

這今天是不能直接在流分析查詢語言將其轉換成單獨的事件 - 敬請期待用於即將到來的可擴展性改進。

您可能可以使用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]