Not able to run java mapreduce

0 votes

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 in Big Data Hadoop by digger
• 27,620 points
33 views

1 answer to this question.

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.
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 by Omkar
• 65,840 points

Related Questions In Big Data Hadoop

0 votes
1 answer

Not able to run Hive queries.

Try bin/hive -e 'LOAD DATA INPATH kv1.txt OVERWRITE ...READ MORE

answered Aug 30, 2018 in Big Data Hadoop by Frankie
• 9,570 points
96 views
0 votes
1 answer

Not able to execute mapreduce code

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

answered Jan 7 in Big Data Hadoop by Omkar
• 65,840 points
17 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
228 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
• 9,030 points
96 views
0 votes
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
• 9,030 points
1,646 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
• 9,030 points
130 views
0 votes
10 answers

hadoop fs -put command?

copy command can be used to copy files ...READ MORE

answered Dec 7, 2018 in Big Data Hadoop by Sujay
7,986 views
0 votes
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,260 points
555 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
• 65,840 points
25 views
0 votes
1 answer

Not able to run hdfs commands

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

answered Jan 3 in Big Data Hadoop by Omkar
• 65,840 points
55 views

© 2018 Brain4ce Education Solutions Pvt. Ltd. All rights Reserved.
"PMP®","PMI®", "PMI-ACP®" and "PMBOK®" are registered marks of the Project Management Institute, Inc. MongoDB®, Mongo and the leaf logo are the registered trademarks of MongoDB, Inc.