具體步驟如下:
1. 在linux本地建立資料源檔案:
touch hive.txt
vi hive.txt
并随意給上一些内容
2.将hive.txt資料源檔案上傳到hdfs的input檔案夾中
hdfs dfs -put hive.txt /input
//上傳檔案
hdfs dfs -ls /input
//檢視
3.進入hive shell指令
hive
//并建立一張資料源表t2
create table t1 (line string);
4.裝載資料
将我們上傳到hdfs的hive.txt檔案寫入到資料源表t2中:
load data inpath '/input/hive.txt' overwrite into table t2;
将内容寫入資料源表
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;
完成!
6.檢視wordcount計算結果:
select * from hiveTest;