Hadop Reklam

Sponsor Reklam

Monday, August 5, 2013

Hadoop Example: WordCount v1.0 Part-2

Usage

Compile WordCount.java:
$ mkdir wordcount_classes $ javac -cp classpath -d wordcount_classes WordCount.java
where classpath is:
  • CDH4 - /usr/lib/hadoop/*:/usr/lib/hadoop/client-0.20/*
  • CDH3 - /usr/lib/hadoop-0.20/hadoop-0.20.2-cdh3u4-core.jar
Create a JAR:
$ jar -cvf wordcount.jar -C wordcount_classes/ .
Assuming that:
  • /user/cloudera/wordcount/input - input directory in HDFS
  • /user/cloudera/wordcount/output - output directory in HDFS
Create sample text files as input and move to HDFS:
$ echo "Hello World Bye World" > file0
$ echo "Hello Hadoop Goodbye Hadoop" > file1
$ hadoop fs -mkdir /user/cloudera /user/cloudera/wordcount /user/cloudera/wordcount/input
$ hadoop fs -put file* /user/cloudera/wordcount/input
Run the application:
$ hadoop jar wordcount.jar org.myorg.WordCount /user/cloudera/wordcount/input /user/cloudera/wordcount/output
Output:
$ hadoop fs -cat /user/cloudera/wordcount/output/part-00000
Bye 1
Goodbye 1
Hadoop 2
Hello 2
World 2
Applications can specify a comma-separated list of paths that would be present in the current working directory of the task using the option -files. The -libjars option allows applications to add JARs to the classpaths of the maps and reduces. The -archives allows them to pass archives as arguments that are unzipped/unjarred and a link with name of the zip/JAR are created in the current working directory of tasks. More details about the command line options are available at Hadoop Command Guide.
Running wordcount example with -libjars and -files:
hadoop jar hadoop-examples.jar wordcount -files cachefile.txt -libjars mylib.jar input output

9 comments:

  1. Cloud is one of the tremendous technology that any company in this world would rely on(Salesforce developer training in chennai). Using this technology many tough tasks can be accomplished easily in no time. Your content are also explaining the same(Salesforce training institutes in chennai). Thanks for sharing this in here. You are running a great blog, keep up this good work.

    ReplyDelete
  2. I am really enjoying reading your well written articles.
    It looks like you spend a lot of effort and time on your blog.
    I have bookmarked it and I am looking forward to reading new articles.Keep up the good work..
    RPA Training in Chennai
    RPA Classes in Chennai
    Blue Prism Training in Chennai
    Ethical Hacking Training in Chennai
    Cloud Computing Training in Chennai
    RPA Training in T Nagar
    RPA Training in Porur

    ReplyDelete
  3. I am really enjoying reading your well written articles.
    It looks like you spend a lot of effort and time on your blog.
    I have bookmarked it and I am looking forward to reading new articles.Keep up the good work..
    RPA Training in Chennai
    RPA Classes in Chennai
    Blue Prism Training in Chennai
    Ethical Hacking Training in Chennai
    Cloud Computing Training in Chennai
    RPA Training in T Nagar
    RPA Training in Porur

    ReplyDelete
  4. Thanks for sharing valuable information.It will help everyone.keep Post.
    Kerala Lottery guessing

    ReplyDelete
  5. Automated Forex Trading With FBS Metatrader 4 - Download .

    ReplyDelete