Hive 实现WordCount

准备数据

wd.txt
在这里插入图片描述

创建Hive表

create table ruoze_wc(
sentence string
);

加载数据到表中

load data local inpath '/home/hadoop/data/wd.txt' into table ruoze_wc;

查看表数据

在这里插入图片描述

执行hive

  1. 使用 split 函数 按照逗号切分单词
    在这里插入图片描述
  2. 使用explode 函数 将切分好的单词数组切成多行数据
    在这里插入图片描述
  3. 统计每个单词 出现的次数
    在这里插入图片描述

完整的sql

select word, count(1) as c
from
(
select explode(split(sentence,",")) as word from ruoze_wc
) t group by word
order by c desc;

猜你喜欢

转载自blog.csdn.net/weixin_40420525/article/details/83476749
今日推荐