Not able to run java mapreduce

–1 vote

I have the following java code:

import java.io.IOException;

import org.apache.hadoop.io.LongWritable;

import org.apache.hadoop.io.Text;

import org.apache.hadoop.mapreduce.Mapper;

import org.apache.hadoop.conf.Configuration;

import org.apache.hadoop.mapreduce.Job;

import org.apache.hadoop.mapreduce.lib.input.TextInputFormat;

import org.apache.hadoop.mapreduce.lib.output.TextOutputFormat;

import org.apache.hadoop.mapreduce.lib.input.FileInputFormat;

import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat;

import org.apache.hadoop.fs.Path;


public class HotColdDay {

public static class Map extends

Mapper<LongWritable, Text, Text, Text> {

static long counter = 0; 

   

        @Override 

        public void map(LongWritable key, Text value, Context context)

throws IOException, InterruptedException {

       

        counter++;

       

        String line = value.toString();

        String[] lineInputs = line.split("\\s+");

       

        Text date = new Text();

        date.set(lineInputs[1]);

       

        Double maxTemp = Double.parseDouble(lineInputs[5]);

        Double minTemp = Double.parseDouble(lineInputs[6]);

       

        System.out.println("counter=" + counter +"date="+ date + "minTemp=" + minTemp + "maxTemp=" + maxTemp);

       

        String coldDay = "";

       

        if(minTemp < 10 ) {

        coldDay = "Cold Day";

        }

        else if (maxTemp > 40)

        coldDay = "Hot Day";

        else coldDay = "Normal Day";

       

        Text coldDayText = new Text();

        coldDayText.set(coldDay);

                       

            context.write(date, coldDayText); 


        } 

    } 

    

     

    

    public static void main(String[] args) throws Exception {     

Configuration conf = new Configuration();

Job job = new Job(conf, "HotColdDay");

job.setJarByClass(HotColdDay.class);

job.setMapperClass(Map.class);

//job.setReducerClass(Reduce.class);

job.setMapOutputKeyClass(Text.class);

job.setMapOutputValueClass(Text.class);

job.setOutputKeyClass(Text.class);

job.setOutputValueClass(Text.class);

job.setInputFormatClass(TextInputFormat.class);

job.setOutputFormatClass(TextOutputFormat.class);

job.setNumReduceTasks(0);

        Path outputPath = new Path(args[1]);

        

        FileInputFormat.addInputPath(job, new Path(args[0]));

FileOutputFormat.setOutputPath(job, new Path(args[1]));

outputPath.getFileSystem(conf).delete(outputPath);

System.exit(job.waitForCompletion(true) ? 0 : 1);

    } 

}

I am getting the following error:

Jan 11, 2019 in Big Data Hadoop by digger
• 26,740 points
1,182 views

1 answer to this question.

0 votes
The error which you are getting i.e ArrayIndexOutOfBound Exception is because there are some extra spaces at the end of the dataset.

Please remove any extra spaces available at the end of the dataset and then try to execute the code once more. It should work
answered Jan 11, 2019 by Omkar
• 69,230 points

Related Questions In Big Data Hadoop

0 votes
2 answers

Not able to run Hive queries.

If you are loading your data from ...READ MORE

answered Mar 3, 2020 in Big Data Hadoop by chima

edited Mar 4, 2020 by Gitika 1,593 views
–1 vote
1 answer

Not able to execute mapreduce code

Follow the below steps to execute the ...READ MORE

answered Jan 7, 2019 in Big Data Hadoop by Omkar
• 69,230 points
598 views
0 votes
1 answer

Not able to start Job History Server in Hadoop 2.8.1

You have to start JobHistoryServer process specifically ...READ MORE

answered Mar 30, 2018 in Big Data Hadoop by Ashish
• 2,650 points
2,501 views
0 votes
1 answer

Not able to find HDFS directory on my system?

I guess you didn't understand it correctly dfs.datanode.data.dir, ...READ MORE

answered Apr 17, 2018 in Big Data Hadoop by nitinrawat895
• 11,380 points
7,532 views
+1 vote
1 answer

Hadoop Mapreduce word count Program

Firstly you need to understand the concept ...READ MORE

answered Mar 16, 2018 in Data Analytics by nitinrawat895
• 11,380 points
10,908 views
0 votes
1 answer

hadoop.mapred vs hadoop.mapreduce?

org.apache.hadoop.mapred is the Old API  org.apache.hadoop.mapreduce is the ...READ MORE

answered Mar 16, 2018 in Data Analytics by nitinrawat895
• 11,380 points
2,439 views
+2 votes
11 answers

hadoop fs -put command?

Hi, You can create one directory in HDFS ...READ MORE

answered Mar 16, 2018 in Big Data Hadoop by nitinrawat895
• 11,380 points
108,204 views
–1 vote
1 answer

Hadoop dfs -ls command?

In your case there is no difference ...READ MORE

answered Mar 16, 2018 in Big Data Hadoop by kurt_cobain
• 9,390 points
4,533 views
0 votes
1 answer

Not able to run mapreduce job. Attempt failes error

The most common reason for this is ...READ MORE

answered Nov 22, 2018 in Big Data Hadoop by Omkar
• 69,230 points
1,200 views
0 votes
1 answer

Not able to run hdfs commands

Because you said it ran yesterday and ...READ MORE

answered Jan 3, 2019 in Big Data Hadoop by Omkar
• 69,230 points
3,135 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP