Word_Count实验

菜鸟的博客 / 2024-11-07 / 原文

今天试用了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