hive之wordcount

1.创建一张表,记录文件数据,使用换行符作为分隔符

  create table file_data(content string)

  row format delimited fields terminated by '/n'

2.将准备的数据(/home/hadoop/wordcount.tx)添加到file_data 表中

  load data local inpath '/home/hadoop/wordcount.tx' into table file_data

3.根据" "切分数据,切分出来的每个单词作为一行 记录到结果表。

  (1)创建结果表,将切分的单词作为每一行记录到结果表中去

    create table words(word string)

    insert into table words select explode(split(line," ")) from file_data

  (2)使用聚合函数count进行统计

    select word,count(word)

    from words

    group by word

    (可以将count(word)取别名count,然后利用order by count来进行排序)

    

posted on 2019-08-27 09:39  hdc520  阅读(189)  评论(0)    收藏  举报

导航