准备数据
wd.txt
创建Hive表
create table ruoze_wc(
sentence string
);
加载数据到表中
load data local inpath '/home/hadoop/data/wd.txt' into table ruoze_wc;
查看表数据
执行hive
- 使用 split 函数 按照逗号切分单词
- 使用explode 函数 将切分好的单词数组切成多行数据
- 统计每个单词 出现的次数
完整的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;