流分析 - 处理 JSON 没有数组名称

Stream analytics - Pocessing JSON with no array name

我想使用包含 CROSS APPLY GetArrayElements() 的流分析查询将此数组转换为行,但此函数需要数组名称。显然没有名字。有什么建议吗?

要解析的 JSON 示例:

{
  "Alert1": {
    "Site": "11109370",
    "Sensor": "UPS",
    "Event": "Load Not Protected",
    "Time": "08-28-2019 10:39:02",
    "Value": "0",
    "Threshold": 0,
    "Severity": "2",
    "Status": "Open"
  },
  "Alert2": {
    "Site": "11109370",
    "Sensor": "UPS",
    "Event": "Emergency stop",
    "Time": "08-28-2019 10:39:02",
    "Value": "1",
    "Threshold": 1,
    "Severity": "2",
    "Status": "Open"
  },
  "Alert3": {
    "Site": "11109370",
    "Sensor": "UPS",
    "Event": "Load Protected(UPS Coupled)",
    "Time": "08-28-2019 10:39:02",
    "Value": "0",
    "Threshold": 0,
    "Severity": "1",
    "Status": "Open"
  },
  "Alert4": {
    "Site": "11109370",
    "Sensor": "UPS",
    "Event": "Battery Deep Discharge Protection",
    "Time": "08-28-2019 10:39:02",
    "Value": "0",
    "Threshold": 0,
    "Severity": "1",
    "Status": "Open"
  },
  "Alert5": {
    "Site": "11109370",
    "Sensor": "UPS",
    "Event": "Battery Present",
    "Time": "08-28-2019 10:39:02",
    "Value": "0",
    "Threshold": 0,
    "Severity": "1",
    "Status": "Open"
  },
  "Alert6": {
    "Site": "11109370",
    "Sensor": "UPS",
    "Event": "Sensor Communication Error",
    "Time": "08-28-2019 10:39:02",
    "Status": "Close"
  }
}

我尝试了下面的代码,但遇到了错误:

错误:列名无效:'arrayvalue'。具有该名称的列不存在。

SELECT message.ArrayValue
FROM INPUT as event
CROSS APPLY GetRecordProperties(event) AS message

你的方向是正确的,但是,我认为你在 GetRecordProperties 函数的用法上犯了一个小错误。

请看官方文档中的example,不是任何ArrayValue属性:

SELECT   
    recordProperty.PropertyName,  
    recordProperty.PropertyValue  
FROM input as event  
CROSS APPLY GetRecordProperties(event.recordField) AS recordProperty  

根据您的情况,您可以执行以下 sql:

SELECT   
    recordProperty.PropertyName,  
    recordProperty.PropertyValue  
FROM input as event  
CROSS APPLY GetRecordProperties(event) AS recordProperty  

输出:

我问过你想如何处理 Alert1,Alert2 属性,如果你想摆脱它们,请使用下面的 sql:

SELECT    
    recordProperty.PropertyValue.Site,  recordProperty.PropertyValue.Sensor....<more your columns>
FROM input as event  
CROSS APPLY GetRecordProperties(event) AS recordProperty  

输出: