Mapreduce 在配置单元中定义此映射缩减函数(UDF)

Mapreduce 在配置单元中定义此映射缩减函数(UDF),mapreduce,hive,Mapreduce,Hive,我有一个配置单元表a,其中有4个字符串列,名称为:用户、项目、类型、时间 示例输入如下所示: user item type time 1 101 0 06-16 # June 16, 2013 , all dates are in the same year 2 101 0 09-04 1 102 1 07-03 有4种类型(0,1,2,3),权重分别为1,2,3,4。每行有一个时间分数,定义如下: tScore=

我有一个配置单元表a,其中有4个字符串列,名称为:用户、项目、类型、时间

示例输入如下所示:

user  item  type   time
1     101    0     06-16   # June 16, 2013 , all dates are in the same year 
2     101    0     09-04
1     102    1     07-03
有4种类型(0,1,2,3),权重分别为1,2,3,4。每行有一个时间分数,定义如下:
tScore=(时间-2013年1月6日)/7

i、 e,从6月1日起有几周
fScore=类型权重*时间分数

然后,我需要根据(user,item)作为键聚合fScore,并根据降序聚合的fScore对表进行排序

我不知道我是否清楚地描述了我要做的事情。如果有任何不清楚的地方,请发表评论

select user, item, (type + 1) * datediff(concat('2013-', time), '2013-06-01') / 7 as fScore
from A
order by fScore desc;
查看所有内置函数

此外,如果权重不是刚好(type+1),则可以用case语句替换该部分。例如:

select user, item, case type when 0 then 1 when 1 then 2 when 2 then 3...