7.1 wordCount.java介紹
在下列網址hadoop說明文件中有wordcount.java 的程式碼:
http://hadoop.apache.org/docs/current/hadoop-mapreduce-client/hadoop-mapreduce-client-core/MapReduceTutorial.html
7.2 編輯wordCount.java
Step1 建立wordcount目錄
mkdir -p ~/wordcount/input cd ~/wordcountStep2 編輯WordCount.java
gedit WordCount.javaStep3~6 編輯WordCount.java
在gedit 輸入 WordCount.java完整程式碼
import java.io.IOException; import java.util.StringTokenizer; import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.fs.Path; import org.apache.hadoop.io.IntWritable; import org.apache.hadoop.io.Text; import org.apache.hadoop.mapreduce.Job; import org.apache.hadoop.mapreduce.Mapper; import org.apache.hadoop.mapreduce.Reducer; import org.apache.hadoop.mapreduce.lib.input.FileInputFormat; import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat; public class WordCount { public static class TokenizerMapper extends Mapper7.3 編譯wordCount.java
Step1 修改編譯所需要的環境變數檔
sudo gedit ~/.bashrc輸入下列內容
export PATH=${JAVA_HOME}/bin:${PATH} export HADOOP_CLASSPATH=${JAVA_HOME}/lib/tools.jarStep2 讓 ~/.bashrc 修改的設定值生效
source ~/.bashrcStep3 開始編譯
hadoop com.sun.tools.javac.Main WordCount.java jar cf wc.jar WordCount*.class ll7.4 建立測試文字檔
cp /usr/local/hadoop/LICENSE.txt ~/wordcount/input ll ~/wordcount/input start-all.sh hadoop fs -mkdir -p /user/hduser/wordcount/input cd ~/wordcount/input hadoop fs -copyFromLocal LICENSE.txt /user/hduser/wordcount/input hadoop fs -ls /user/hduser/wordcount/input7.5 執行wordCount.java
cd ~/wordcount hadoop jar wc.jar WordCount /user/hduser/wordcount/input/LICENSE.txt /user/hduser/wordcount/output7.6 查看執行結果
hadoop fs -ls /user/hduser/wordcount/output hadoop fs -cat /user/hduser/wordcount/output/part-r-00000
以上內容節錄自這本書有詳細介紹:
Hadoop+Spark大數據巨量分析與機器學習整合開發實戰 http://www.books.com.tw/products/0010695285
您好:我的照上面編譯,會出現:
回覆刪除hduser@master:~/wordcount$ hadoop com.sun.tools.javac.Main WordCount.java
WordCount.java:40: error: incompatible types: Object cannot be converted to IntWritable
for (IntWritable val : values) {
^
Note: WordCount.java uses unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
1 error
不知如何解決,
麻煩您了!
謝謝!
建議你直接copy 這裡的程式碼 http://hadoop.apache.org/docs/current/hadoop-mapreduce-client/hadoop-mapreduce-client-core/MapReduceTutorial.html 我試過是OK的
刪除您好:
回覆刪除執行hadoop fs -ls /user/hduser/wordcount/output後,
資料夾內空無一物,
不知哪裡出了問題?
煩請撥冗惠覆。
MMORPG OYUNLAR
回覆刪除ınstagram takipci satın al
tiktok jeton hilesi
tiktok jeton hilesi
antalya saç ekimi
referans kimliği nedir
İnstagram Takipçi Satın Al
Mt2 pvp
Takipci satın al
Smm panel
回覆刪除smm panel
İŞ İLANLARI
instagram takipçi satın al
hirdavatci
HTTPS://WWW.BEYAZESYATEKNİKSERVİSİ.COM.TR/
SERVİS
Jeton hile