简体   繁体   English

Azure流分析中具有不同架构的多个警报联合

[英]Multiple alerts union with varying schema in Azure Stream Analytics

I have an EventHub which receives events with JSON K/V pairs that can vary. 我有一个EventHub,它接收的JSON K / V对事件可能有所不同。 What I want to do is run a single Stream Analytics job, and create multiple alerts while preserving all the K/V pairs in the result. 我要做的是运行一个Stream Analytics作业,并创建多个警报,同时保留结果中的所有K / V对。 For example, events like this might be seen: 例如,可能会看到类似这样的事件:

{"temp1": 45, "temp2": 60, "source": "sensor-a"},
{"temp1": 37, "temp2": 50, "humidity": 17, "source": "new-sensor"}

I'm using humidity as an example, but the point is the keys vary. 我以湿度为例,但要点是按键有所不同。

One way that would work is if I could just run multiple select statements with my various WHERE clauses. 一种可行的方法是,只要我可以使用各种WHERE子句运行多个select语句。

SELECT *, ALERT='Temp LOW' FROM [input] WHERE temp1 < 15
UNION
SELECT *, ALERT='Humidity HIGH' FROM [input] WHERE humidity > 50

But this won't work because SELECT * in ASA is not allowed with UNION. 但这将不起作用,因为UNION不允许ASA中的SELECT * One way this could work is if the original data could be returned as a child named 'raw_data', for example. 例如,如果原始数据可以作为名为“ raw_data”的子级返回,则可能会起作用。 I'm not sure how / if I can make that happen. 我不确定如何/是否可以实现这一目标。 I need the other K/V pairs but I cannot know all the key names. 我需要其他K / V对,但我不知道所有的键名。

With the raw data as a child, the result might look like this: 将原始数据作为子级,结果可能如下所示:

{"ALERT": "Humidity HIGH", "raw_data":
  {"temp1": 33, "temp2": 52, "humidity": 60, "source": "sensorname", "otherkey": "value"}
}

One thing I thought might work is I could use a WITH statement to generate the ALERT field, and then use a JOIN to add to the event stream. 我认为可能起作用的一件事是,我可以使用WITH语句生成ALERT字段,然后使用JOIN添加到事件流中。 I could generate a UUID for each event to JOIN ON. 我可以为每个事件生成一个UUID来加入。 I haven't been able to figure this out yet. 我还无法弄清楚。

Is there any way to do either returning the original event as a child in JSON, or to do the JOIN method to add the ALERT field? 有什么方法可以将原始事件作为JSON中的子级返回,也可以通过JOIN方法添加ALERT字段吗?

Yes, you can make the nested record option work (where the original event is a child record in the result). 是的,您可以使嵌套记录选项起作用(原始事件是结果中的子记录)。

Here is modified example query from your question: 这是您的问题的修改示例查询:

SELECT raw_data=[input], ALERT='Temp LOW' FROM [input] WHERE temp1 < 15
UNION
SELECT raw_data=[input], ALERT='Humidity HIGH' FROM [input] WHERE humidity > 50

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM