@Override public int compareTo(ByteArray o) { if (this.data == null && o.data == null) return 0; else if (this.data == null) return -1; else if (o.data == null) return 1; else return Bytes.compareTo(this.data, this.offset, this.length, o.data, o.offset, o.length); }
@Override public int compareTo(AppendDictSliceKey that) { return Bytes.compareTo(key, that.key); }
@Override public int compare(byte[] o1, byte[] o2) { if (compareAll) { return Bytes.compareTo(o1, o2); } int result = 0; // profiler shows this check is slow // Preconditions.checkArgument(keyLength == o1.length && keyLength == o2.length); for (int i = 0; i < keyLength; ++i) { if (compareMask[i]) { int a = (o1[i] & 0xff); int b = (o2[i] & 0xff); result = a - b; if (result == 0) { continue; } else { return result; } } } return result; } };
/** * @param left left operand * @param right right operand * @return True if equal */ public static boolean equals(final byte[] left, final byte[] right) { // Could use Arrays.equals? //noinspection SimplifiableConditionalExpression if (left == right) return true; if (left == null || right == null) return false; if (left.length != right.length) return false; if (left.length == 0) return true; // Since we're often comparing adjacent sorted data, // it's usual to have equal arrays except for the very last byte // so check that first if (left[left.length - 1] != right[right.length - 1]) return false; return compareTo(left, right) == 0; }
@Override public int compare(byte[] o1, byte[] o2) { return Bytes.compareTo(o1, o2); } });
bPadded = b; if (compareTo(aPadded, bPadded) >= 0) { throw new IllegalArgumentException("b <= a");
public static ByteBuffer getValueAsByteBuffer(Result hbaseRow, byte[] cf, byte[] cq) { List<Cell> cells = hbaseRow.listCells(); if (cells == null || cells.size() == 0) { return null; } else { for (Cell c : cells) { if (Bytes.compareTo(cf, 0, cf.length, c.getFamilyArray(), c.getFamilyOffset(), c.getFamilyLength()) == 0 && // Bytes.compareTo(cq, 0, cq.length, c.getQualifierArray(), c.getQualifierOffset(), c.getQualifierLength()) == 0) { return ByteBuffer.wrap(c.getValueArray(), c.getValueOffset(), c.getValueLength()); } } } return null; }
/** * @return true if should bypass this record */ boolean shouldByPass(GTRecord record) { if (dumps.size() > 0) { return false; //rare case: limit tends to be small, when limit is applied it's not likely to have dumps //TODO: what if bypass before dump happens? } Preconditions.checkState(aggBufMap.size() <= aggregateBufferSizeLimit); if (aggBufMap.size() == aggregateBufferSizeLimit) { Preconditions.checkNotNull(currentLastKey); for (int i = 0; i < groupBy.trueBitCount(); i++) { int c = groupBy.trueBitAt(i); ByteArray col = record.get(c); int compare = Bytes.compareTo(col.array(), col.offset(), col.length(), currentLastKey, groupOffsetsInLastKey[i], col.length()); if (compare > 0) { byPassCounter++; return true; } else if (compare < 0) { return false; } } } return false; }
@Test public void testBasic() throws Exception { Configuration hconf = HadoopUtil.getCurrentConfiguration(); Context context = MockupMapContext.create(hconf, cubeName, outKV); CubeHFileMapper mapper = new CubeHFileMapper(); mapper.doSetup(context); Text key = new Text("not important"); Text value = new Text(new byte[] { 2, 2, 51, -79, 1 }); mapper.map(key, value, context); KeyValue outValue = (KeyValue) outKV[1]; assertTrue(Bytes.compareTo(value.getBytes(), 0, value.getLength(), outValue.getValueArray(), outValue.getValueOffset(), outValue.getValueLength()) == 0); }
@Override public int compareTo(ByteArray o) { return Bytes.compareTo(this.data, o.data); } }
@Override public int compareTo(ByteArray o) { if (this.data == null && o.data == null) return 0; else if (this.data == null) return -1; else if (o.data == null) return 1; else return Bytes.compareTo(this.data, this.offset, this.length, o.data, o.offset, o.length); }
@Override public int compare(byte[] left, byte[] right) { return compareTo(left, right); }
@Override public int compareTo(AppendDictSliceKey that) { return Bytes.compareTo(key, that.key); }
/** * @param left left operand * @param right right operand * @return True if equal */ public static boolean equals(final byte[] left, final byte[] right) { // Could use Arrays.equals? //noinspection SimplifiableConditionalExpression if (left == right) return true; if (left == null || right == null) return false; if (left.length != right.length) return false; if (left.length == 0) return true; // Since we're often comparing adjacent sorted data, // it's usual to have equal arrays except for the very last byte // so check that first if (left[left.length - 1] != right[right.length - 1]) return false; return compareTo(left, right) == 0; }
/** * @param left left operand * @param right right operand * @return True if equal */ public static boolean equals(final byte[] left, final byte[] right) { // Could use Arrays.equals? //noinspection SimplifiableConditionalExpression if (left == right) return true; if (left == null || right == null) return false; if (left.length != right.length) return false; if (left.length == 0) return true; // Since we're often comparing adjacent sorted data, // it's usual to have equal arrays except for the very last byte // so check that first if (left[left.length - 1] != right[right.length - 1]) return false; return compareTo(left, right) == 0; }
@Override public int compare(byte[] o1, byte[] o2) { if (compareAll) { return Bytes.compareTo(o1, o2); } int result = 0; // profiler shows this check is slow // Preconditions.checkArgument(keyLength == o1.length && keyLength == o2.length); for (int i = 0; i < keyLength; ++i) { if (compareMask[i]) { int a = (o1[i] & 0xff); int b = (o2[i] & 0xff); result = a - b; if (result == 0) { continue; } else { return result; } } } return result; } };
bPadded = b; if (compareTo(aPadded, bPadded) >= 0) { throw new IllegalArgumentException("b <= a");
bPadded = b; if (compareTo(aPadded, bPadded) >= 0) { throw new IllegalArgumentException("b <= a");
/** * @return true if should bypass this record */ boolean shouldByPass(GTRecord record) { if (dumps.size() > 0) { return false; //rare case: limit tends to be small, when limit is applied it's not likely to have dumps //TODO: what if bypass before dump happens? } Preconditions.checkState(aggBufMap.size() <= aggregateBufferSizeLimit); if (aggBufMap.size() == aggregateBufferSizeLimit) { Preconditions.checkNotNull(currentLastKey); for (int i = 0; i < groupBy.trueBitCount(); i++) { int c = groupBy.trueBitAt(i); ByteArray col = record.get(c); int compare = Bytes.compareTo(col.array(), col.offset(), col.length(), currentLastKey, groupOffsetsInLastKey[i], col.length()); if (compare > 0) { byPassCounter++; return true; } else if (compare < 0) { return false; } } } return false; }
public static ByteBuffer getValueAsByteBuffer(Result hbaseRow, byte[] cf, byte[] cq) { List<Cell> cells = hbaseRow.listCells(); if (cells == null || cells.size() == 0) { return null; } else { for (Cell c : cells) { if (Bytes.compareTo(cf, 0, cf.length, c.getFamilyArray(), c.getFamilyOffset(), c.getFamilyLength()) == 0 && // Bytes.compareTo(cq, 0, cq.length, c.getQualifierArray(), c.getQualifierOffset(), c.getQualifierLength()) == 0) { return ByteBuffer.wrap(c.getValueArray(), c.getValueOffset(), c.getValueLength()); } } } return null; }