如何将 json 数据存储到 azure table 存储中,该存储应从单个 json 字符串添加为每一行?
How to store json data to azure table storage which should add as each row from a single json string?
我有以下格式的消息结构
{"deviceId":"D1","t":"2017-07-07T12:31:21Z","i1":"112.50","i2":"150.75","i3":"406.25","type":"Instant"}
我想做的是以下列格式将这些数据保存到 azure table 存储中
我可以将其添加到以 i1、i2、i3 作为列的一行中。但是我需要在指定的结构中使用它。
以下查询在流分析中用于将数据存储到 table 存储。这是工作。但是我需要额外的 table 来存储上面指定的数据。
SELECT
deviceId,
TRY_CAST(t AS datetime) as Row,
i1,
i2,
i3,
type
INTO
[iothubstorage]
FROM
[iotinput] timestamp by t
这是有效的。但是我需要额外的 table 来存储上面指定的数据。这可能吗?
您可以使用UNION 来合并3 行,下面的示例代码供您参考。我对其进行了测试,它在我这边运行良好。
With firstQueryResult AS (SELECT
CONCAT(TRY_CAST(deviceId as nvarchar(max)) , ' - i1') as PartitionKey,
t as RowKey,
TRY_CAST(t AS datetime) as TimeReceived,
CONCAT(TRY_CAST(deviceId as nvarchar(max)) , ' - i1') as deviceId,
'i1' as Input,
i1 as Value FROM [iotinput]
UNION
SELECT
CONCAT(TRY_CAST(deviceId as nvarchar(max)) , ' - i2') as PartitionKey,
t as RowKey,
TRY_CAST(t AS datetime) as TimeReceived,
CONCAT(TRY_CAST(deviceId as nvarchar(max)) , ' - i2') as deviceId,
'i2' as Input,
i2 as Value FROM [iotinput]
UNION
SELECT
CONCAT(TRY_CAST(deviceId as nvarchar(max)) , ' - i3') as PartitionKey,
t as RowKey,
TRY_CAST(t AS datetime) as TimeReceived,
CONCAT(TRY_CAST(deviceId as nvarchar(max)) , ' - i3') as deviceId,
'i3' as Input,
i3 as Value FROM [iotinput])
SELECT * INTO
[iothubstorage] FROM firstQueryResult
我有以下格式的消息结构
{"deviceId":"D1","t":"2017-07-07T12:31:21Z","i1":"112.50","i2":"150.75","i3":"406.25","type":"Instant"}
我想做的是以下列格式将这些数据保存到 azure table 存储中
我可以将其添加到以 i1、i2、i3 作为列的一行中。但是我需要在指定的结构中使用它。 以下查询在流分析中用于将数据存储到 table 存储。这是工作。但是我需要额外的 table 来存储上面指定的数据。
SELECT
deviceId,
TRY_CAST(t AS datetime) as Row,
i1,
i2,
i3,
type
INTO
[iothubstorage]
FROM
[iotinput] timestamp by t
这是有效的。但是我需要额外的 table 来存储上面指定的数据。这可能吗?
您可以使用UNION 来合并3 行,下面的示例代码供您参考。我对其进行了测试,它在我这边运行良好。
With firstQueryResult AS (SELECT
CONCAT(TRY_CAST(deviceId as nvarchar(max)) , ' - i1') as PartitionKey,
t as RowKey,
TRY_CAST(t AS datetime) as TimeReceived,
CONCAT(TRY_CAST(deviceId as nvarchar(max)) , ' - i1') as deviceId,
'i1' as Input,
i1 as Value FROM [iotinput]
UNION
SELECT
CONCAT(TRY_CAST(deviceId as nvarchar(max)) , ' - i2') as PartitionKey,
t as RowKey,
TRY_CAST(t AS datetime) as TimeReceived,
CONCAT(TRY_CAST(deviceId as nvarchar(max)) , ' - i2') as deviceId,
'i2' as Input,
i2 as Value FROM [iotinput]
UNION
SELECT
CONCAT(TRY_CAST(deviceId as nvarchar(max)) , ' - i3') as PartitionKey,
t as RowKey,
TRY_CAST(t AS datetime) as TimeReceived,
CONCAT(TRY_CAST(deviceId as nvarchar(max)) , ' - i3') as deviceId,
'i3' as Input,
i3 as Value FROM [iotinput])
SELECT * INTO
[iothubstorage] FROM firstQueryResult