第八次:Hive 操作与应用 词频统计
作者:互联网
一、hive用本地文件进行词频统计
1.准备本地txt文件
1 2 |
echo "hadoop hbase" > f1.txt
echo "hadoop hive" > f2.txt
|
2.启动hadoop,启动hive
3.创建数据库,创建文本表
use hive(创建数据库,选择数据库) create table if not exists wctext(line string); show talbes;
4.映射本地文件的数据到文本表中
load data local inpath '/home/hadoop/wc/f1.txt' into table wctext; load data local inpath '/home/hadoop/wc/f2.txt' into table wctext;
5.hql语句进行词频统计交将结果保存到结果表中。
select word,count(1) as count from (select explode(split(line,' ')) as word from wctext) w group by word order by word;
create table wc as select word,count(1) as count from (select explode(split(line,' ')) as word from wctext) w group by word order by word;
6.查看统计结果
二、hive用HDFS上的文件进行词频统计
1.准备电子书或其它大的文本文件
2.将文本文件上传到HDFS上
hdfs dfs -put story.txt input/wcHive/
3.创建文本表
create table docs(line string);
4.映射HDFS中的文件数据到文本表中
create table docs(line string);
load data inpath '/user/hadoop/input/wcHive/story.txt' overwrite into table docs;
5.hql语句进行词频统计交将结果保存到结果表中
create table word_count as select word,count(1) as count from (select explode(split(line,' ')) as word from docs) word group by word order by word;
6.查看统计结果
show tables; select * from word_count;
标签:count,word,hadoop,Hive,第八次,词频,table,txt,select 来源: https://www.cnblogs.com/lazysen/p/14094435.html