菜鸟的博客

纵有疾风起,人生不言弃。

导航

Word_Count实验

今天试用了Hive的,MapReduce实现Word_Count


1. 创建input目录,output目录会自动生成。其中input为输入目录,output目录为输出目录。命令如下:

cd /usr/local/games
mkdir input

2.然后,在input文件夹中创建两个测试文件file1.txt和file2.txt,命令如下:

cd  /usr/local/hadoop/input
echo "hello MuZhadoDi" > file1.txt
echo "MuZhadoDi likes hadoop" > file2.txt

3.然后进入Hive-shell下,输入下列命令:

create table docs(line string);
load data inpath 'file:///usr/local/games/input' overwrite into table docs;
create table word_count as 
select word, count(1) as count from
(select explode(split(line,' '))as word from docs) w
group by word
order by word;

4.然后查询语句,查询结果:

select * from word_count

 

posted on 2024-10-21 21:34  hhmzd233  阅读(5)  评论(0编辑  收藏  举报