需求是一个表里的两波数据进行匹配去重,单去重不是单条对单挑的,是先把相同的合并,然后在匹配
例如
编号 姓名 年龄
1 小六 null
1 小七 18
然后新进来的数据与上面的去比较查重
编号 姓名 年龄
1 小六 18
以编号相同为前提查重,这条数据的结果应该是完全重复
我的想法是先将数据库的相同编号的数据group by合并,然后将他们的其他字段保存为数组,然后转为字符串,最后join的时候看看新数据是否包含在原来的字段里
然后写了这个语句,刚开始测试没问题,可以用,后来底层查重的数据变多,5000w,hive经常会死掉,求优化
(join左边的表数据全部的都是不重复的,但是右边的表有重复)
(数据都在一章表里,我通过type来划分成两部分的)
select t.num from test.data_test as t
inner join (select num,concat_ws(",",collect_set(t1.username)) as username,concat_ws(",",collect_set(t1.gender)) as gender,concat_ws(",",collect_set(cast(t1.age as string))) as age,concat_ws(",",collect_set(t1.city_short)) as city_short from test.data_test t1
where t1.type != 'ty1'
group by t1.num)t2
on t.num = t2.num
where t.type = "ty1"
and ((instr(t2.username,t.username) > 0) or t.username is null)
and ((instr(t2.gender,t.gender) > 0) or t.gender is null)
and ((instr(t2.age,cast(t.age as string)) > 0) or t.age is null)
and ((instr(t2.city_short,t.city_short) > 0) or t.city_short is null)
或者请指点这里面那里的操作会很很耗费性能,我们是单线程操作,没有并发