Data science Software Course Training in Ameerpet Hyderabad

Data science Software Course Training in Ameerpet Hyderabad

Tuesday 30 August 2016

MR Lab3

grouping By Multiple columns.

ex:

 select dno, sex, sum(sal) from emp
   group by dno, sex;


DnoSexSalMap.java
--------------------
package mr.analytics;

import java.io.IOException;

import
org.apache.hadoop.io.IntWritable;
import
org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.Text;
import
org.apache.hadoop.mapreduce.Mapper;
public class DnoSexSalMap extends

Mapper
 <LongWritable,Text,Text,IntWritable>
{
     //  file : emp
     // schema : id,name,sal,sex,dno
    //  delimiter : "," (comma)
 //  sample row : 101,amar,20000,m,11
 //   sex as key, sal as value.
    public void map(LongWritable 
k,Text v,
            Context  con)
     throws IOException,
InterruptedException
     {
        String line =
v.toString();
      String[] w = line.split(",");   
      String sex = w[3];
      String dno = w[4];
      String myKey = dno+"\t"+sex;
     int sal =Integer.parseInt(w[2]);
    con.write(new Text(myKey),new
IntWritable(sal));
     }
  }

----------------
Driver8.java
----------------

package mr.analytics;

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.lib.input.F

ileInputFormat;
import

org.apache.hadoop.mapreduce.lib.output.

FileOutputFormat;

public class Driver8
{
    public static void main(String

[] args)
     throws Exception
     {
        Configuration c = new

Configuration();
        Job j = new Job

(c,"d8");
        j.setJarByClass

(Driver8.class);
        j.setMapperClass

(DnoSexSalMap.class);
        j.setReducerClass

(RedForSum.class);
        j.setOutputKeyClass

(Text.class);
        j.setOutputValueClass

(IntWritable.class);
         Path p1 = new Path

(args[0]); //input
         Path p2 = new Path

(args[1]); //output
       
FileInputFormat.addInputPath(j,p1);
FileOutputFormat.setOutputPath(j, p2);

System.exit(j.waitForCompletion(true) ?

0:1);
  }
}

--------------------------

submit:

[training@localhost ~]$ hadoop fs -cat

mrlab/r8/part-r-00000
11      f       25000
11      m       26000
12      f       18000
13      m       19000

______________________________



12 comments:

  1. The info was very much useful http://www.traininginsholinganallur.in/hadoop-training-in-chennai.html

    ReplyDelete
  2. thank you for Giving such a valuable information.very helpful blog and useful to professionals and students.one of the recommanded blog.very apriciated

    Hadoop Online Training In Hyderabad!

    ReplyDelete
  3. Excellent and very cool idea and the subject at the top of magnificence and I am happy to this post..Interesting post! Thanks for writing it. What's wrong with this kind of post exactly? It follows your previous guideline for post length as well as clarity..

    Hadoop Training in Chennai

    ReplyDelete
  4. thank you giving your valuable information about the hadoop

    hadoop online training

    ReplyDelete
  5. Webtrackker technology is the best IT training institute in NCR. Webtrackker provide training on all latest technology such as hadoop training. Webtrackker is not only training institute but also it also provide best IT solution to his client. Webtrackker provide training by experienced and working in the industry on same technology.Webtrackker Technology C-67 Sector-63 Noida 8802820025

    Hadoop Training institute in indirapuram


    Hadoop Training institute in Noida


    Hadoop Training institute in Ghaziabad


    Hadoop Training institute in Vaishali


    Hadoop Training institute in Vasundhara


    Hadoop Training institute in Delhi South Ex

    ReplyDelete
  6. nice blog. thank you for sharing hadoop tutorials. Really helpful for me. Keep sharing on hadoop tutorials

    ReplyDelete
  7. thank you for offering such a nice content.we are very delighted to read .one of the recommended blog.very use full content for fresher and professionalsdata science training in hyderabad
    data science training in ameerpet
    best data science training institute in hyderabad

    ReplyDelete
  8. Thanks for giving this much useful hadoop information

    Hadoop Training in Hyderabad

    ReplyDelete
  9. Thank you for providing useful information and this is the best article blog for the students.learn Python programming training course.
    Python Training in Hyderabad

    ReplyDelete
  10. Thank you for sharing such a valuable article with good information in this blog.learn Data science course with advanced technology.
    Data Science Training in Hyderabad

    ReplyDelete
  11. Thanks for sharing valuable article having good information and also gain worth-full knowledge.

    Oracle ICS Online Training

    ReplyDelete
  12. Thank you for sharing your awesome and valuable article this is the best blog for the students they can also learn.

    Workday Online Training


    ReplyDelete