Reputation: 19
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.
Upvotes: 0
Views: 173
Reputation: 842
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.
Upvotes: 0