如何在Stream分析中查询JSON以取消包含多个数组值的JSON

时间:2018-05-03 17:05:47

标签: json azure-sql-database azure-stream-analytics

我想在流分析

中查询从IotHub收到的JSON输入数据
{
            "DeviceId": "12355",
            "Message": {
                        "TimeStamp": [{"Time": "1"}, {"Time": "2"}],
                        "Streak": "4",
                        "Checkin": [{"Time": "3"}, {"Time": "4"}],
                        "Status": ""
            }
}

我使用了下面的查询,它在应用交叉后给了我四个输出我只想要两个输出

我希望我的输出格式如下。

DeviceID    Streak  TimeStamp   Checkin  Status
  "12355"   "4"     "1"         "3"      ""
  "12355"   "4"     "2"         "4"      ""

这是我使用Cross Apply

编写的查询
SELECT
 [Stat].[DeviceId] AS [DeviceId],

 [Stat].[Message].[Streak] AS [Streak],
 [Stat].[Message].[Status] AS [Status],
 [Stat].[Message].[Error] AS [Error],
 [Stat].[UseTime].[Time] AS [Checkin],
 [Stat].[Open].[Time] AS [OpenTime]
 INTO
 Messages
FROM
(
 SELECT
 [EventAlias].*,
 [Checkin].[ArrayValue] AS [UseTime],
[OutputTime].[ArrayValue] AS [Open]
 FROM [SmartCapData] AS [EventAlias]
 CROSS APPLY GetArrayElements(EventAlias.Message.Checkin) AS [Checkin]
 CROSS APPLY GetArrayElements(EventAlias.Message.Timestamp) AS [OutputTime]
) AS Stat

在上面它是跨越十字架我想并行使用它, 在此先感谢:)

0 个答案:

没有答案