Created by liwei on 9/27/16.
| 14 | * Created by liwei on 9/27/16. |
| 15 | */ |
| 16 | public class DocMetaMapper extends Mapper<LongWritable, Text, Text, Text> { |
| 17 | |
| 18 | private String metaService_; |
| 19 | private String bussiness_; |
| 20 | private String metaUrl_; |
| 21 | private String logDay_; |
| 22 | private String shortDay_; |
| 23 | private String lines_ = ""; |
| 24 | private int count_ = 0; |
| 25 | private boolean firstkey_ = true; |
| 26 | private String filename_; |
| 27 | |
| 28 | @Override |
| 29 | protected void setup(org.apache.hadoop.mapreduce.Mapper.Context context) |
| 30 | throws java.io.IOException, java.lang.InterruptedException { |
| 31 | super.setup(context); |
| 32 | System.err.println(context.getInputSplit().toString()); |
| 33 | metaService_ = context.getConfiguration().get("meta_service"); |
| 34 | bussiness_ = context.getConfiguration().get("log_name"); |
| 35 | metaUrl_ = new String("http://" + metaService_ + "/service/meta/" + bussiness_ + "/doc/set"); |
| 36 | logDay_ = context.getConfiguration().get("log_day"); |
| 37 | shortDay_ = logDay_.replace("-", "").substring(2); |
| 38 | FileSplit split = (FileSplit) context.getInputSplit(); |
| 39 | filename_ = split.getPath().getName(); |
| 40 | System.err.println("get shortDay: " + shortDay_); |
| 41 | } |
| 42 | |
| 43 | @Override |
| 44 | protected void cleanup(Context context) throws IOException, InterruptedException { |
| 45 | super.cleanup(context); |
| 46 | System.err.println("cleanup"); |
| 47 | set(); |
| 48 | } |
| 49 | |
| 50 | @Override |
| 51 | protected void map(LongWritable key, Text value, Mapper<LongWritable, Text, Text, Text>.Context context) |
| 52 | throws IOException, InterruptedException { |
| 53 | |
| 54 | |
| 55 | //System.err.println(value.toString()); |
| 56 | String[] meta = value.toString().split("\t"); |
| 57 | if (meta.length < 2) { |
| 58 | return; |
| 59 | } |
| 60 | if (firstkey_) { |
| 61 | firstkey_ = false; |
| 62 | context.write(new Text(filename_), new Text(meta[0])); |
| 63 | } |
| 64 | //System.err.println(meta[1]); |
| 65 | //byte[] rawPb = Base64.decodeBase64(meta[1]); |
| 66 | //proto.PoseidonIf.DocGzMeta gzmeta = proto.PoseidonIf.DocGzMeta.parseFrom(rawPb); |
| 67 | //System.err.println(gzmeta.toString()); |
| 68 | |
| 69 | String line = shortDay_ + meta[0] + "\t" + meta[1]; |
| 70 | lines_ += line; |
| 71 | lines_ += "\n"; |
| 72 | count_ += 1; |
| 73 | if (count_ >= 50) { |
nothing calls this directly
no outgoing calls
no test coverage detected