一、实验内容:用hive实现wordcount
二、实验步骤:
1.准备数据
首先利用vi编辑器,编写一个word.txt文件,内容如下图所示:
2.启动并创建测试数据库,命名test,输入如下命令,如图所示
bin/hive
create database test;
3.在test数据库中创建表wordcount
create table wordcount(rowdata string);
4.加载数据
代码如下
load data local inpath '/home/hadoop/word.txt' into table wordcount;
5. SQL编程实现WordCount
代码如下:
select word ,count(1) cnt
from wordcount lateral view explode(split(rowdata," ")) alaistable as word
group by word
order by cnt ;
三、实验结果
如图所示