/
CouchbaseImportMapper.java
50 lines (40 loc) · 1.29 KB
/
CouchbaseImportMapper.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
package com.couchbase.sqoop.mapreduce;
import com.cloudera.sqoop.lib.LargeObjectLoader;
import com.cloudera.sqoop.lib.SqoopRecord;
import com.cloudera.sqoop.mapreduce.AutoProgressMapper;
import java.io.IOException;
import java.sql.SQLException;
import org.apache.hadoop.io.NullWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat;
public class CouchbaseImportMapper
extends AutoProgressMapper<Text, SqoopRecord, Text, NullWritable> {
private Text outkey;
private LargeObjectLoader lobLoader;
public CouchbaseImportMapper() {
outkey = new Text();
}
@Override
protected void setup(Context context)
throws IOException, InterruptedException {
this.lobLoader = new LargeObjectLoader(context.getConfiguration(),
FileOutputFormat.getWorkOutputPath(context));
}
@Override
public void map(Text key, SqoopRecord val, Context context)
throws IOException, InterruptedException {
try {
val.loadLargeObjects(lobLoader);
} catch (SQLException sqlE) {
throw new IOException(sqlE);
}
outkey.set(val.toString());
context.write(outkey, NullWritable.get());
}
@Override
protected void cleanup(Context context) throws IOException {
if (null != lobLoader) {
lobLoader.close();
}
}
}