【问题标题】:How to dedupe a file and maintain original sort order in Hive?如何在 Hive 中对文件进行重复数据删除并保持原始排序顺序?
【发布时间】:2016-03-10 21:38:09
【问题描述】:

我的数据已经按 last_column 降序和 third_column 降序排序。我想根据 last_column 对数据集进行重复数据删除,同时保持原始排序顺序。因此,对于每个 last_column,我想要最终输出中的第一行。 我需要使用 Hive 来实现这一点。 我的数据是:

10009,12/3/1959,Rodney,Purtle,M,8/28/1986,d007
10010,5/1/1954,Ahishek ,Kumar,M,12/1/1986,d007
10011,1/21/1955,Abhilash,Whatever,M,9/12/1989,d007
10016,5/1/1954,Ross,Hupchuck,M,12/1/1986,d006
10008,1/21/1955,Michael ,Gross,M,9/12/1989,d006
10014,1/21/1955,John ,Talburt,M,9/12/1989,d006
10013,5/1/1954,John,Doe,M,12/1/1986,d006
10015,12/3/1959,Daniel ,Pullen,M,8/28/1986,d006

期望的输出:

10009,12/3/1959,Rodney,Purtle,M,8/28/1986,d007
10016,5/1/1954,Ross,Hupchuck,M,12/1/1986,d006

我当前的代码:

select * 
from 
(select *, row_number() over (partition by last_column order by desc)as r from table_name)s 
where r = 1;

我得到的输出是:

10014   1/21/1955   John    Talburt M   9/12/1989   d006    1
10010   5/1/1954    Ahishek     Kumar   M   12/1/1986   d007    1

谁能帮忙并提出我可能做错了什么?

【问题讨论】:

    标签: sorting hadoop hive mapreduce bigdata


    【解决方案1】:

    @Utsav 你可以试试下面的查询:

    select * from (select *, row_number() over (partition by last_column order bythird_column desc)as r from table_name)s where r=1 order by last_column desc;

    希望对你有帮助!

    【讨论】:

      猜你喜欢
      • 2020-06-27
      • 1970-01-01
      • 2019-07-18
      • 2021-04-15
      • 2019-02-18
      • 1970-01-01
      • 2016-12-23
      • 2021-12-23
      • 1970-01-01
      相关资源
      最近更新 更多