Azure流分析查询JSON

时间:2017-12-18 14:49:03

标签: json azure azure-stream-analytics

编写查询以从json文件中提取数组中的表时出现问题:问题是如何获取数组“clientPerformance”的信息,然后将它们全部放在普通的sql表中。

该文件如下所示:

"clientPerformance":[  
        {  
         "name":"opportunity",
         "clientProcess":{  
            "value":3620000.0,
            "count":1.0,
            "min":3620000.0,
            "max":3620000.0,
            "stdDev":0.0,
            "sampledValue":3620000.0
         },
         "networkConnection":{  
            "value":10000.0,
            "count":1.0,
            "min":10000.0,
            "max":10000.0,
            "stdDev":0.0,
            "sampledValue":10000.0
         },
         "receiveRequest":{  
            "value":9470000.0,
            "count":1.0,
            "min":9470000.0,
            "max":9470000.0,
            "stdDev":0.0,
            "sampledValue":9470000.0
         },
         "sendRequest":{  
            "value":1400000.0,
            "count":1.0,
            "min":1400000.0,
            "max":1400000.0,
            "stdDev":0.0,
            "sampledValue":1400000.0
         },
         "total":{  
            "value":14500000.0,
            "count":1.0,
            "min":14500000.0,
            "max":14500000.0,
            "stdDev":0.0,
            "sampledValue":14500000.0
         },
         "url":"https://xxxx",
         "urlData":{  
            "base":"/main.aspx",
            "host":"xxxx",
            "hashTag":"",
            "protocol":"https"
         }
      }
   ]

我尝试使用Get数组元素方法和其他方法,但我永远无法访问clientProcess,networkConnection .. elements

我试图用这个例子来代替:

Select 
GetRecordPropertyValue(GetArrayElement(Input.clientPerformance, 0), 'name') AS Name,
GetRecordPropertyValue(GetArrayElement(Input.clientPerformance, 1), 'clientProcess.count') AS clientProcessCount,
FROM [app-insights-blob-dev] Input 

我将不胜感激任何帮助:)

1 个答案:

答案 0 :(得分:1)

我稍微编辑了您的查询以返回clientProcessCount。 (我将数组索引从1更改为0)。还要确保您的JSON对象以{并以}结尾。

开头
Select
GetRecordPropertyValue(GetArrayElement(Input.clientPerformance, 0), 'name') AS Name,
GetRecordPropertyValue(GetArrayElement(Input.clientPerformance, 0), 'clientProcess.count') AS clientProcessCount
FROM [app-insights-blob-dev] Input

对于使用ASA查询复杂对象的其他示例,请不要犹豫,查看此blog post