问题
我有一个Azure IoT-Hub将消息发送到Azure流分析作业。
每条消息都包含一个“ nodename”。 我有一个表“ plcnext_nodes”,其中每个节点都有一个唯一的“ NodeId”及其对应的“ nodename”。
如何使用“ plcnext_nodes”表中的输入和IoT-Hub消息使用“ NodeId”将事件数据存储在另一个SQL表中?
我想使用“ NodeId”代替“ nodename”,因为某些名称可能会变得很长,并且每条消息一遍又一遍地保存它们是浪费存储空间。
所需解决方案
我想从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": {
...
}
}
将“ nodename”与 plcnext_nodes 表中的“ nodename”进行比较,以获取适当的“ 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限制(plcnext_nodes表没有时间戳),所以我无法使用JOIN子句