首页 > 其他 > 详细

[Hive_add_6] Hive 实现 Word Count

时间:2019-01-05 12:41:35      阅读:132      评论:0      收藏:0      [点我收藏+]

 0. 说明

 

 

 


 1. Hive 实现 Word Count 方式一

  1.1 思路

  将每一行文本变为 Array 数组的一个元素

  再通过 collection items terminated by ‘ ‘ 完成转换单行文本

  最后通过表生成函数 explode 分裂 array 数组中的元素变成多行

 

  1.2 实现

  1. 创建表 wc

create table wc(line array<string>) row format delimited collection items terminated by  ;

 

  2. 加载数据

load data local inpath /home/centos/files/wc.txt into table wc;

 

  3. 编写 SQL 语句

select word, count(*) as count from (select explode(line) word from wc ) a group by word order by count desc;

 

 


 

2. Hive 实现 Word Count 方式二

  2.1 思路

  将一行文本加载为 String ,通过 split 结合正则表达书进行拆分

 

 

 

 


 

[Hive_add_6] Hive 实现 Word Count

原文:https://www.cnblogs.com/share23/p/10223845.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!