Hive怎么实现WordCount

这篇文章将为大家详细讲解有关Hive怎么实现WordCount,文章内容质量较高,因此小编分享给大家做个参考,希望大家阅读完这篇文章后对相关知识有一定的了解。

站在用户的角度思考问题,与客户深入沟通,找到头屯河网站设计与头屯河网站推广的解决方案,凭借多年的经验,让设计与互联网技术结合,创造个性化、用户体验好的作品,建站类型包括:网站建设、成都做网站、企业官网、英文网站、手机端网站、网站推广、域名注册、网络空间、企业邮箱。业务覆盖头屯河地区。

1. 创建一个存放源数据的表(外部表)t_words_src, 表中字段line为string类型, 存放一行单词

源数据示列: 

hello,tom
hello,jerry
hello,kitty
hello,world
hello,tom
hive> create external table t_words_src (line string)
row format delimited
fields terminated by '\n'    # 按\n来切分字段, 一行就是一个字段
location '/wc/input';    # 源数据路径为 'hdfs://node1:9000/wc/input' 

hive> select * from t_words;
OK
hello,tom
hello,jerry
hello,kitty
hello,world
hello,tom

2. 创建一个存放所有单词的表t_words, 表中字段word为string类型, 存放单词

hive> create table t_words (word string);
hive> insert into table t_words select explode(split(line,',')) as word from t_words_src;

hive> select * from t_words;
OK
hello
tom
hello
jerry
hello
kitty
hello
world
hello
tom

3. 创建一个存放WordCount结果的表t_wc_result, 表中字段word为string类型, 存放单词, counts为int类型, 存放单词出现次数

hive> create table t_wc_result (word string, counts int);
hive> insert into table t_wc_result select word as word, count(word) as counts from t_words;

hive> select * from t_wc_result;
OK
hello	5
jerry	1
kitty	1
tom	2
world	1

相对MapReduce来说, Hive的HQL版WordCount写起来代码量少很多, 但他们的思想都是一样的

关于Hive怎么实现WordCount就分享到这里了,希望以上内容可以对大家有一定的帮助,可以学到更多知识。如果觉得文章不错,可以把它分享出去让更多的人看到。

本文名称:Hive怎么实现WordCount
本文地址:https://www.cdcxhl.com/article38/ppgcsp.html

成都网站建设公司_创新互联,为您提供小程序开发建站公司静态网站全网营销推广网站维护响应式网站

广告

声明:本网站发布的内容(图片、视频和文字)以用户投稿、用户转载内容为主,如果涉及侵权请尽快告知,我们将会在第一时间删除。文章观点不代表本网站立场,如需处理请联系客服。电话:028-86922220;邮箱:631063699@qq.com。内容未经允许不得转载,或转载时需注明来源: 创新互联

绵阳服务器托管