使用hive 实现WordCount 计数

启动Hive

《使用hive 实现WordCount 计数》 启动hive

2.建表

《使用hive 实现WordCount 计数》 建表

3.导入数据

《使用hive 实现WordCount 计数》 导入数据

4.查询:

《使用hive 实现WordCount 计数》 查看wordcount 表

至此,数据导入完成。我原先以为做单词统计,这一张表就可以,但是我发现非常的困难,到这个地步就不能在用Hadoop里的MR来思维了,应该用RMDS的思维来解决这个问题,所以我又新建了一张表,叫words,用来存储分割字符串后的单词。

6.新建words表

《使用hive 实现WordCount 计数》 建表

7对words表进行格式上的处理执行下列语句

insert overwrite table wordsselect explode(split(word,'[ \t]+’)) wordfrom wordcount;         explode是hive的函数,在以后的深入学会了解到。

对表行一个处理,即遇到一个“\t”自动切分

words表中的格式

8.使用HQL语句查询words表

select word ,count(*) from   words group by word

《使用hive 实现WordCount 计数》

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