I am running a mapreduce code, an error I am getting is
Error: java.lang.ClassCastException: org.apache.hadoop.io.LongWritable cannot be cast to org.apache.hadoop.io.IntWritable
at test.temp$Mymapper.map(temp.java:1)
at org.apache.hadoop.mapreduce.Mapper.run(Mapper.java:146)
at org.apache.hadoop.mapred.MapTask.runNewMapper(MapTask.java:787)
at org.apache.hadoop.mapred.MapTask.run(MapTask.java:341)
at org.apache.hadoop.mapred.YarnChild$2.run(YarnChild.java:164)
at java.security.AccessController.doPrivileged(Native Method)
at javax.security.auth.Subject.doAs(Subject.java:415)
at org.apache.hadoop.security.UserGroupInformation.doAs(UserGroupInformation.java:1657)
at org.apache.hadoop.mapred.YarnChild.main(YarnChild.java:158)
The code is given below:
package test;
import java.io.IOException;
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.mapred.JobConf;
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 temp {
public static class Mymapper extends Mapper<Object, Text, IntWritable,Text> {
public void map(Object key, Text value,Context context) throws IOException, InterruptedException{
int month=Integer.parseInt(value.toString().substring(17, 19));
IntWritable mon=new IntWritable(month);
String temp=value.toString().substring(27,31);
String t=null;
for(int i=0;i<temp.length();i++){
if(temp.charAt(i)==',')
break;
else
t=t+temp.charAt(i);
}
Text data=new Text(value.toString().substring(22, 26)+t);
context.write(mon, data);
}
}
public static class Myreducer extends Reducer<IntWritable,Text,IntWritable,IntWritable> {
public void reduce(IntWritable key,Iterable<Text> values,Context context) throws IOException, InterruptedException{
String temp="";
int max=0;
for(Text t:values)
{
temp=t.toString();
if(temp.substring(0, 4)=="TMAX"){
if(Integer.parseInt(temp.substring(4,temp.length()))>max){
max=Integer.parseInt(temp.substring(4,temp.length()));
}
}
}
context.write(key,new IntWritable(max));
}
}
public static void main(String[] args) throws Exception {
Configuration conf = new Configuration();
Job job = Job.getInstance(conf, "temp");
job.setJarByClass(temp.class);
job.setMapperClass(Mymapper.class);
job.setCombinerClass(Myreducer.class);
job.setReducerClass(Myreducer.class);
job.setOutputKeyClass(IntWritable.class);
job.setOutputValueClass(IntWritable.class);
FileInputFormat.addInputPath(job, new Path(args[0]));
FileOutputFormat.setOutputPath(job, new Path(args[1]));
job.waitForCompletion(true);
}
}
and the input file is
USC00300379,19000101,TMAX,-78,,,6, USC00300379,19000101,TMAX,-133,,,6, USC00300379,19000101,TMAX,127,,,6
kindly reply and help please!