gpt4 book ai didi

java - MapReduce 与 Hive 的结合

转载 作者:可可西里 更新时间:2023-11-01 16:32:56 27 4
gpt4 key购买 nike

我们能否使用 HiveMapReduce组合

说:我有一个 csv 文件。我需要找到一列的 mean 并将空数据替换为平均值(replace null with mean)。

所以我们是否可以在驱动程序中编写一个 hive 查询(以找到均值),然后编写一个 mapreduce block 以用均值替换 null。

哪种方式更好

  1. 只编写 mapreduce 代码或
  2. 结合使用 Hive 和 MapReduce。

最佳答案

这是可以使用(仅配置单元)解决的另一个答案

假设您的 csv 输入是这样的:

firstname,secondname,score,group

维杰,库马尔,123,cse

萨蒂什,巴布,,它

库马尔,nagendra,200,eie

阿尼尔,巴布,,它

然后像这样应用查询(我运行它有效):

hive> from students s join (select avg(score)as avg from students) a
> select s.firstname,
> case
> when s.score="" or s.score=NULL then cast(avg AS string)
> else s.score
> end as new_score ;

MapReduce 作业总数 = 2

输出:

好的

firstname       new_score

维杰 123

萨蒂什 161.5

库马尔 200

阿尼尔 161.5

耗时:67.059 秒,获取:4 行

关于java - MapReduce 与 Hive 的结合,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21177715/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com