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

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

@Import('iot.per.device.stream.android.gravity:1.0.0')
define stream GravityStream (meta_owner string, meta_deviceId string, meta_timestamp long, x float, y float, z float);

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

partition with (meta_deviceId of GravityStream)
begin
    from GravityStream
    select meta_owner, meta_deviceId, meta_timestamp, x, y, z, 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 GravityStatsStream;
end;