具有多个输入的Azure流分析查询

问题描述 投票:1回答:1

问题

我有一个Azure IoT-Hub将消息发送到Azure流分析作业。

每个消息都包含一个'NodeName'。我有一个表“ plcnext_nodes”,其中每个节点都有一个唯一的“ NodeId”及其对应的“ NodeName”。

我如何同时使用'plcnext_nodes'表的输入和IoT-Hub消息使用'NodeId'将事件数据存储在另一个SQL表中?

我想使用'NodeId'代替'NodeName',因为某些名称可能会变得很长,并且每条消息一遍又一遍地保存它们是浪费存储空间。


所需解决方案

我想解析以下来自IoT Hub的消息

{
    "NodeName": "ns=5;s=Arp.Plc.Eclr/DI2",
    "NodeDataType": "Boolean",
    "EventValue": 0,
    "EventMeasuredUtcTime": "2019-11-11T12:15:22.4830000Z",
    "EventProcessedUtcTime": "2019-11-11T12:41:57.1706596Z",
    "EventEnqueuedUtcTime": "2019-11-11T12:15:32.1260000Z",
    "IoTHub": {
        ...
    }
}

将'NodeName'与plcnext_nodes表中的那些进行比较,以获得适当的'NodeId':

NodeId  NodeName                 NodeDataType
---------------------------------------------
1       ns=5;s=Arp.Plc.Eclr/DI1  Boolean
2       ns=5;s=Arp.Plc.Eclr/DI2  Boolean
...

要获得以下输出并插入到[[plcnext_events表中:

NodeId EventValue EventMeasured ----------------------------------------------- 1 0 2019-11-11 12:15:22.4830000

查询

我已经在Azure流分析上尝试以下查询:

SELECT NodeId, EventValue, EventMeasuredUtcTime, EventEnqueuedUtcTime, EventProcessedUtcTime INTO [plcnext_events] FROM [plcnext_nodes], [iot_hub] WHERE [iot_hub].NodeName = [plcnext-nodes].NodeName

但是FROM中不支持JOIN,并且由于DATEDIFF的限制,我无法使用JOIN子句(plcnext_nodes表没有时间戳)

有没有办法做到这一点?

sql azure stream analytics
1个回答
0
投票
您可以在Stream Analytics中使用参考数据联接来联接表。

Using Reference Data for Lookups in Stream Analytics

参考数据(也称为查找表)是本质上是静态或缓慢变化的有限数据集,用于执行查找或扩充数据流。

根据您的情况,在Stream Analytics作业的

Inputs部分下,然后添加参考输入。您可以选择Blob存储或SQL数据库作为源。Add Reference Input

然后,您可以定义SQL查询以返回所需的参考数据。对于您的情况,您的参考数据查询将如下所示:

SELECT NodeId, NodeName, NodeDataType FROM dbo.plcnext-nodes

一旦在SA中定义了引用数据联接,请转到Stream Analytics中的

Query部分并更新查询。对于您的方案,您的查询将如下所示(使用JOIN):

SELECT pn.NodeId, hub.EventValue, hub.EventMeasuredUtcTime, hub.EventEnqueuedUtcTime, hub.EventProcessedUtcTime INTO [plcnext_events] FROM [iot_hub] hub JOIN [plcnext-nodes] pn ON pn.NodeName = hub.NodeName
© www.soinside.com 2019 - 2024. All rights reserved.