(String token, String type, long docid, int line_offset,
Mapper<LongWritable, Text, Text, Text>.Context context)
| 19 | } |
| 20 | |
| 21 | protected void Write(String token, String type, long docid, int line_offset, |
| 22 | Mapper<LongWritable, Text, Text, Text>.Context context) { |
| 23 | if (token.isEmpty() || token.compareTo("null") == 0) { |
| 24 | return; |
| 25 | } |
| 26 | byte[] token_buf = token.getBytes(); |
| 27 | int token_hash = MurmurHash3.murmurhash3_x86_32(token_buf, 0, token_buf.length, 0); |
| 28 | |
| 29 | if (token_hash < 0) { |
| 30 | token_hash = 0 - token_hash; |
| 31 | } |
| 32 | int partition_hash = token_hash / 200; |
| 33 | String new_key = String.format("%08d", partition_hash); |
| 34 | //String line = token + "\t" + type +"\t" + docid +"\t" + line_offset; |
| 35 | //StringBuffer ss = new StringBuffer(); |
| 36 | //ss.append(token).append("\t").append(type).append("\t").append("1").append("\t").append(docid).append(",").append(line_offset); |
| 37 | String ss = token + "\t" + type + "\t" + docid + "," + line_offset + "\t" + 1; |
| 38 | try { |
| 39 | //context.write(new Text(new_key), new Text(line)); |
| 40 | context.write(new Text(new_key), new Text(ss)); |
| 41 | } catch (IOException e) { |
| 42 | // TODO Auto-generated catch block |
| 43 | // e.printStackTrace(); |
| 44 | } catch (InterruptedException e) { |
| 45 | // TODO Auto-generated catch block |
| 46 | // e.printStackTrace(); |
| 47 | } catch (Exception e) { |
| 48 | // 可能会有异常java.io.IOException: Map Task output too many bytes! which shouldn't be more than 21474836480 |
| 49 | // 全部输出的话会产生ERROR org.apache.hadoop.mapred.Child: Error in syncLogs: java.io.IOException: Tasklog stderr size 1096750402 exceeded limit 1073741824 |
| 50 | //e.printStackTrace(); |
| 51 | } |
| 52 | //System.err.println(ss); |
| 53 | } |
| 54 | } |
no test coverage detected