Big Data Hadoop Spark Developer Nov 12 to Dec 3 (Naman)

Discussion in 'Big Data and Analytics' started by Moghul., Nov 15, 2018.

  1. Moghul.

    Moghul. Well-Known Member
    Alumni

    Joined:
    Oct 19, 2016
    Messages:
    628
    Likes Received:
    21
    Hi Learners,

    This link is for Big Data Hadoop Spark Developer Nov 12 to Dec 3 (Trainer Naman) 06 AM batch.

    Regards,
    Simplilearn Team.
     
    #1
    _13017 likes this.
  2. vishvedula

    vishvedula New Member

    Joined:
    Nov 17, 2018
    Messages:
    1
    Likes Received:
    0
    Hi Team,

    Need some help here. As per the 12th Nov classes for Big Data Hadoop and Spark developer, I have tried running the MapReduce logic as a standalone, but though the code is error free, there's no output.

    The logic of mapper and reducer doesn't get executed / invoked.

    Am i missing something like setting up hadoop cluster locally? Is that a mandatory thing?

    I wouldn't need a jar file now to be deployed into hadoop cluster, just need to run it as a simple "psvm" standalone app.

    Any suggestions or help would be appreciated.
     
    #2
  3. ruhi.jain

    ruhi.jain Well-Known Member
    Simplilearn Support

    Joined:
    Jun 7, 2018
    Messages:
    133
    Likes Received:
    1
    Hi Learner,

    Please use the below program,

    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 Mapper<Object, Text, Text, IntWritable>{

    private final static IntWritable one = new IntWritable(1);
    private Text word = new Text();

    public void map(Object key, Text value, Context context
    ) throws IOException, InterruptedException {
    StringTokenizer itr = new StringTokenizer(value.toString());
    while (itr.hasMoreTokens()) {
    word.set(itr.nextToken());
    context.write(word, one);
    }
    }
    }

    public static class IntSumReducer
    extends Reducer<Text,IntWritable,Text,IntWritable> {
    private IntWritable result = new IntWritable();

    public void reduce(Text key, Iterable<IntWritable> values,
    Context context
    ) throws IOException, InterruptedException {
    int sum = 0;
    for (IntWritable val : values) {
    sum += val.get();
    }
    result.set(sum);
    context.write(key, result);
    }
    }

    public static void main(String[] args) throws Exception {
    Configuration conf = new Configuration();
    Job job = Job.getInstance(conf, "word count");
    job.setJarByClass(WordCount.class);
    job.setMapperClass(TokenizerMapper.class);
    job.setCombinerClass(IntSumReducer.class);
    job.setReducerClass(IntSumReducer.class);
    job.setOutputKeyClass(Text.class);
    job.setOutputValueClass(IntWritable.class);
    FileInputFormat.addInputPath(job, new Path(args[0]));
    FileOutputFormat.setOutputPath(job, new Path(args[1]));
    System.exit(job.waitForCompletion(true) ? 0 : 1);
    }
    }

    Thanks!
     
    #3

Share This Page