Hive典型表内除重的写法:
insert overwrite table table_name
select t.p_key,t.sort_word
from (select p_key,
sort_word ,
row_number() over(distribute by p_key sort by sort_word) as rn
from store
)t
where t.rn=1;
p_key为除重依据,sort_word 为排序依据,一般为时间, rn为排名。
注意hql方言中,表的嵌套要家别名,字段前加上表别名。
采用hive提供的distribute by 和 sort by, 这样可以充分利用hadoop资源,p_key相同的数据会被送到同一个reducer去处理
insert overwrite table table_name
select t.p_key,t.sort_word
from (select p_key,
sort_word ,
row_number() over(distribute by p_key sort by sort_word) as rn
from store
)t
where t.rn=1;
p_key为除重依据,sort_word 为排序依据,一般为时间, rn为排名。
注意hql方言中,表的嵌套要家别名,字段前加上表别名。
采用hive提供的distribute by 和 sort by, 这样可以充分利用hadoop资源,p_key相同的数据会被送到同一个reducer去处理