首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 其他教程 > 其他相关 >

使用RawComparator加紧Hadoop程序

2013-12-28 
使用RawComparator加速Hadoop程序?http://yoyzhou.github.io/blog/2013/05/13/hadoop-write-ur-own-rawcom

使用RawComparator加速Hadoop程序

?

http://yoyzhou.github.io/blog/2013/05/13/hadoop-write-ur-own-rawcomparator/

?

static class MyComparator extends WritableComparator {static {WritableComparator.define(MyWritable.class, new MyComparator());}protected MyComparator() {super(MyWritable.class);}public int compare(byte[] b1, int s1, int l1, byte[] b2, int s2, int l2) {int cmp = 1;//determine how many bytes the first VLong takesint n1 = WritableUtils.decodeVIntSize(b1[s1]);int n2 = WritableUtils.decodeVIntSize(b2[s2]);try {//read value from VLongWritable byte arraylong l11 = readVLong(b1, s1);long l21 = readVLong(b2, s2);cmp = l11 > l21 ? 1 : (l11 == l21 ? 0 : -1);if (cmp != 0) {return cmp;} else {long l12 = readVLong(b1, s1 + n1);long l22 = readVLong(b2, s2 + n2);return cmp = l12 > l22 ? 1 : (l12 == l22 ? 0 : -1);}} catch (IOException e) {throw new RuntimeException(e);}}}static class MyWritable extends BinaryComparable implements WritableComparable<BinaryComparable> {@Overridepublic void write(DataOutput out) throws IOException {out.write("hello".getBytes());}@Overridepublic void readFields(DataInput in) throws IOException {String str = WritableUtils.readString(in);System.out.println(str);}@Overridepublic int getLength() {return 0;}@Overridepublic byte[] getBytes() {return null;}}

?

热点排行