org.apache.hadoop.hbase
Class KeyValue.KVComparator

java.lang.Object
  extended by org.apache.hadoop.hbase.KeyValue.KVComparator
All Implemented Interfaces:
Comparator<Cell>, KeyValue.SamePrefixComparator<byte[]>, org.apache.hadoop.io.RawComparator<Cell>
Direct Known Subclasses:
KeyValue.MetaComparator, KeyValue.RawBytesComparator
Enclosing class:
KeyValue

public static class KeyValue.KVComparator
extends Object
implements org.apache.hadoop.io.RawComparator<Cell>, KeyValue.SamePrefixComparator<byte[]>

Compare KeyValues. When we compare KeyValues, we only compare the Key portion. This means two KeyValues with same Key but different Values are considered the same as far as this Comparator is concerned.


Constructor Summary
KeyValue.KVComparator()
           
 
Method Summary
 byte[] calcIndexKey(byte[] lastKeyOfPreviousBlock, byte[] firstKeyInBlock)
           
protected  Object clone()
           
 int compare(byte[] l, int loff, int llen, byte[] r, int roff, int rlen)
           
 int compare(Cell left, Cell right)
          Compares the Key of a cell -- with fields being more significant in this order: rowkey, colfam/qual, timestamp, type, mvcc
protected  int compareColumns(byte[] left, int loffset, int llength, int lfamilylength, byte[] right, int roffset, int rlength, int rfamilylength)
           
 int compareFlatKey(byte[] left, byte[] right)
           
 int compareFlatKey(byte[] left, int loffset, int llength, byte[] right, int roffset, int rlength)
          Compares left to right assuming that left,loffset,llength and right,roffset,rlength are full KVs laid out in a flat byte[]s.
 int compareIgnoringPrefix(int commonPrefix, byte[] left, int loffset, int llength, byte[] right, int roffset, int rlength)
          Overridden
 int compareKey(byte[] key, int koff, int klen, byte[] row, int roff, int rlen, byte[] fam, int foff, int flen, byte[] col, int coff, int clen, long ts, byte type)
           
protected  int compareRowKey(Cell left, Cell right)
          Compares the only the user specified portion of a Key.
 int compareRows(byte[] left, int loffset, int llength, byte[] right, int roffset, int rlength)
          Get the b[],o,l for left and right rowkey portions and compare.
 int compareRows(KeyValue left, KeyValue right)
           
 int compareTimestamps(KeyValue left, KeyValue right)
           
 String getLegacyKeyComparatorName()
          The HFileV2 file format's trailer contains this class name.
 byte[] getShortMidpointKey(byte[] leftKey, byte[] rightKey)
          This is a HFile block index key optimization.
 boolean matchingRowColumn(KeyValue left, KeyValue right)
          Compares the row and column of two keyvalues for equality
 boolean matchingRows(byte[] left, int loffset, int llength, byte[] right, int roffset, int rlength)
          Compare rows.
 boolean matchingRows(KeyValue left, KeyValue right)
          Compares the row of two keyvalues for equality
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface java.util.Comparator
equals
 

Constructor Detail

KeyValue.KVComparator

public KeyValue.KVComparator()
Method Detail

getLegacyKeyComparatorName

public String getLegacyKeyComparatorName()
The HFileV2 file format's trailer contains this class name. We reinterpret this and instantiate the appropriate comparator. TODO: With V3 consider removing this.

Returns:
legacy class name for FileFileTrailer#comparatorClassName

compare

public int compare(byte[] l,
                   int loff,
                   int llen,
                   byte[] r,
                   int roff,
                   int rlen)
Specified by:
compare in interface org.apache.hadoop.io.RawComparator<Cell>

compareRowKey

protected int compareRowKey(Cell left,
                            Cell right)
Compares the only the user specified portion of a Key. This is overridden by MetaComparator.

