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

数据:

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;

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

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

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

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

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

使用explode函数行转列

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

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

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

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

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

    原文作者:Ace_Wang
    原文地址: https://www.jianshu.com/p/a4a575c671c4
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