-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathReadLoveFromHDFSMapper.java
35 lines (31 loc) · 1.11 KB
/
ReadLoveFromHDFSMapper.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
package HbaseHDFS;
import org.apache.hadoop.hbase.client.Put;
import org.apache.hadoop.hbase.io.ImmutableBytesWritable;
import org.apache.hadoop.hbase.util.Bytes;
import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Mapper;
import java.io.IOException;
/**
* @author CDMloong
* @version 1.0
*/
public class ReadLoveFromHDFSMapper extends Mapper<LongWritable, Text, ImmutableBytesWritable, Put> {
@Override
protected void map(LongWritable key, Text value, Context context) throws IOException, InterruptedException {
//1.读取数据
String line = value.toString();
//2.切分数据
String[] split = line.split("\t");
//3.封装数据
byte[] rowKey = Bytes.toBytes(split[0]);
byte[] name = Bytes.toBytes(split[1]);
byte[] desc = Bytes.toBytes(split[2]);
//封装put对象
Put put = new Put(rowKey);
put.addColumn(Bytes.toBytes("info"),Bytes.toBytes("name"),name);
put.addColumn(Bytes.toBytes("info"),Bytes.toBytes("desc"),desc);
//4.传输数据到Reducer
context.write(new ImmutableBytesWritable(rowKey),put);
}
}