流分析 - 查询嵌套数组返回0结果

时间:2017-06-05 00:04:13

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

我有一系列消息;在每个消息中是另一个开始/停止值数组。我可以很好地获取消息数组,但是在Azure中执行流分析查询时,获取下一级嵌套的启动/停止值会返回0条记录。

以下是Stream Analytics查询。

WITH 
main AS
(
    SELECT          message.ArrayValue.header.messageId,
                    message.ArrayValue.startStopBlock as SSBlock                    

    FROM            IoTHub i
    CROSS APPLY     GetArrayElements(i.[STARTSTOPTIME:topic].message) AS 
message
)

SELECT              m.messageId,               
                    SSEntry.ArrayValue.start,
                    SSEntry.ArrayValue.stop

FROM            main m
CROSS APPLY     GetArrayElements(m.SSBLOCK.ArrayValue.startStop) AS SSEntry

这是json

{
	"@xsi:schemaLocation" : "",
	"nextBuffer" : {
		"url" : "",
		"moreData" : "false"
	},
	"message" : [{
			"header" : {
				"messageId" : "951262328",
			},
			"totalStartStops" : "2",
			"startStopBlock" : {
				"startStop" : [{
						"start" : "2017-05-16 14:11:01",
						"stop" : "2017-05-16 14:14:16",
						"operatorId" : "0"
					}, {
						"start" : "2017-05-16 14:38:45",
						"stop" : "2017-05-16 14:44:19",
						"operatorId" : "0"
					}
				]
			}
		}, {
			"header" : {
				"messageId" : "951266462",
			},
			"totalStartStops" : "2",
			"startStopBlock" : {
				"startStop" : [{
						"start" : "2017-05-16 14:08:09",
						"stop" : "2017-05-16 14:08:20",
						"operatorId" : "-1"
					}, {
						"start" : "2017-05-16 14:54:38",
						"stop" : "2017-05-16 15:01:17",
						"operatorId" : "-1"
					}
				]
			}
		}
	]
}

1 个答案:

答案 0 :(得分:0)

根据我的理解,您可以尝试通过将message.ArrayValue.startStopBlock as SSBlock更改为message.ArrayValue.startStopBlock.startStop as SSBlock来检索第一个查询中的嵌套数组。这是我的测试,你可以参考它:

<强>查询

WITH main AS
(
    SELECT  
      message.ArrayValue.header.messageId,
      message.ArrayValue.startStopBlock.startStop as SSBlock                    
    FROM IoTHub i
    CROSS APPLY GetArrayElements(i.message) AS message
)

SELECT
  m.messageId,               
  SSEntry.ArrayValue.start,
  SSEntry.ArrayValue.stop
FROM main m
CROSS APPLY GetArrayElements(m.SSBLOCK) AS SSEntry

<强>结果 enter image description here