天天看点

HiveQl语句应用实例:WordCount具体步骤如下:

具体步骤如下:

1. 在linux本地创建数据源文件:

touch hive.txt
 vi hive.txt  
           

并随意给上一些内容

HiveQl语句应用实例:WordCount具体步骤如下:

2.将hive.txt数据源文件上传到hdfs的input文件夹中

hdfs dfs -put hive.txt /input   
 //上传文件
hdfs dfs -ls /input     
 //查看
           
HiveQl语句应用实例:WordCount具体步骤如下:

3.进入hive shell命令

hive
//并新建一张数据源表t2
create table t1 (line string);
           
HiveQl语句应用实例:WordCount具体步骤如下:

4.装载数据

将我们上传到hdfs的hive.txt文件写入到数据源表t2中:

load data inpath '/input/hive.txt' overwrite into table t2;
将内容写入数据源表
           
HiveQl语句应用实例:WordCount具体步骤如下:

5.编写HiveQL语句实现wordcount算法,并建表hiveTest保存计算结果:

create table hiveTest as 
select word, count(1) as count from 
(select explode (split (line, ' ')) as word from t2) w
group by word 
order by word;
           
HiveQl语句应用实例:WordCount具体步骤如下:

完成!

HiveQl语句应用实例:WordCount具体步骤如下:

6.查看wordcount计算结果:

select * from hiveTest;
           
HiveQl语句应用实例:WordCount具体步骤如下:

继续阅读