Implement wordcount with Hive

1. Experiment content: implement wordcount with hive

2. Experimental steps:

1. Prepare the data
First, use the vi editor to write a word.txt file with the content as shown in the figure below:
Insert picture description here

2. Start and create a test database, name test, enter the following command, as shown in the figure

bin/hive
create database test;

Insert picture description here
3. Create a table wordcount in the test database

create table wordcount(rowdata string);

Insert picture description here
4. Load data The
code is as follows

load data local inpath '/home/hadoop/word.txt' into table wordcount;

Insert picture description here
5. SQL programming to achieve WordCount
code is as follows:

select word ,count(1) cnt 
from wordcount lateral view explode(split(rowdata," ")) alaistable as  word
 group by word 
 order by cnt ;

Insert picture description here

3. Experimental results

as the picture shows
Insert picture description here

Guess you like

Origin blog.csdn.net/weixin_44322234/article/details/106882977