1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 package org.apache.hadoop.hbase.mapreduce;
19
20 import java.io.IOException;
21 import java.util.Arrays;
22
23 import org.apache.hadoop.hbase.KeyValue;
24 import org.apache.hadoop.hbase.client.Put;
25 import org.apache.hadoop.hbase.mapreduce.ImportTsv.TsvParser.BadTsvLineException;
26 import org.apache.hadoop.hbase.mapreduce.ImportTsv.TsvParser.ParsedLine;
27 import org.apache.hadoop.hbase.util.Bytes;
28
29
30
31
32
33
34 public class TsvImporterCustomTestMapperForOprAttr extends TsvImporterMapper {
35 @Override
36 protected void populatePut(byte[] lineBytes, ParsedLine parsed, Put put, int i)
37 throws BadTsvLineException, IOException {
38 KeyValue kv;
39 kv = new KeyValue(lineBytes, parsed.getRowKeyOffset(), parsed.getRowKeyLength(),
40 parser.getFamily(i), 0, parser.getFamily(i).length, parser.getQualifier(i), 0,
41 parser.getQualifier(i).length, ts, KeyValue.Type.Put, lineBytes, parsed.getColumnOffset(i),
42 parsed.getColumnLength(i));
43 if (parsed.getIndividualAttributes() != null) {
44 String[] attributes = parsed.getIndividualAttributes();
45 for (String attr : attributes) {
46 String[] split = attr.split(ImportTsv.DEFAULT_ATTRIBUTES_SEPERATOR);
47 if (split == null || split.length <= 1) {
48 throw new BadTsvLineException(msg(attributes));
49 } else {
50 if (split[0].length() <= 0 || split[1].length() <= 0) {
51 throw new BadTsvLineException(msg(attributes));
52 }
53 put.setAttribute(split[0], Bytes.toBytes(split[1]));
54 }
55 }
56 }
57 put.add(kv);
58 }
59
60 private String msg(Object[] attributes) {
61 return "Invalid attributes separator specified: " + Arrays.toString(attributes);
62 }
63 }