我的流分析查询存在语法问题。以下是我的Stream Analytics查询,我试图从事件中获取以下字段:
非工作查询
SELECT input.vehicleId,
FUEL_DIFF = LAG(input.Payload.FuelLevel) OVER (PARTITION BY vehicleId LIMIT DURATION(minute, 1)) - input.Payload.FuelLevel,
ODO_DIFF = input.Payload.OdometerValue - LAG(input.Payload.OdometerValue) OVER (PARTITION BY input.vehicleId LIMIT DURATION(minute, 1))
from input
以下是一个示例输入事件,上面的查询/作业在一系列事件上运行:
{
"IoTDeviceId":"DeviceId_1",
"MessageId":"03494607-3aaa-4a82-8e2e-149f1261ebbb",
"Payload":{
"TimeStamp":"2017-01-23T11:16:02.2019077-08:00",
"FuelLevel":19.9,
"OdometerValue":10002
},
"Priority":1,
"Time":"2017-01-23T11:16:02.2019077-08:00",
"VehicleId":"MyCar_1"
}
运行Stream Analytics作业时会抛出以下语法错误:
列名无效:'有效负载'。具有此类名称的列不存在。
具有讽刺意味的是,以下查询可以正常运行:
工作查询
SELECT input.vehicleId,
FUEL_DIFF = LAG(input.Payload.FuelLevel) OVER (PARTITION BY vehicleId LIMIT DURATION(second, 1)) - input.Payload.FuelLevel
from input
WORKING QUERY和NON-WORKING QUERY之间唯一的区别是使用的LAG结构的数量。非工作查询有两个LAG结构,而WORKING QUERY只有一个LAG结构。
我参考了流分析查询语言,它们只有基本的例子。还试图查看多个博客。另外,我尝试过使用 GetRecordPropertyValue ()函数,但没有运气。请建议。
提前感谢您!
答案 0 :(得分:0)
这看起来确实是语法错误。感谢您的报告 - 我们将在即将发布的更新中修复它。
请考虑将此查询用作解决方法:
WITH Step1 AS
(
SELECT vehicleId, Payload.FuelLevel, Payload.OdometerValue
FROM input
)
SELECT vehicleId,
FUEL_DIFF = LAG(FuelLevel) OVER (PARTITION BY vehicleId LIMIT DURATION(minute, 1)) - FuelLevel,
ODO_DIFF = OdometerValue - LAG(OdometerValue) OVER (PARTITION BY vehicleId LIMIT DURATION(minute, 1))
from Step1