2015-11-16 102 views
0

當我嘗試使用最後一個函數(https://msdn.microsoft.com/en-us/library/azure/mt421186.aspx)。我得到以下錯誤:Azure流分析 - 編譯查詢失敗

Compiling query failed.

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樣品中,所以我不知道爲什麼有問題。

+0

我已經嘗試更改爲一個小於語句爲空,但沒有任何效果。我正在努力確定這是什麼問題。 –

回答

1

您正在查詢中使用[externaltemp],但它不包含在group by中。這就是原因。而「最後一個」功能不允許在它裏面聚集,所以下面就不會工作,以及

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