-Hello,
We have tried a program in hadoop for printing the given number in
text.but we got two errors.we dont know the reason for those errors.with this i
have attached the java file ,input file and the errors.Can you please
solve this and tell me the exact reason.
Your Mail works best with the New Yahoo Optimized IE8. Get it NOW!.
Your Mail works best with the New Yahoo Optimized IE8. Get it NOW!.
The INTERNET now has a personality. YOURS! See your Yahoo! Homepage.
//package org.apache.hadoop.examples;
import java.io.*;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.StringTokenizer;
import java.lang.*;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.conf.Configured;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapred.FileInputFormat;
import org.apache.hadoop.mapred.FileOutputFormat;
import org.apache.hadoop.mapred.JobClient;
import org.apache.hadoop.mapred.JobConf;
import org.apache.hadoop.mapred.MapReduceBase;
import org.apache.hadoop.mapred.Mapper;
import org.apache.hadoop.mapred.OutputCollector;
import org.apache.hadoop.mapred.Reducer;
import org.apache.hadoop.mapred.Reporter;
import org.apache.hadoop.util.Tool;
import org.apache.hadoop.util.ToolRunner;
//To run:bin/hadoop jar build/hadoop-examples.jar te1 <in-dir> <out-dir>
public class te1 extends Configured implements Tool {
public static class MapClass extends MapReduceBase
implements Mapper<IntWritable, Text, Text, IntWritable> {
private static int one ;//= new int();
private static IntWritable on=new IntWritable();
private Text word = new Text();
public void map(IntWritable key, Text value,
OutputCollector<IntWritable,Text> output,
Reporter reporter) throws IOException {
String line1 = value.toString();
StringTokenizer itr = new StringTokenizer(line1);//String line1= value.toString();//int onet;
while (itr.hasMoreTokens()) {
// = value.toString();
//word.set(itr.nextToken());
word.set(itr.nextToken());line1=word.toString();
one=Integer.parseInt(line1);
//on=one;
//one=IntWritable(onet);
if(one==1)
word.set("onee");
else word.set("not onee");
on.set(one);
output.collect(on,word);
}
}
}
public static class Reduce extends MapReduceBase
implements Reducer<IntWritable, Text, Text, IntWritable> {
public void reduce(IntWritable key, Iterator<Text> values,
OutputCollector<IntWritable,Text> output,
Reporter reporter) throws IOException {
Text word1;// = new Text();
// int sum = 0;
while (values.hasNext()) {
word1 = values.next();
output.collect(key, word1);
}
}
}
public int run(String[] args) throws Exception {
JobConf conf = new JobConf(getConf(), te1.class);
conf.setJobName("te1");
// the keys are words (strings)
conf.setOutputKeyClass(IntWritable.class);
// the values are counts (ints)
conf.setOutputValueClass(Text.class);
FileInputFormat.setInputPaths(conf, args[0]);
conf.setMapperClass(MapClass.class);
conf.setCombinerClass(Reduce.class);
conf.setReducerClass(Reduce.class);
FileOutputFormat.setOutputPath(conf, new Path(args[1]));
//conf.setOutputFormat(SequenceFileOutputFormat.class);
//conf.setOutputKeyClass(IntWritable.class);
//conf.setOutputValueClass(Text.class);
/* List<String> other_args = new ArrayList<String>();
for(int i=0; i < args.length; ++i) {
try {
if ("-m".equals(args[i])) {
conf.setNumMapTasks(Integer.parseInt(args[++i]));
} else if ("-r".equals(args[i])) {
conf.setNumReduceTasks(Integer.parseInt(args[++i]));
} else {
other_args.add(args[i]);
}
} catch (NumberFormatException except) {
System.out.println("ERROR: Integer expected instead of " + args[i]);
return printUsage();
} catch (ArrayIndexOutOfBoundsException except) {
System.out.println("ERROR: Required parameter missing from " +
args[i-1]);
return printUsage();
}
}*/
// Make sure there are exactly 2 parameters left.
/* if (other_args.size() != 2) {
System.out.println("ERROR: Wrong number of parameters: " +
other_args.size() + " instead of 2.");
return printUsage();
}*/
JobClient.runJob(conf);
return 0;
}
public static void main(String[] args) throws Exception {
int res = ToolRunner.run(new Configuration(), new te1(), args);
System.exit(res);
}
}