【问题标题】:Stream Analytics job has validation errors: Job will exceed the maximum amount of Event Hub Receivers.流分析作业存在验证错误:作业将超过事件中心接收器的最大数量。
【发布时间】:2017-01-13 19:28:09
【问题描述】:

我正在尝试在 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 查询未能启动并出现以下错误:

流分析作业存在验证错误:作业将超过 事件中心接收器的最大数量

如果我将它减少到 5 个信标——它会起作用!!!那么如何编写一个可以在一个 unpivot 中处理超过 5 列的 ASA 查询呢?

\比约恩

【问题讨论】:

    标签: azure iot unpivot azure-stream-analytics


    【解决方案1】:

    不支持 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%'
    

    【讨论】:

    • 它有效 - 完美。我使用 GetArrayElements 重写了代码 - 这使它变得更简单而且更强大。
    猜你喜欢
    • 1970-01-01
    • 2022-11-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-03-29
    • 1970-01-01
    相关资源
    最近更新 更多