WordCount範例

Step 1: 將word.txt上傳至HDFS

$ hadoop fs –put word.txt

Step 2: 下載範例程式

$ git clone https://github.com/ogre0403/NCHC-Hadoop-Tutorial
Cloning into 'NCHC-Hadoop-Tutorial'...
remote: Counting objects: 253, done.
remote: Total 253 (delta 0), reused 0 (delta 0), pack-reused 253
Receiving objects: 100% (253/253), 6.73 MiB | 1.60 MiB/s, done.
Resolving deltas: 100% (51/51), done.
Checking connectivity... done.

Step 3: 編譯MapReduce程式

$ cd cd NCHC-Hadoop-Tutorial
$ mvn clean package
…
[INFO] Copying hbase-client-0.98.6-cdh5.3.2.jar to /home/hadoop/NCHC-Hadoop-Tutorial/target/dependency-jars/hbase-client-0.98.6-cdh5.3.2.jar
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 05:07 min
[INFO] Finished at: 2016-07-05T08:50:28+00:00
[INFO] Final Memory: 36M/212M
[INFO] ------------------------------------------------------------------------

Step 4: 執行

$ hadoop jar target/MR-sample-0.0.1-SNAPSHOT.jar \
  org.nchc.train.mr.wordcount.WordCount word.txt output

Step 5: 檢查輸出

$ hadoop fs –ls output
Found 3 items
-rw-r--r-- 3 ogre supergroup  0 2016-03-30 13:31 output/_SUCCESS
-rw-r--r-- 3 ogre supergroup  16 2016-03-30 13:31 output/part-r-00000

$ hadoop fs –cat output/part-r-00000
(bbb,1)
(ddd,2)

results matching ""

    No results matching ""