我有一种情况,我需要在 mapreduce 中复制 SQL rank 函数。类似这样: QUALIFY Row_number() over(partition by a.column1 order by a.column2 desc, d.column3 desc) =1
谢谢你。
类似这样: QUALIFY Row_number() over(partition by a.column1 order by a.column2 desc, d.column3 desc) =1
对不起,我不太明白这个。你是想通过 hive 还是 MR 来实现这一点?你的问题说你需要通过 MR,但你已经展示了这个查询。两者完全不同。
如果您想通过 Hive 实现此目的,您可能会发现这篇文章很有用。如果你想要这种 MR 方式,你需要从头开始编写代码。
高温高压
下面给出的是使用普通查询复制 Rank 函数。
无论数据库如何,此查询都将执行。要求是根据文件名中的日期对文件名进行排名。
**Sample Records**:
`insert into ref values('840001','840001_2015_04_29');
insert into ref values('840002','840002_2015_04_29');
insert into ref values('840003','840003_2015_04_29');
insert into ref values('840004','840004_2015_04_29');
insert into ref values('840008','840008_2015_04_28');
insert into ref values('840009','840009_2015_05_02');
insert into ref values('850005','850010_2015_05_29');
insert into ref values('850005','850010_2015_05_23');
insert into ref values('850005','850010_2015_05_12');
insert into ref values('850005','850010_2015_05_17');
insert into ref values('850006','850010_2015_05_29');
insert into ref values('850006','850010_2015_05_23');
insert into ref values('850006','850010_2015_05_16');`
`**Table Structure**:
CREATE TABLE ref
(
ffid TEXT
,filename TEXT
);`
**Query**:
SELECT
S1.FFID
,S1.FILENAME
,(
SELECT COUNT(*) + 1
FROM
(SELECT DISTINCT FFID,FILENAME FROM REF) AS S2
WHERE S1.FFID=S2.FFID AND S1.FILENAME < S2.FILENAME
) AS RANK
FROM
(SELECT DISTINCT FFID,FILENAME FROM REF) AS S1
WHERE RANK=1
ORDER BY FFID ;
等级是隐含的:
rank() over (partition by a.column1 order by a.column2 desc, d.column3 desc)
https://cwiki.apache.org/confluence/display/Hive/LanguageManual+WindowingAndAnalytics