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

@Plan:description('Calculate the total network usage of mobile data and others')

@Import('iot.per.device.stream.android.data:1.0.0')
define stream DataStream (meta_owner string, meta_deviceId string, meta_timestamp long, type string, received long, sent long);

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

partition with (meta_deviceId of DataStream)
begin
    from DataStream
    select meta_owner, meta_deviceId, meta_timestamp, type, (received + sent) as total, 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 DataStatsStream;
end;