@Override protected Object clone() throws CloneNotSupportedException { super.clone(); return new KVComparator(); }
short lrowlength = left.getRowLength(); short rrowlength = right.getRowLength(); if ((left.getRowLength() + left.getFamilyLength() + left.getQualifierLength()) != (right .getRowLength() + right.getFamilyLength() + right.getQualifierLength())) { return false; if (!matchingRows(left, lrowlength, right, rrowlength)) { return false; int lfamilylength = left.getFamilyLength(); int rfamilylength = right.getFamilyLength(); int diff = compareFamilies(left.getFamilyArray(), lfoffset, lfamilylength, right.getFamilyArray(), rfoffset, rfamilylength); if (diff != 0) { return false; } else { diff = compareColumns(left.getQualifierArray(), left.getQualifierOffset(), lclength, right.getQualifierArray(), right.getQualifierOffset(), rclength); return diff == 0;
return Arrays.copyOf(rightKey, rightKey.length); if (compareFlatKey(leftKey, rightKey) >= 0) { throw new IllegalArgumentException("Unexpected input, leftKey:" + Bytes.toString(leftKey) + ", rightKey:" + Bytes.toString(rightKey)); short leftRowLength = Bytes.toShort(leftKey, 0); short rightRowLength = Bytes.toShort(rightKey, 0); int leftCommonLength = ROW_LENGTH_SIZE + FAMILY_LENGTH_SIZE + leftRowLength; int rightColumnLength = rightKey.length - rightCommonLengthWithTSAndType; if (leftRowLength == rightRowLength && compareRows(leftKey, ROW_LENGTH_SIZE, leftRowLength, rightKey, ROW_LENGTH_SIZE, rightRowLength) == 0) { return new KeyValue(newRowKey, null, null, HConstants.LATEST_TIMESTAMP, Type.Maximum).getKey();
long ts, byte type) { int compare = compareRows( cell.getRowArray(), cell.getRowOffset(), cell.getRowLength(), row, roff, rlen); if (compare != 0) { compare = compareFamilies( cell.getFamilyArray(), cell.getFamilyOffset(), cell.getFamilyLength(), fam, foff, flen); return compare; compare = compareColumns( cell.getQualifierArray(), cell.getQualifierOffset(), cell.getQualifierLength(), col, coff, clen); compare = compareTimestamps(cell.getTimestamp(), ts); if (compare != 0) { return compare;
/** * @param left * @param right * @return Result comparing rows. */ public int compareRows(final Cell left, final Cell right) { return compareRows(left.getRowArray(),left.getRowOffset(), left.getRowLength(), right.getRowArray(), right.getRowOffset(), right.getRowLength()); }
return Bytes.compareTo(left, lfamilyoffset + common, lfamilylength - common, right, rfamilyoffset + common, rfamilylength - common); final int comparison = Bytes.compareTo(left, lfamilyoffset + common, lcolumnlength - common, right, rfamilyoffset + common, rcolumnlength - common); long ltimestamp = Bytes.toLong(left, loffset + (llength - TIMESTAMP_TYPE_SIZE)); long rtimestamp = Bytes.toLong(right, roffset + (rlength - TIMESTAMP_TYPE_SIZE)); int compare = compareTimestamps(ltimestamp, rtimestamp); if (compare != 0) { return compare;
@Override public int compare(byte[] left, int loffset, int llength, byte[] right, int roffset, int rlength) { // BytesWritable and KeyValue each serialize 4 bytes to indicate length if (llength < 8) { throw new AssertionError("Too small llength: " + llength); } if (rlength < 8) { throw new AssertionError("Too small rlength: " + rlength); } Cell leftKey = new KeyValue(left, loffset + 8, llength - 8); Cell rightKey = new KeyValue(right, roffset + 8, rlength - 8); int rowCmp = Bytes.compareTo( leftKey.getRowArray(), leftKey.getRowOffset(), leftKey.getRowLength(), rightKey.getRowArray(), rightKey.getRowOffset(), rightKey.getRowLength()); if (rowCmp != 0) { return rowCmp; } else { return KeyValue.COMPARATOR.compare(leftKey, rightKey); } }
/** * Subclasses can call this method to make sure the first KV is within multi-writer range. * @param left The left boundary of the writer. * @param row The row to check. * @param rowOffset Offset for row. * @param rowLength Length for row. */ protected void sanityCheckLeft( byte[] left, byte[] row, int rowOffset, int rowLength) throws IOException { if (StripeStoreFileManager.OPEN_KEY != left && comparator.compareRows(row, rowOffset, rowLength, left, 0, left.length) < 0) { String error = "The first row is lower than the left boundary of [" + Bytes.toString(left) + "]: [" + Bytes.toString(row, rowOffset, rowLength) + "]"; LOG.error(error); throw new IOException(error); } }
public boolean moreRowsMayExistAfter(Cell kv) { if (this.isReversed) { if (rowComparator.compareRows(kv.getRowArray(), kv.getRowOffset(), kv.getRowLength(), stopRow, 0, stopRow.length) <= 0) { return false; } else { return true; } } if (!Bytes.equals(stopRow , HConstants.EMPTY_END_ROW) && rowComparator.compareRows(kv.getRowArray(),kv.getRowOffset(), kv.getRowLength(), stopRow, 0, stopRow.length) >= 0) { // KV >= STOPROW // then NO there is nothing left. return false; } else { return true; } }
/** * @param left * @param lrowlength * @param right * @param rrowlength * @return True if rows match. */ private boolean matchingRows(final Cell left, final short lrowlength, final Cell right, final short rrowlength) { return lrowlength == rrowlength && matchingRows(left.getRowArray(), left.getRowOffset(), lrowlength, right.getRowArray(), right.getRowOffset(), rrowlength); }
public byte[] calcIndexKey(byte[] lastKeyOfPreviousBlock, byte[] firstKeyInBlock) { byte[] fakeKey = getShortMidpointKey(lastKeyOfPreviousBlock, firstKeyInBlock); if (compareFlatKey(fakeKey, firstKeyInBlock) > 0) { LOG.error("Unexpected getShortMidpointKey result, fakeKey:" + Bytes.toStringBinary(fakeKey) + ", firstKeyInBlock:" + Bytes.toStringBinary(firstKeyInBlock)); return firstKeyInBlock; } if (lastKeyOfPreviousBlock != null && compareFlatKey(lastKeyOfPreviousBlock, fakeKey) >= 0) { LOG.error("Unexpected getShortMidpointKey result, lastKeyOfPreviousBlock:" + Bytes.toStringBinary(lastKeyOfPreviousBlock) + ", fakeKey:" + Bytes.toStringBinary(fakeKey)); return firstKeyInBlock; } return fakeKey; }
@Override public int compare(byte[] left, int loffset, int llength, byte[] right, int roffset, int rlength) { // BytesWritable and KeyValue each serialize 4 bytes to indicate length if (llength < 8) { throw new AssertionError("Too small llength: " + llength); } if (rlength < 8) { throw new AssertionError("Too small rlength: " + rlength); } Cell leftKey = new KeyValue(left, loffset + 8, llength - 8); Cell rightKey = new KeyValue(right, roffset + 8, rlength - 8); byte[] lRow = leftKey.getRow(); byte[] rRow = rightKey.getRow(); int rowCmp = Bytes.compareTo(lRow, rRow); if (rowCmp != 0) { return rowCmp; } else { return KeyValue.COMPARATOR.compare(leftKey, rightKey); } }
@Override public int compareRows(byte [] left, int loffset, int llength, byte [] right, int roffset, int rlength) { int leftDelimiter = getDelimiter(left, loffset, llength, HConstants.DELIMITER); int rightDelimiter = getDelimiter(right, roffset, rlength, HConstants.DELIMITER); int result = Bytes.compareTo(left, loffset, lpart, right, roffset, rpart); if (result != 0) { return result; int leftFarDelimiter = getDelimiterInReverse(left, leftDelimiter, llength - (leftDelimiter - loffset), HConstants.DELIMITER); int rightFarDelimiter = getDelimiterInReverse(right, result = super.compareRows(left, leftDelimiter, lpart, right, rightDelimiter, rpart); if (result != 0) { return result; result = Bytes.compareTo(left, leftFarDelimiter, llength - (leftFarDelimiter - loffset), right, rightFarDelimiter, rlength - (rightFarDelimiter - roffset)); return result;
/** * Compares the row of two keyvalues for equality * @param left * @param right * @return True if rows match. */ public boolean matchingRows(final Cell left, final Cell right) { short lrowlength = left.getRowLength(); short rrowlength = right.getRowLength(); return matchingRows(left, lrowlength, right, rrowlength); }
/** * Checks whether the given scan rowkey range overlaps with the current storefile's * @param scan the scan specification. Used to determine the rowkey range. * @return true if there is overlap, false otherwise */ public boolean passesKeyRangeFilter(Scan scan) { if (this.getFirstKey() == null || this.getLastKey() == null) { // the file is empty return false; } if (Bytes.equals(scan.getStartRow(), HConstants.EMPTY_START_ROW) && Bytes.equals(scan.getStopRow(), HConstants.EMPTY_END_ROW)) { return true; } KeyValue smallestScanKeyValue = scan.isReversed() ? KeyValueUtil .createFirstOnRow(scan.getStopRow()) : KeyValueUtil.createFirstOnRow(scan .getStartRow()); KeyValue largestScanKeyValue = scan.isReversed() ? KeyValueUtil .createLastOnRow(scan.getStartRow()) : KeyValueUtil.createLastOnRow(scan .getStopRow()); boolean nonOverLapping = (getComparator().compareFlatKey( this.getFirstKey(), largestScanKeyValue.getKey()) > 0 && !Bytes .equals(scan.isReversed() ? scan.getStartRow() : scan.getStopRow(), HConstants.EMPTY_END_ROW)) || getComparator().compareFlatKey(this.getLastKey(), smallestScanKeyValue.getKey()) < 0; return !nonOverLapping; }
/** * Compares left to right assuming that left,loffset,llength and right,roffset,rlength are * full KVs laid out in a flat byte[]s. * @param left * @param loffset * @param llength * @param right * @param roffset * @param rlength * @return 0 if equal, <0 if left smaller, >0 if right smaller */ public int compareFlatKey(byte[] left, int loffset, int llength, byte[] right, int roffset, int rlength) { // Compare row short lrowlength = Bytes.toShort(left, loffset); short rrowlength = Bytes.toShort(right, roffset); int compare = compareRows(left, loffset + Bytes.SIZEOF_SHORT, lrowlength, right, roffset + Bytes.SIZEOF_SHORT, rrowlength); if (compare != 0) { return compare; } // Compare the rest of the two KVs without making any assumptions about // the common prefix. This function will not compare rows anyway, so we // don't need to tell it that the common prefix includes the row. return compareWithoutRow(0, left, loffset, llength, right, roffset, rlength, rrowlength); }
private void appendDeleteFamilyBloomFilter(final KeyValue kv) throws IOException { if (!kv.isDeleteFamily()) { return; } // increase the number of delete family in the store file deleteFamilyCnt++; if (null != this.deleteFamilyBloomFilterWriter) { boolean newKey = true; if (lastDeleteFamilyKV != null) { newKey = !kvComparator.matchingRows(kv, lastDeleteFamilyKV); } if (newKey) { this.deleteFamilyBloomFilterWriter.add(kv.getBuffer(), kv.getRowOffset(), kv.getRowLength()); this.lastDeleteFamilyKV = kv; } } }
public void collect(Cell cell) { valLen.update(cell.getValueLength()); if (prevCell != null && KeyValue.COMPARATOR.compareRows(prevCell, cell) != 0) { // new row collectRow(); } curRowBytes += KeyValueUtil.length(cell); curRowKeyLength = KeyValueUtil.keyLength(cell); curRowCols++; prevCell = cell; }
/** * Compares the row and timestamp of two keys * Was called matchesWithoutColumn in HStoreKey. * @param right Key to compare against. * @return True if same row and timestamp is greater than the timestamp in * <code>right</code> */ public boolean matchingRowsGreaterTimestamp(final KeyValue left, final KeyValue right) { short lrowlength = left.getRowLength(); short rrowlength = right.getRowLength(); if (!matchingRows(left, lrowlength, right, rrowlength)) { return false; } return left.getTimestamp() >= right.getTimestamp(); }