Hive处理表中重复数据


在我们使用Kylin构建Cube时,常常会因为表中有某些重复的字段,导致运行失败,这时我们需要到原表中处理哪些重复的数据。

处理的方式大致有以下几种:

(1)hive表中某些数据是整行的重复,而且字段过多时distinct *:

如:

insert overwrite table stu_tab
select distinct * from stu_tab;

通过过滤不同的行,将原表进行覆盖。

上传实际工作中遇到的问题,如下其中就一个字段不重复,其他均重复,导致kylin构建失败,根据情况我们将含有2的那行数据进行删除;

insert overwrite table sys_cus_hz_20210127
select distinct * from sys_cus_hz_20210127 where consumlevel!=2;

之后再次运行Cube成功。

(2)当表中字段不多,而且数据是某些字段重复,可通过row_number():

insert overwrite table emp_tab
select id,name,sal from (
select * ,
row_number() over(partition by id order by sal desc) rank
from emp_tab)t1
where t1.rank=1;

(3)在某些情况中我们不是需要全部字段,而是仅仅过滤出某些不重复的字段:

select distinct id from stu_tab;
#单个字段去重
select distinct id,name from stu_tab;
#多个字段之间通过逗号去重

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM