我有一个json文件如下:
{" imei":{" imei":" 358174069248418F"," imeiBinary":" NYF0BpJIQY8 =&#34 ;," imeiNotEncoded":" 358174069248418","有效":1}," dataPackets":[[" msy.mxp .datapacket.AlarmNotification",{" version":1," id":21," op":2," sizeDynamic" :0," alarmStatus":4}],[" msy.mxp.datapacket.IOStatus",{"版本":1," id&# 34 ;: 15," op":2," sizeDynamic":0," ioStatus":135," ioDirections":120}] ,[" msy.mxp.datapacket.LogicalStatus",{" version":1," id":16," op":2 ," sizeDynamic":0," logicalStatus":5}],[" msy.mxp.datapacket.Position",{" version" :1," id":19," op":2,"纬度":40.835243,"经度":14.246057,&#34 ;海拔高度":40,"速度":0,"当然":68," gpsNumSatellite":5," glonassNumSatellite": 1," fixValid":1, " timeValid":1," wgs84degMinFormat":1," glonass":1," fixMode":3," timestamp&# 34;:{" timeSecFrom1Gen2000":925560202," time":1490648755000}," sizeDynamic":0}]]}
我正在通过以下查询阅读:
WITH Datapackets AS
(
SELECT imei.imei as imei,
persistent as persistent,
[timestamp].[time] as input_time,
compressed as compressed,
GetArrayElement(dataPackets, 3) as position
FROM h24
), one as(
SELECT *,
GetRecordPropertyValue (GetArrayElement(position,1), 'timestamp') as position_timestamp --1st
from Datapackets
), two as (
select
imei,
GetRecordPropertyValue (GetArrayElement(position,1), 'op') as position_OP,
[position_timestamp].[time] as position_time,
dateadd(S, [position_timestamp].[timeSecFrom1Gen2000], '1970-01-01') as timing,
GetRecordPropertyValue (GetArrayElement(position,1), 'latitude') as position_latitude,
GetRecordPropertyValue (GetArrayElement(position,1), 'longitude') as position_longitude,
GetRecordPropertyValue (GetArrayElement(position,1), 'altitude') as position_altitude,
GetRecordPropertyValue (GetArrayElement(position,1), 'speed') as position_speed
from one) SELECT * from two
现在我想让窗口翻滚组按照以下30秒进行,但是我有一个问题告诉我输入文件不允许使用timestamp属性" 2" ,,这里是我使用的查询
WITH Datapackets AS
(
SELECT imei.imei as imei,
persistent as persistent,
[timestamp].[time] as input_time,
compressed as compressed,
GetArrayElement(dataPackets, 3) as position
FROM h24
), one as(
SELECT *,
GetRecordPropertyValue (GetArrayElement(position,1), 'timestamp') as position_timestamp --1st
from Datapackets
), two as (
select
imei,
GetRecordPropertyValue (GetArrayElement(position,1), 'op') as position_OP,
[position_timestamp].[time] as position_time,
dateadd(S, [position_timestamp].[timeSecFrom1Gen2000], '1970-01-01') as timing,
GetRecordPropertyValue (GetArrayElement(position,1), 'latitude') as position_latitude,
GetRecordPropertyValue (GetArrayElement(position,1), 'longitude') as position_longitude,
GetRecordPropertyValue (GetArrayElement(position,1), 'altitude') as position_altitude,
GetRecordPropertyValue (GetArrayElement(position,1), 'speed') as position_speed
from one) SELECT imei, System.TimeStamp AS 'start', Avg(position_speed), max(position_latitude)
FROM two TIMESTAMP BY TIMING GROUP BY imei, TumblingWindow(duration(second, 30))
错误出现在最后两行(FROM TIMESTAMP BY TIMING),
**************更新,经过调查后,我发现我只能在输入中使用选项timestamp,而且只有在我做的时候我才能使用它为事件定制时间戳。通常,它们会按到达时间加上时间戳作为默认值(https://msdn.microsoft.com/en-us/library/mt573293.aspx)
现在我的问题是如何使用记录在Json文件中的第3级数组中的时间字段为我的事件添加时间戳,以便能够进行聚合。
有关我如何处理此问题的任何建议,谢谢
答案 0 :(得分:1)
根据https://msdn.microsoft.com/en-us/library/mt598501.aspx TIMESTAMP BY
只能用于输入来源,因此您可以将其作为第一步的一部分:
WITH Datapackets AS
...
FROM h24 TIMESTAMP BY (expression)
...
此外,来自同一来源,在窗口上与System.TimeStamp
一起使用时引用GROUP BY
:
聚合结果的时间戳是此结果对应的时间窗口的结尾。
因此,当您在最终System.TimeStamp
语句中编写SELECT
时,它会引用当前窗口的结尾。