1

我想使用包含 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
4

1 回答 1

0

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

请看官方文档中的例子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  

输出:

在此处输入图像描述

于 2019-08-29T07:28:12.350 回答