hive-函数-计算单词出现次数

2018-06-22  本文已影响0人  Ace_Wang

数据:

hive-wc.txt  

hello,world,welcomehello,welcome

创建表:

create table hive_wc(sentence string);

加载数据:

load data local inpath '/home/hadoop/data/hive-wc.txt' into table hive_wc;

下面我们一步一步完善sql:

select * from hive_wc;

select split(sentence,',') from hive_wc;

按“,”分割字符串得到数据

select explode(split(sentence,',')) from hive_wc;

使用explode函数行转列

select word,count(1) from (select explode(split(sentence,',')) as word from hive_wc) t group by word;

统计单词出现次数PS:使用虚拟表必须用别名

hive统计单词出现次数完成,确实是比mapreduce编程简单;

上一篇 下一篇

猜你喜欢

热点阅读