5分钟
运行代码结果
1)准备测试数据
通过Eclipse新建一个项目,项目名称为InvertedIndex。新建类InvertedIndex,将代码输入,注意类名一致。在参数选项卡中设置输入文件的目录user/hadoop/index_in和输出文件的目录user/hadoop/index_out,并制定虚拟内存为1024MB。
2)在本地上传三个txt文件
在本地建立三个txt文件,分别是file1、file2、file3,文件的内容与“实例描述”中的三个文件一样,通过Eclipse上传到user/hadoop/index_in,成功上传之后,用命令查看三个文件的内容。
[ccwan@Master ~]$hadoop fs –is deput_in
-rw-r--r—3 hadoop supergroup 96 2012-06-12 23:45 /user/hadoop/dedup_in/file1.txt
-rw-r--r—3 hadoop supergroup 96 2012-06-12 23:45 /user/hadoop/dedup_in/file2.txt
-rw-r--r—3 hadoop supergroup 96 2012-06-12 23:45 /user/hadoop/dedup_in/file3.txt
[ccwan@Master ~]$hadoop fs –cat index_in/file1.txt
MapReduce is sample
[ccwan@Master ~]$hadoop fs –cat index_in/file1.txt
MapReduce is powerful is sample
[ccwan@Master ~]$hadoop fs –cat index_in/file1.txt
Hello MapReduce bye MapReduce3)查看运行结果
右击SimpleIndex类,选择Run as→Open Run Dialog命令。查看运行结果,右击Eclipse的DFS Locations中的/user/hadoop文件夹进行刷新,这时会发现多出一个index_out文件夹,且里面有3个文件,然后打开part-r-00000文件,会在Eclipse中把内容显示出来,如下图所示。
学员评价