我正在尝试在 ASA(Azure 流分析)中编写查询,其中输入是如下所示的 json 行消息
{
"DeviceId": "Device3",
"DateTime": "2016-09-05T13:23:04.5444423",
"Value": [ 1, 0, 1, 0, 0, 1, 0 ]
}
我想要做的是执行 Unpivot,以便数据出现在表单中
create table LightBeacon (
DeviceId int primary key not null,
EventDateTime datetime not null,
LightBeaconId varchar(25) not null,
LightBeaconState SmallInt not null
)
但似乎 ASA 不支持 SQL Unpivot 功能,并且左侧有多个选择语句,例如
with
DataUnArray as (
SELECT DeviceId, DateTime as EventDateTime
, GetArrayElement(Value, 0) as LigthBeacon01
, GetArrayElement(Value, 1) as LigthBeacon02
, GetArrayElement(Value, 2) as LigthBeacon03
, GetArrayElement(Value, 3) as LigthBeacon04
, GetArrayElement(Value, 4) as LigthBeacon05
, GetArrayElement(Value, 5) as LigthBeacon06
, GetArrayElement(Value, 6) as LigthBeacon07
FROM DataIoT
where DeviceId = 'Device3'),
DataUnpivot as (
select DeviceId, EventDateTime, 'LigthBeacon01' as LigthBeaconId, LigthBeacon01 as LigthBeaconState from DataUnArray
Union All select DeviceId, EventDateTime, 'LigthBeacon02' as LigthBeaconId, LigthBeacon02 as LigthBeaconState from DataUnArray
Union All select DeviceId, EventDateTime, 'LigthBeacon03' as LigthBeaconId, LigthBeacon03 as LigthBeaconState from DataUnArray
Union All select DeviceId, EventDateTime, 'LigthBeacon04' as LigthBeaconId, LigthBeacon04 as LigthBeaconState from DataUnArray
Union All select DeviceId, EventDateTime, 'LigthBeacon05' as LigthBeaconId, LigthBeacon05 as LigthBeaconState from DataUnArray
Union All select DeviceId, EventDateTime, 'LigthBeacon06' as LigthBeaconId, LigthBeacon06 as LigthBeaconState from DataUnArray
Union All select DeviceId, EventDateTime, 'LigthBeacon07' as LigthBeaconId, LigthBeacon07 as LigthBeaconState from DataUnArray
)
select DeviceId, EventDateTime, LigthBeaconId, LigthBeaconState
into DataLakeCSV
from DataUnpivot
ASA 查询无法启动,并出现以下错误:
Stream Analytics job has validation errors: Job will exceed the maximum amount of Event Hub Receivers
如果我将其减少到 5 个信标 – 它就会起作用!!!那么如何编写可以在 unpivot 中处理超过 5 列的 ASA 查询?
\比约恩
最佳答案
不支持 UNPIVOT,但您可以使用 CROSS APPLY 和 GetRecordProperties 函数获得相同的结果:
WITH DataUnArray
AS (
SELECT DeviceId
,DATETIME AS EventDateTime
,GetArrayElement(Value, 0) AS LigthBeacon01
,GetArrayElement(Value, 1) AS LigthBeacon02
,GetArrayElement(Value, 2) AS LigthBeacon03
,GetArrayElement(Value, 3) AS LigthBeacon04
,GetArrayElement(Value, 4) AS LigthBeacon05
,GetArrayElement(Value, 5) AS LigthBeacon06
,GetArrayElement(Value, 6) AS LigthBeacon07
FROM DataIoT
WHERE DeviceId = 'Device3'
)
SELECT
event.DeviceId
,event.EventDateTime
,p.PropertyName AS LigthBeaconId,
p.PropertyValue AS LigthBeaconState
FROM DataUnArray event
CROSS APPLY GetRecordProperties(event) p
WHERE p.PropertyName LIKE 'ligthbeacon%'
关于azure - 流分析作业存在验证错误 : Job will exceed the maximum amount of Event Hub Receivers.,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39347310/