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 10, 2019 in Big Data Hadoop by digger
• 26,670 points
142 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 10, 2019 by Omkar
• 69,040 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 2 in Big Data Hadoop by chima

edited Mar 4 by Gitika 408 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,040 points
89 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 29, 2018 in Big Data Hadoop by Ashish
• 2,630 points
852 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
• 10,920 points
1,147 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
• 10,920 points
5,303 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
• 10,920 points
778 views
+1 vote
11 answers

hadoop fs -put command?

put syntax: put <localSrc> <dest> copy syntax: copyF ...READ MORE

answered Dec 7, 2018 in Big Data Hadoop by Aditya
32,360 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,310 points
2,001 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,040 points
169 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,040 points
955 views