我想使用包含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
答案 0 :(得分:0)
您的方向是正确的,但是,我认为您在使用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
输出: