Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // kate: space-indent on; indent-width 2; mixedindent off; indent-mode cstyle;
- package org.verificatum;
- 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.ArrayWritable;
- 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;
- import org.apache.hadoop.util.GenericOptionsParser;
- public class Verificatum {
- public static class PowMapper
- extends Mapper<Object, ArrayWritable<IntWritable>, IntWritable, IntWritable>{
- private final static IntWritable one = new IntWritable(1);
- private IntWritable result = new IntWritable(1);
- public void map(Object key, ArrayWritable<IntWritable> value, Context context
- ) throws IOException, InterruptedException {
- StringTokenizer itr = new StringTokenizer(value.toString());
- while (itr.hasMoreTokens()) {
- IntWritable[] valueArray = value.get();
- result.set(valueArray[0] * valueArray[1]);
- context.write(result, one);
- }
- }
- }
- public static void main(String[] args) throws Exception {
- Configuration conf = new Configuration();
- String[] otherArgs = new GenericOptionsParser(conf, args).getRemainingArgs();
- if (otherArgs.length != 2) {
- System.err.println("Usage: verificatum <in> <out>");
- System.exit(2);
- }
- Job job = new Job(conf, "verificatum");
- job.setJarByClass(Verificatum.class);
- job.setMapperClass(VerificatumMapper.class);
- // job.setCombinerClass(VerificatumMapper.class);
- // job.setReducerClass(VerificatumMapper.class);
- job.setOutputKeyClass(IntWritable.class);
- job.setOutputValueClass(IntWritable.class);
- FileInputFormat.addInputPath(job, new Path(otherArgs[0]));
- FileOutputFormat.setOutputPath(job, new Path(otherArgs[1]));
- System.exit(job.waitForCompletion(true) ? 0 : 1);
- }
- }
Add Comment
Please, Sign In to add comment