@Plan:name('Android-Pressure-ExecutionPlan')

@Plan:description('Process pressure changes.')

@Import('iot.per.device.stream.android.pressure:1.0.0')
define stream PressureStream (meta_owner string, meta_deviceId string, meta_timestamp long, pressure float);

@Export('iot.per.device.stream.android.pressure.stats:1.0.0')
define stream PressureStatsStream (meta_owner string, meta_deviceId string, meta_timestamp long, pressure float, year int,
month int, day int, hour int, minute int);

partition with (meta_deviceId of PressureStream)
begin
    from PressureStream
    select meta_owner, meta_deviceId, meta_timestamp, pressure, time:extract
    (meta_timestamp, 'year') as year, time:extract(meta_timestamp, 'month') as month, time:extract(meta_timestamp, 'day') as day, time:extract(meta_timestamp, 'hour') as hour, time:extract(meta_timestamp, 'minute') as minute
    insert into PressureStatsStream;
end;