set  hive.exec.dynamic.partition.mode=nonstrict;
set  hive.exec.dynamic.partition=true;
set mapred.max.split.size=536870912;
set mapred.min.split.size.per.node=536870912;
set mapred.min.split.size.per.rack=536870912;
set mapreduce.map.memory.mb=4000;
set mapreduce.map.java.opts=-Xmx3000m;
set mapreduce.reduce.memory.mb=3072;
set mapreduce.reduce.java.opts=-Xmx2458m;
set hive.jobname.length=100;

-- laxin
insert overwrite table dwh.gdt_data partition(day='${dt_today}',category='alipay_lahuo_laxin_delete',business='laxin_0')
      select t2.device_id
      from
      (select device_id from dwh.gdt_data
      where day='${dt_today}' and category='alipay_lahuo_laxin' and business='laxin_0') t1
      right join
      (select device_id  from dwh.gdt_data
      where day='${dt_yesterday}'  and category='alipay_lahuo_laxin' and business='laxin_0') t2
      on t1.device_id=t2.device_id
      where t1.device_id is null;

insert overwrite table dwh.gdt_data partition(day='${dt_today}',category='alipay_lahuo_laxin_delete',business='laxin_1')
      select t2.device_id
      from
      (select device_id from dwh.gdt_data
      where day='${dt_today}' and category='alipay_lahuo_laxin' and business='laxin_1') t1
      right join
      (select device_id  from dwh.gdt_data
      where day='${dt_yesterday}'  and category='alipay_lahuo_laxin' and business='laxin_1') t2
      on t1.device_id=t2.device_id
      where t1.device_id is null;

insert overwrite table dwh.gdt_data partition(day='${dt_today}',category='alipay_lahuo_laxin_delete',business='laxin_2')
      select t2.device_id
      from
      (select device_id from dwh.gdt_data
      where day='${dt_today}' and category='alipay_lahuo_laxin' and business='laxin_2') t1
      right join
      (select device_id  from dwh.gdt_data
      where day='${dt_yesterday}'  and category='alipay_lahuo_laxin' and business='laxin_2') t2
      on t1.device_id=t2.device_id
      where t1.device_id is null;



-- lahuo
insert overwrite table dwh.gdt_data partition(day='${dt_today}',category='alipay_lahuo_laxin_delete',business='lahuo_0')
      select t2.device_id
      from
      (select device_id from dwh.gdt_data
      where day='${dt_today}' and category='alipay_lahuo_laxin' and business='lahuo_0') t1
      right join
      (select device_id  from dwh.gdt_data
      where day='${dt_yesterday}'  and category='alipay_lahuo_laxin' and business='lahuo_0') t2
      on t1.device_id=t2.device_id
      where t1.device_id is null;

insert overwrite table dwh.gdt_data partition(day='${dt_today}',category='alipay_lahuo_laxin_delete',business='lahuo_1')
      select t2.device_id
      from
      (select device_id from dwh.gdt_data
      where day='${dt_today}' and category='alipay_lahuo_laxin' and business='lahuo_1') t1
      right join
      (select device_id  from dwh.gdt_data
      where day='${dt_yesterday}'  and category='alipay_lahuo_laxin' and business='lahuo_1') t2
      on t1.device_id=t2.device_id
      where t1.device_id is null;

insert overwrite table dwh.gdt_data partition(day='${dt_today}',category='alipay_lahuo_laxin_delete',business='lahuo_2')
      select t2.device_id
      from
      (select device_id from dwh.gdt_data
      where day='${dt_today}' and category='alipay_lahuo_laxin' and business='lahuo_2') t1
      right join
      (select device_id  from dwh.gdt_data
      where day='${dt_yesterday}'  and category='alipay_lahuo_laxin' and business='lahuo_2') t2
      on t1.device_id=t2.device_id
      where t1.device_id is null;



insert overwrite table dwh.gdt_data partition(day='${dt_today}',category='alipay_lahuo_laxin_delete',business='lahuo_3')
      select t2.device_id
      from
      (select device_id from dwh.gdt_data
      where day='${dt_today}' and category='alipay_lahuo_laxin' and business='lahuo_3') t1
      right join
      (select device_id  from dwh.gdt_data
      where day='${dt_yesterday}'  and category='alipay_lahuo_laxin' and business='lahuo_3') t2
      on t1.device_id=t2.device_id
      where t1.device_id is null;


insert overwrite table dwh.gdt_data partition(day='${dt_today}',category='alipay_lahuo_laxin_delete',business='lahuo_4')
      select t2.device_id
      from
      (select device_id from dwh.gdt_data
      where day='${dt_today}' and category='alipay_lahuo_laxin' and business='lahuo_4') t1
      right join
      (select device_id  from dwh.gdt_data
      where day='${dt_yesterday}'  and category='alipay_lahuo_laxin' and business='lahuo_4') t2
      on t1.device_id=t2.device_id
      where t1.device_id is null;


insert overwrite table dwh.gdt_data partition(day='${dt_today}',category='alipay_lahuo_laxin_delete',business='lahuo_5')
      select t2.device_id
      from
      (select device_id from dwh.gdt_data
      where day='${dt_today}' and category='alipay_lahuo_laxin' and business='lahuo_5') t1
      right join
      (select device_id  from dwh.gdt_data
      where day='${dt_yesterday}'  and category='alipay_lahuo_laxin' and business='lahuo_5') t2
      on t1.device_id=t2.device_id
      where t1.device_id is null;
