[info] (1)创建单词统计文件 hiveWordCount.txt
# 进入software目录
cd /data/software
# 创建 hiveWordCount.txt 文件
vi hiveWordCount.txt
# 写入一下内容
A喜欢B B喜欢C C喜欢A A喜欢B B喜欢C C喜欢A
A喜欢B B喜欢C C喜欢A
A喜欢B
A喜欢B
:-:
[info] (2)把 hiveWordCount.txt 推送去HDFS
# 创建HDFS的上传目录hiveWordCount
hadoop fs -mkdir /hiveWordCount
# 把hiveWordCount.txt推送上去HDFS的hiveWordCount
hadoop fs -put /data/software/hiveWordCount.txt /hiveWordCount
:-:
[info] (3)在 bigdata1登录hive,并创建表hiveWordCountTable
# 登录hive
hive
# 创建内部表hiveWordCountTable
create table hiveWordCountTable(line String);
# 把HDFS中的hiveWordCount.txt导入到内部表hiveWordCountTable
load data inpath '/hiveWordCount/hiveWordCount.txt' into table hiveWordCountTable;
:-:
[info] (4)执行数据分析语句
create table word_count as
select single_word, count(1) as count from (select explode(split(line,' '))
as single_word from hiveWordCountTable) w
group by single_word
order by single_word;
:-:
[info] (5)查看分析结果
select * from word_count;
:-:
内容来源于网络,如有侵权,请联系作者删除!