Azure流分析 - 编译查询失败

时间:2015-11-16 16:34:38

标签: azure azure-stream-analytics

当我尝试使用最后一个函数(https://msdn.microsoft.com/en-us/library/azure/mt421186.aspx)时。我收到以下错误:

  

编译查询失败。

SELECT
    deviceId
    ,System.TimeStamp as timestamp
    ,avg(events.externaltemp) as externaltemp
    ,LAST(System.Timestamp) OVER (PARTITION BY deviceId LIMIT DURATION(second, 1) when [externaltemp] is not null ) as Latest
INTO
    [powerBI]
FROM
    [EventHub] as events timestamp by [timestamp]

GROUP BY deviceId, TumblingWindow(second,1)

我的上一个函数看起来与msdn示例中的函数非常相似,所以我不确定为什么会出现问题。

1 个答案:

答案 0 :(得分:1)

您在查询中使用[externaltemp],但它不包括在分组中。这就是原因。并且"最后"函数不允许聚合在其中,所以下面也不会起作用

LAST(System.Timestamp) OVER (PARTITION BY deviceId LIMIT DURATION(second, 1) when avg([externaltemp]) is not null ) as Latest

可以通过将查询分为两个步骤来实现,例如

with DeviceAggregates
as
(
SELECT
    System.TimeStamp as [Timestamp],
    deviceId,
    avg(events.externaltemp) as [externaltemp]
FROM
    [EventHub] as events timestamp by [timestamp]
GROUP BY 
    deviceId, 
    TumblingWindow(second,1)
),

DeviceAggregatesWithLast as
(
select 
    *,
    last([Timestamp]) over (partition by deviceId limit duration(second,1) when [externaltemp] is not null) [LastTimeThereWasANonNullTemperature] 
from 
    DeviceAggregates
)


select * 
INTO
    [powerBI]
from
    DeviceAggregatesWithLast