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)

扫描二维码关注公众号,回复: 7108032 查看本文章

    from words

    group by word

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

    

猜你喜欢

转载自www.cnblogs.com/hdc520/p/11416382.html