-
Notifications
You must be signed in to change notification settings - Fork 0
/
AllTimeHigh.java
72 lines (61 loc) · 2.31 KB
/
AllTimeHigh.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
import java.io.*;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.DoubleWritable;
import org.apache.hadoop.mapreduce.Job;
import org.apache.hadoop.mapreduce.Mapper;
import org.apache.hadoop.mapreduce.Reducer;
import org.apache.hadoop.conf.*;
import org.apache.hadoop.fs.*;
import org.apache.hadoop.mapreduce.lib.input.*;
import org.apache.hadoop.mapreduce.lib.output.*;
public class AllTimeHigh {
public static class MapClass extends Mapper<LongWritable,Text,Text,DoubleWritable>
{
private Text stock_id = new Text();
private DoubleWritable High = new DoubleWritable();
public void map(LongWritable key, Text value, Context context)
{
try{
String[] str = value.toString().split(",");
double high = Double.parseDouble(str[4]);
stock_id.set(str[1]);
High.set(high);
context.write(stock_id, High);
}
catch(Exception e)
{
System.out.println(e.getMessage());
}
}
}
public static class ReduceClass extends Reducer<Text,DoubleWritable,Text,DoubleWritable>
{
private DoubleWritable result = new DoubleWritable();
public void reduce(Text key, Iterable<DoubleWritable> values,Context context) throws IOException, InterruptedException {
double maxValue=0;
double temp_val=0;
for (DoubleWritable value : values) {
temp_val = value.get();
if (temp_val > maxValue) {
maxValue = temp_val;
}
}
result.set(maxValue);
context.write(key, result);
}
}
public static void main(String[] args) throws Exception {
Configuration conf = new Configuration();
Job job = Job.getInstance(conf, "High");
job.setJarByClass(AllTimeHigh.class);
job.setMapperClass(MapClass.class);
job.setReducerClass(ReduceClass.class);
job.setNumReduceTasks(1);
job.setOutputKeyClass(Text.class);
job.setOutputValueClass(DoubleWritable.class);
FileInputFormat.addInputPath(job, new Path(args[0]));
FileOutputFormat.setOutputPath(job, new Path(args[1]));
System.exit(job.waitForCompletion(true) ? 0 : 1);
}
}