简体   繁体   English

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

[英]Azure Stream Analytics query with multiple inputs

Issue问题

I have a Azure IoT-Hub sending messages to a Azure Stream Analytics Job.我有一个 Azure IoT-Hub 向 Azure Stream 分析作业发送消息。

Each message contains a 'NodeName'.每条消息都包含一个“NodeName”。 I have a table 'plcnext_nodes' which has a unique 'NodeId' for each node with their corresponding 'NodeName'.我有一个表“plcnext_nodes”,每个节点都有一个唯一的“NodeId”及其对应的“NodeName”。

How can I use both the input from the 'plcnext_nodes' table and the IoT-Hub messages to store the event data in another SQL table using the 'NodeId'?如何使用“plcnext_nodes”表中的输入和 IoT-Hub 消息来使用“NodeId”将事件数据存储在另一个 SQL 表中?

I want to use the 'NodeId' instead of the 'NodeName' because some names can get very long and saving them over and over with each message is a waste of storage.我想使用“NodeId”而不是“NodeName”,因为某些名称可能会变得很长,并且在每条消息中一遍又一遍地保存它们会浪费存储空间。


Desired solution所需的解决方案

I would like to parse the following message from the IoT Hub :我想解析来自 IoT 中心的以下消息

{
    "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": {
        ...
    }
}

Compare the 'NodeName' with those in the plcnext_nodes table to get the appropriate 'NodeId':将“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
...

To get the following output and insert into the plcnext_events table:要获取以下 output 并插入到plcnext_events表中:

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

Query询问

I have tried the following query on Azure Stream Analytics:我在 Azure Stream Analytics 上尝试了以下查询:

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

But JOIN is not supported in FROM and I haven't been able to use a JOIN clause because of it's DATEDIFF restriction (The plcnext_nodes table has no timestamps)但是 FROM 不支持 JOIN 并且我无法使用 JOIN 子句,因为它有 DATEDIFF 限制(plcnext_nodes 表没有时间戳)

Is there a way to achieve this?有没有办法做到这一点?

You can use a Reference Data JOIN in Stream Analytics to join tables.您可以使用 Stream Analytics 中的参考数据联接来联接表。

Using Reference Data for Lookups in Stream Analytics 在 Stream Analytics 中使用参考数据进行查找

Reference data (also known as a lookup table) is a finite data set that is static or slowly changing in nature, used to perform a lookup or to augment your data streams.参考数据(也称为查找表)是一个有限数据集,即 static 或性质缓慢变化的数据集,用于执行查找或扩充数据流。

In your case, go under the Inputs section in your Stream Analytics job and add a Reference Input.在您的情况下,go 在 Stream 分析作业的输入部分下,并添加参考输入。 You can select either Blob Storage or SQL Database as your source.您可以将 select Blob StorageSQL 数据库作为您的源。 添加参考输入

You can then define your SQL query to return the reference data you need.然后,您可以定义您的 SQL 查询以返回您需要的参考数据。 For your case, your reference data query would look like this:对于您的情况,您的参考数据查询将如下所示:

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

Once you define your reference data join in SA, go to the Query section in Stream Analytics and update your query.在 SA 中定义参考数据联接后,go 到 Stream Analytics 中的查询部分并更新您的查询。 For your scenario your query would look like this (with the JOIN):对于您的场景,您的查询将如下所示(使用 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

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

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