forked from cloudera/emailarchive
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ConvertEmailsToSequence.java
executable file
·71 lines (58 loc) · 2.42 KB
/
ConvertEmailsToSequence.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
import java.io.IOException;
import org.apache.hadoop.conf.Configured;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.io.BytesWritable;
import org.apache.hadoop.io.NullWritable;
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.Reporter;
import org.apache.hadoop.mapred.SequenceFileOutputFormat;
import org.apache.hadoop.mapred.lib.IdentityReducer;
import org.apache.hadoop.util.Tool;
import org.apache.hadoop.util.ToolRunner;
public class ConvertEmailsToSequence extends Configured
implements Tool {
static class SequenceFileMapper extends MapReduceBase
implements Mapper<NullWritable, BytesWritable, Text, BytesWritable> {
private JobConf conf;
@Override
public void configure(JobConf conf) {
this.conf = conf;
}
@Override
public void map(NullWritable key, BytesWritable value,
OutputCollector<Text, BytesWritable> output, Reporter reporter)
throws IOException {
String filename = conf.get("map.input.file");
output.collect(new Text(filename), value);
}
}
@Override
public int run(String[] args) throws IOException {
JobConf jobConf = new JobConf(ConvertEmailsToSequence.class);
jobConf.setJobName("SequenceCreator");
FileInputFormat.setInputPaths(jobConf, new Path(args[0]));
FileOutputFormat.setOutputPath(jobConf, new Path(args[1]));
jobConf.setInputFormat(WholeFileInputFormat.class);
jobConf.setOutputFormat(SequenceFileOutputFormat.class);
// SequenceFileOutputFormat.setOutputCompressionType(jobConf, CompressionType.BLOCK);
// SequenceFileOutputFormat.setCompressOutput(jobConf, true);
// SequenceFileOutputFormat.setOutputCompressorClass(jobConf, GzipCodec.class);
jobConf.setOutputKeyClass(Text.class);
jobConf.setOutputValueClass(BytesWritable.class);
jobConf.setMapperClass(SequenceFileMapper.class);
jobConf.setReducerClass(IdentityReducer.class);
JobClient.runJob(jobConf);
return 0;
}
public static void main(String[] args) throws Exception {
int exitCode = ToolRunner.run(new ConvertEmailsToSequence(), args);
System.exit(exitCode);
}
}