假设 words.txt 内容如下:
the day is sunny the the
the sunny is is
你的脚本应当输出(以词频降序排列):
the 4
is 3
sunny 2
day 1
-- 创建表
-- word.txt 上传到表text下
create table text(
line string
);
-- 查询表
select * from text;
-- 按空格将数据分割
select split(line,' ') from text;
-- 用爆炸函数,数据按行分开显示
select explode(split(line,' ')) from text;
-- 按词分租,统计词频
select word,count(word) as rn from
(select explode(split(line,' ')) as word from text) tb1 group by word order by rn;