简体   繁体   中英

Azure Stream Analytics - How to save data for more than one IoT device in Azure SQL db

I am able to save data for one running IoT device in Azure SQL DB but not able to understand how to save data in Azure SQL DB for data coming from more than 1 IoT device using stream analytics, the data can be different. For example - Device1 may produce temperature, humidity and Device2 may produce torque, pressure

I have used the stream analytics preview feature in Azure SQL DB. I didn't want to create a schema for the table because I'm not sure what kind of data will be coming from different IoT devices.

The most basic way to proceed here is the following one:

WITH 
TempInput AS (SELECT DeviceId, 'Temperature' AS sensorName, Temperature AS sensorValue FROM Input WHERE DeviceType = 'A'),

HumidityInput AS  (SELECT DeviceId, 'Humidity' AS sensorName, Humidity AS sensorValue FROM Input WHERE DeviceType = 'A'),

TorqueInput AS (SELECT DeviceId, 'Torque' AS sensorName, Torque AS sensorValue FROM Input WHERE DeviceType = 'B'),

PressureInput AS  (SELECT DeviceId, 'Pressure' AS sensorName, Pressure AS sensorValue FROM Input WHERE DeviceType = 'B')

UnionOutput AS (
SELECT DeviceId, sensorName, sensorValue FROM TempInput 
UNION
SELECT DeviceId, sensorName, sensorValue FROM HumidityInput
UNION
SELECT DeviceId, sensorName, sensorValue FROM TorqueInput 
UNION
SELECT DeviceId, sensorName, sensorValue FROM PressureInput
)

SELECT *
INTO Output
FROM UnionOutput 

So this scenario is supported, but the query pattern above can't really be generalized until we know more about the actual schemas involved. We have smarter ways to parse and pivot data that may be applicable in your specific case. It's important to have more details both in terms of input (CSV, JSON, how are fields nested or not, arrays) and output. We have a good doc on general patterns , but also parsing JSON data that can help.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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