-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProSel.java
More file actions
62 lines (53 loc) · 1.9 KB
/
ProSel.java
File metadata and controls
62 lines (53 loc) · 1.9 KB
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
import java.io.IOException;
import java.util.*;
import org.apache.hadoop.conf.*;
import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.io.*;
import org.apache.hadoop.mapreduce.*;
import org.apache.hadoop.mapreduce.lib.input.*;
import org.apache.hadoop.mapreduce.lib.output.*;
import org.apache.hadoop.util.GenericOptionsParser;
public class ProSel
{
public static class ProSelMapper extends Mapper<Object, Text, Text, Text>
{
private Text word = new Text();
private Text result = new Text(new byte[0]);
public void map(Object key, Text value, Context context) throws IOException, InterruptedException
{
StringTokenizer itr = new StringTokenizer(value.toString(), "|");
if(itr.countTokens() < 4) return;
String emp_id = itr.nextToken().trim();
String dept_id = itr.nextToken().trim();
int salary = Integer.parseInt(itr.nextToken().trim());
String emp_info = itr.nextToken().trim();
if(salary >= 3500000) {
word.set(new byte[0]);
word.set(emp_id + "|" + salary);
context.write(word, result);
}
}
}
// REDUCER 필요없음
public static void main(String[] args) throws Exception
{
Configuration conf = new Configuration();
String[] otherArgs = new GenericOptionsParser(conf, args).getRemainingArgs();
if (otherArgs.length != 2)
{
System.err.println("Usage: ProSel <in> <out>");
System.exit(2);
}
Job job = new Job(conf, "ProSel");
job.setJarByClass(ProSel.class);
job.setMapperClass(ProSelMapper.class);
job.setNumReduceTasks(0); // reduce 사용 안 한다는 뜻
job.setOutputKeyClass(Text.class);
job.setOutputValueClass(Text.class);
FileInputFormat.addInputPath(job, new Path(otherArgs[0]));
FileOutputFormat.setOutputPath(job, new Path(otherArgs[1]));
FileSystem.get(job.getConfiguration()).delete( new Path(otherArgs[1]), true);
System.exit(job.waitForCompletion(true) ? 0 : 1);
}
}