用Hive实现wordcount

一、实验内容:用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 ;

在这里插入图片描述

三、实验结果

如图所示
在这里插入图片描述

猜你喜欢

转载自blog.csdn.net/weixin_44322234/article/details/106882977