hive:用hql來做wordcount
阿新 • • 發佈:2018-12-12
-
- 用hql來做wordcount
有以下文字檔案:
hello tom hello jim hello rose hello tom tom love rose rose love jim jim love tom love is what what is love |
需要用hive做wordcount
-- 建表對映
create table t_wc(sentence string);
-- 匯入資料
load data local inpath '/root/hivetest/xx.txt' into table t_wc;
hql答案:
SELECT word ,count(1) as cnts FROM ( SELECT explode(split(sentence, ' ')) AS word FROM t_wc ) tmp GROUP BY word order by cnts desc ; |