hive:用hql来做wordcount

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/fly910905/article/details/82869328

用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
;

猜你喜欢

转载自blog.csdn.net/fly910905/article/details/82869328