use dwh;


insert overwrite table dmp_device_tag partition(dt = '${yes_date}', source = 'external',business = 'yunhai')
 select X.device_id,X.device_type,X.platform,X.package_name,concat_ws(',', collect_set(X.tags)) tags,update_date
 from ( select device_id,device_type,platform,package_name,tags,update_date from dmp_device_tag where dt = '${yes_date_before}' and source = 'external' and business =  'yunhai'
union
select device_id,device_type,platform,package_name,concat_ws(',', collect_set(concat(tag_type,'#',first_tag, '#', coalesce(second_tag,'')))) tags,'${yes_date_str_midline}'  update_date from dm_device_yunhai_tag where dt = '${yes_date}'
group by device_id,device_type,platform,package_name) X
group by X.device_id,X.device_type,X.platform,X.package_name,X.update_date