美文网首页
hive-函数-计算单词出现次数

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

作者: Ace_Wang | 来源:发表于2018-06-22 07:01 被阅读0次

数据:

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编程简单;

相关文章

网友评论

      本文标题:hive-函数-计算单词出现次数

      本文链接:https://www.haomeiwen.com/subject/yxmhyftx.html