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.FileInputFor mat;
import org.apache.hadoop.mapreduce.lib.output.FileOutputF ormat;
public class VaccineCount {
public static class VaccineMapper extends Mapper<Object, Text, Text, IntWritable> {
private Text state = new Text();
private IntWritable vaccinatedCount = new IntWritable();
public void map(Object key, Text value, Context context) throws IOException, InterruptedException {
String line = value.toString();
if (!line.startsWith("Date") ) {
String[] fields = value.toString().split(",");
String stateName = fields[1];
int lastColumnIndex = fields.length - 1;
for (int i = 2; i < fields.length; i++) {
if (fields[i].equalsIgnoreCase("Total Individuals Vaccinated")) {
lastColumnIndex = i;
break;
}
}
int count = Integer.parseInt(fields[fields.length - 1]);
state.set(stateName);
vaccinatedCount.set(count);
context.write(state, vaccinatedCount);
}
}
public static class VaccineReducer extends Reducer<Text, IntWritable, Text, IntWritable> {
private IntWritable totalVaccinatedCount = new IntWritable();
public void reduce(Text key, Iterable<IntWritable> values, Context context)
throws IOException, InterruptedException {
int sum = 0;
for (IntWritable count : values) {
sum += count.get();
}
totalVaccinatedCount.set(sum);
context.write(key, totalVaccinatedCount);
}
}
public static void main(String[] args) throws Exception {
Configuration conf = new Configuration();
Job job = Job.getInstance(conf, "VaccineCount");
job.setJarByClass(VaccineCount.class);
job.setMapperClass(VaccineMapper.class);
job.setReducerClass(VaccineReducer.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);
}
}
}
--- Update ---
after running this Vaccine.jar file in hadoop linux it is displaying Exception in thread "main" java.lang.NoSuchMethodException: VaccineCount.main([Ljava.lang.String
at java.base/java.lang.Class.getMethod(Class.java:2108)
at org.apache.hadoop.util.RunJar.run(RunJar.java:215)
at org.apache.hadoop.util.RunJar.main(RunJar.java:136 )