码迷,mamicode.com
首页 > 其他好文 > 详细

[Hive_add_6] Hive 实现 Word Count

时间:2019-01-05 13:35:34      阅读:121      评论:0      收藏:0      [点我收藏+]

标签:word   方式   from   limit   centos   拆分   path   xpl   sele   


 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

标签:word   方式   from   limit   centos   拆分   path   xpl   sele   

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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!