Parameters:
left -
right -
Returns:
0 if equal, <0 if left smaller, >0 if right smaller

compareFlatKey

public int compareFlatKey(byte[] left,
                          int loffset,
                          int llength,
                          byte[] right,
                          int roffset,
                          int rlength)
Compares left to right assuming that left,loffset,llength and right,roffset,rlength are full KVs laid out in a flat byte[]s.

Parameters:
left -
loffset -
llength -
right -
roffset -
rlength -
Returns:
0 if equal, <0 if left smaller, >0 if right smaller

compareFlatKey

public int compareFlatKey(byte[] left,
                          byte[] right)

compareKey

public int compareKey(byte[] key,
                      int koff,
                      int klen,
                      byte[] row,
                      int roff,
                      int rlen,
                      byte[] fam,
                      int foff,
                      int flen,
                      byte[] col,
                      int coff,
                      int clen,
                      long ts,
                      byte type)

compare

public int compare(Cell left,
                   Cell right)
Compares the Key of a cell -- with fields being more significant in this order: rowkey, colfam/qual, timestamp, type, mvcc

Specified by:
compare in interface Comparator<Cell>

compareTimestamps

public int compareTimestamps(KeyValue left,
                             KeyValue right)

compareRows

public int compareRows(KeyValue left,
                       KeyValue right)
Parameters:
left -
right -
Returns:
Result comparing rows.

compareRows

public int compareRows(byte[] left,
                       int loffset,
                       int llength,
                       byte[] right,
                       int roffset,
                       int rlength)
Get the b[],o,l for left and right rowkey portions and compare.

Parameters:
left -
loffset -
llength -
right -
roffset -
rlength -
Returns:
0 if equal, <0 if left smaller, >0 if right smaller

compareColumns

protected int compareColumns(byte[] left,
                             int loffset,
                             int llength,
                             int lfamilylength,
                             byte[] right,
                             int roffset,
                             int rlength,
                             int rfamilylength)

compareIgnoringPrefix

public int compareIgnoringPrefix(int commonPrefix,
                                 byte[] left,
                                 int loffset,
                                 int llength,
                                 byte[] right,
                                 int roffset,
                                 int rlength)
Overridden

Specified by:
compareIgnoringPrefix in interface KeyValue.SamePrefixComparator<byte[]>
Parameters:
commonPrefix -
left -
loffset -
llength -
right -
roffset -
rlength -
Returns:
0 if equal, <0 if left smaller, >0 if right smaller

matchingRowColumn

public boolean matchingRowColumn(KeyValue left,
                                 KeyValue right)
Compares the row and column of two keyvalues for equality

Parameters:
left -
right -
Returns:
True if same row and column.

matchingRows

public boolean matchingRows(KeyValue left,
                            KeyValue right)
Compares the row of two keyvalues for equality

Parameters:
left -
right -
Returns:
True if rows match.

matchingRows

public boolean matchingRows(byte[] left,
                            int loffset,
                            int llength,
                            byte[] right,
                            int roffset,
                            int rlength)
Compare rows. Just calls Bytes.equals, but it's good to have this encapsulated.

Parameters:
left - Left row array.
loffset - Left row offset.
llength - Left row length.
right - Right row array.
roffset - Right row offset.
rlength - Right row length.
Returns:
Whether rows are the same row.

calcIndexKey

public byte[] calcIndexKey(byte[] lastKeyOfPreviousBlock,
                           byte[] firstKeyInBlock)

getShortMidpointKey

public byte[] getShortMidpointKey(byte[] leftKey,
                                  byte[] rightKey)
This is a HFile block index key optimization.

Parameters:
leftKey -
rightKey -
Returns:
0 if equal, <0 if left smaller, >0 if right smaller

clone

protected Object clone()
                throws CloneNotSupportedException
Overrides:
clone in class Object
Throws:
CloneNotSupportedException


Copyright © 2015 The Apache Software Foundation. All Rights Reserved.