Last active
May 3, 2017 21:47
-
-
Save dedunumax/8859952 to your computer and use it in GitHub Desktop.
Code shows how to implement a mapper only Hadoop Job
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package org.dedunumax.mapperOnly; | |
import java.io.IOException; | |
import org.apache.hadoop.io.LongWritable; | |
import org.apache.hadoop.io.Text; | |
import org.apache.hadoop.mapreduce.Mapper; | |
public class Map extends Mapper<LongWritable, Text, Text, Text> { | |
public void map(LongWritable key, Text value, Context context) | |
throws IOException, InterruptedException { | |
// Do what ever you want here | |
context.write(value,null); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package org.dedunumax.mapperOnly; | |
import java.io.IOException; | |
import org.apache.hadoop.conf.Configuration; | |
import org.apache.hadoop.fs.Path; | |
import org.apache.hadoop.io.Text; | |
import org.apache.hadoop.mapreduce.Job; | |
import org.apache.hadoop.mapreduce.lib.input.FileInputFormat; | |
import org.apache.hadoop.mapreduce.lib.input.TextInputFormat; | |
import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat; | |
import org.apache.hadoop.mapreduce.lib.output.TextOutputFormat; | |
public class App | |
{ | |
public static void main( String[] args ) throws IOException, ClassNotFoundException, InterruptedException | |
{ | |
Configuration conf = new Configuration(); | |
Job job = new Job(conf, "Mapper_Only_Job"); | |
job.setJarByClass(App.class); | |
job.setMapperClass(Map.class); | |
job.setOutputKeyClass(Text.class); | |
job.setOutputValueClass(Text.class); | |
job.setInputFormatClass(TextInputFormat.class); | |
job.setOutputFormatClass(TextOutputFormat.class); | |
// Sets reducer tasks to 0 | |
job.setNumReduceTasks(0); | |
FileInputFormat.addInputPath(job, new Path(args[0])); | |
FileOutputFormat.setOutputPath(job, new Path(args[1])); | |
boolean result = job.waitForCompletion(true); | |
System.exit(result ? 0 : 1); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment