Java code doesn't produce output



0
Hi,

The following program from module 3 assignment 2 is not producing output. And also the java code is compiling with warnings.

String monthYear=date.getYear() + "_" + date.getMonth();

the above line in eclipse is displaying as if striked off. Can you please help?

/************************************************/

package com.assignments;

import java.io.IOException;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Iterator;

import org.apache.hadoop.fs.Path;
import org.apache.hadoop.io.DoubleWritable;
import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapred.FileInputFormat;
import org.apache.hadoop.mapred.FileOutputFormat;
import org.apache.hadoop.mapred.JobClient;
import org.apache.hadoop.mapred.JobConf;
import org.apache.hadoop.mapred.MapReduceBase;
import org.apache.hadoop.mapred.Mapper;
import org.apache.hadoop.mapred.OutputCollector;
import org.apache.hadoop.mapred.Reducer;
import org.apache.hadoop.mapred.Reporter;
import org.apache.hadoop.mapred.TextInputFormat;
import org.apache.hadoop.mapred.TextOutputFormat;

public class NasdaqAssignment2 {
private static DateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
public static class Map extends MapReduceBase implements Mapper {
private Text stock_month = new Text();
private DoubleWritable price = new DoubleWritable(1.0D);
private final static Long threshold=300000L;

public void map(LongWritable key, Text value, OutputCollector output, Reporter reporter) throws IOException {
String line = value.toString();
String[] tokens = line.split(",");
if(!tokens[0].equals("exchange"))
{
Long volume=Long.parseLong(tokens[7]);
if(volume>threshold)
{
Date date;
try {
date = formatter.parse(tokens[2]);
String monthYear=date.getYear() + "_" + date.getMonth();
stock_month.set(tokens[1] + "_" + monthYear);
price.set(Double.parseDouble(tokens[4]));
output.collect(stock_month, price);
} catch (ParseException e) {
e.printStackTrace();
}

}
}
}
}

public static class Reduce extends MapReduceBase implements Reducer {
public void reduce(Text key, Iterator values, OutputCollector output, Reporter reporter) throws IOException {
double highestPrice = 0;
while (values.hasNext()) {
Double price=values.next().get();
if(price>highestPrice)
{
highestPrice=price;
}
}
output.collect(key, new DoubleWritable(highestPrice));
}
}

public static void main(String[] args) throws Exception {
JobConf conf = new JobConf(NasdaqAssignment2.class);
conf.setJobName("nasdaq2");

conf.setOutputKeyClass(Text.class);
conf.setOutputValueClass(DoubleWritable.class);

conf.setMapperClass(Map.class);
conf.setReducerClass(Reduce.class);

conf.setInputFormat(TextInputFormat.class);
conf.setOutputFormat(TextOutputFormat.class);

FileInputFormat.setInputPaths(conf, new Path(args[0]));
FileOutputFormat.setOutputPath(conf, new Path(args[1]));

JobClient.runJob(conf);
}
}

2 Answer(s)


0

Hello Srinivasa:

If you hover over the "strikeouts" with the mouse, you will see that the "strikeout", in this case, is indicating a deprecated method, getYear().

The quick fix is to add the @SuppressWarnings("deprecation") on the line just prior to the deprecated method. The strikeout will still appear, however.

Or, if you want to experiment, you could modify the deprecated method with the new Calendar.get(Calendar.YEAR)-1900 method. This information will appear once you add the "@Supr.." on the prior line and hovering over the "strikeout" with your mouse.

However, the program should still work as written with the deprecated method.

0

hi Srinivasa,

Strike through is enabled in eclipse only if the method is deprecated and the program will work without issues.

in the below line Year and Month are concatenated and printed (
String monthYear=date.getYear() + "_" + date.getMonth();). Please check if there is any problem with the input data as the code looks fine.

Your Answer

Click on this code-snippet-icon icon to add code snippet.

Upload Files (Maximum image file size - 1.5 MB, other file size - 10 MB, total size - not more than 50 MB)

Email
Password