流分析 - 将窗口中的多个单独记录传递到UDF

时间:2017-05-20 13:36:46

标签: azure azure-stream-analytics

我想在一个设置窗口中传递多个单独的记录(可以翻滚,跳跃,滑动),而不会像这样聚合到javascript UDF中:

输入数据是:

{ "device":"A", "temp":20.0, "humidity":0.9, "param1": 83}
{ "device":"A", "temp":22.0, "humidity":0.9, "param1": 63}
{ "device":"B", "temp":15.0, "humidity":0.5, "param1": 13}
{ "device":"A", "temp":22.0, "humidity":0.5, "param1": 88}
{ "device":"A", "temp":22.0, "humidity":0.5, "param1": 88}

将指定窗口中的记录作为对象数组传递:

function process_records(record_array) {
   //access individual records
   record_one_device = records[0].device
   record_two_device = records[1].device
   record_three_device = records[2].device
   ...
}

感谢您的帮助!

1 个答案:

答案 0 :(得分:0)

根据您的要求,我假设您可以利用Azure Stream Analytics中的Collect聚合功能。这是我的测试,你可以参考它:

<强>输入

[  
    {
        "Make": "Honda",
        "Time": "2015-01-01T00:00:01.0000000Z",
        "Weight": 1000
    }, 
    {
        "Make": "Honda",
        "Time": "2015-01-01T00:00:03.0000000Z",
        "Weight": 3000
    },
    {
        "Make": "Honda",
        "Time": "2015-01-01T00:00:12.0000000Z",
        "Weight": 2000
    }, 
    {
        "Make": "Honda",
        "Time": "2015-01-01T00:00:52.0000000Z",
        "Weight": 1000
    }
]

通过以下查询,我可以检索时间窗口中包含的数据,如下所示:

SELECT
    Make,
    System.TimeStamp AS Time,
    Collect() AS records
FROM
    Input TIMESTAMP BY Time
GROUP BY
    Make,
    HoppingWindow(second, 10,10)

enter image description here

然后,您可以在查询中调用UDF.processRecords(Collect())。有关详情,请参阅common Stream Analytics usage patternsAzure Stream Analytics UDF以及Stream Analytics Window functions