org.apache.hadoop.hbase
Class KeyValueUtil

java.lang.Object
  extended by org.apache.hadoop.hbase.KeyValueUtil

@InterfaceAudience.Private
public class KeyValueUtil
extends Object

static convenience methods for dealing with KeyValues and collections of KeyValues


Constructor Summary
KeyValueUtil()
           
 
Method Summary
protected static int appendKeyToByteArrayWithoutValue(Cell cell, byte[] output, int offset)
           
static int appendToByteArray(Cell cell, byte[] output, int offset)
          copy key and value
static void appendToByteBuffer(ByteBuffer bb, KeyValue kv, boolean includeMvccVersion)
           
static ByteBuffer copyKeyToNewByteBuffer(Cell cell)
           
static byte[] copyToNewByteArray(Cell cell)
           
static ByteBuffer copyToNewByteBuffer(Cell cell)
           
static KeyValue copyToNewKeyValue(Cell cell)
          copy key only
static KeyValue createFirstDeleteFamilyOnRow(byte[] row, byte[] family)
          Create a Delete Family KeyValue for the specified row and family that would be smaller than all other possible Delete Family KeyValues that have the same row and family.
static KeyValue createFirstKeyInIncrementedRow(Cell in)
          Increment the row bytes and clear the other fields
static KeyValue createFirstKeyInNextRow(Cell in)
          Append single byte 0x00 to the end of the input row key
static KeyValue createFirstOnRow(byte[] row)
          Create a KeyValue that is smaller than all other possible KeyValues for the given row.
static KeyValue createFirstOnRow(byte[] row, byte[] family, byte[] qualifier)
          Create a KeyValue for the specified row, family and qualifier that would be smaller than all other possible KeyValues that have the same row,family,qualifier.
static KeyValue createFirstOnRow(byte[] buffer, byte[] row, byte[] family, byte[] qualifier)
          Create a KeyValue for the specified row, family and qualifier that would be smaller than all other possible KeyValues that have the same row, family, qualifier.
static KeyValue createFirstOnRow(byte[] row, byte[] f, byte[] q, long ts)
           
static KeyValue createFirstOnRow(byte[] buffer, int boffset, byte[] row, int roffset, int rlength, byte[] family, int foffset, int flength, byte[] qualifier, int qoffset, int qlength)
          Create a KeyValue for the specified row, family and qualifier that would be smaller than all other possible KeyValues that have the same row, family, qualifier.
static KeyValue createFirstOnRow(byte[] row, int roffset, int rlength, byte[] family, int foffset, int flength, byte[] qualifier, int qoffset, int qlength)
          Create a KeyValue for the specified row, family and qualifier that would be smaller than all other possible KeyValues that have the same row, family, qualifier.
static KeyValue createFirstOnRow(byte[] row, int roffset, short rlength)
          Create a KeyValue that is smaller than all other possible KeyValues for the given row.
static KeyValue createFirstOnRow(byte[] row, long ts)
          Creates a KeyValue that is smaller than all other KeyValues that are older than the passed timestamp.
static KeyValue createFirstOnRowColTS(Cell kv, long ts)
          Creates the first KV with the row/family/qualifier of this KV and the given timestamp.
static KeyValue createFirstOnRowColTS(KeyValue kv, long ts)
          Creates the first KV with the row/family/qualifier of this KV and the given timestamp.
static KeyValue createLastOnRow(byte[] row)
          Creates a KeyValue that is last on the specified row id.
static KeyValue createLastOnRow(byte[] row, int roffset, int rlength, byte[] family, int foffset, int flength, byte[] qualifier, int qoffset, int qlength)
          Create a KeyValue for the specified row, family and qualifier that would be larger than or equal to all other possible KeyValues that have the same row, family, qualifier.
static KeyValue createLastOnRow(Cell kv)
          Creates a keyValue for the specified keyvalue larger than or equal to all other possible KeyValues that have the same row, family, qualifer.
static KeyValue createLastOnRowCol(Cell kv)
          Similar to createLastOnRow(byte[], int, int, byte[], int, int, byte[], int, int) but creates the last key on the row/column of this KV (the value part of the returned KV is always empty).
static KeyValue ensureKeyValue(Cell cell)
           
static List<KeyValue> ensureKeyValues(List<Cell> cells)
           
static int keyLength(Cell cell)
           
static int length(Cell cell)
          length
static int lengthWithMvccVersion(KeyValue kv, boolean includeMvccVersion)
           
static KeyValue nextShallowCopy(ByteBuffer bb, boolean includesMvccVersion, boolean includesTags)
          Creates a new KeyValue object positioned in the supplied ByteBuffer and sets the ByteBuffer's position to the start of the next KeyValue.
static KeyValue previousKey(KeyValue in)
          Decrement the timestamp.
static int totalLengthWithMvccVersion(Iterable<? extends KeyValue> kvs, boolean includeMvccVersion)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

KeyValueUtil

public KeyValueUtil()
Method Detail

length

public static int length(Cell cell)
length


keyLength

public static int keyLength(Cell cell)

lengthWithMvccVersion

public static int lengthWithMvccVersion(KeyValue kv,
                                        boolean includeMvccVersion)

totalLengthWithMvccVersion

public static int totalLengthWithMvccVersion(Iterable<? extends KeyValue> kvs,
                                             boolean includeMvccVersion)

copyToNewKeyValue

public static KeyValue copyToNewKeyValue(Cell cell)
copy key only


copyKeyToNewByteBuffer

public static ByteBuffer copyKeyToNewByteBuffer(Cell cell)

copyToNewByteArray

public static byte[] copyToNewByteArray(Cell cell)

appendKeyToByteArrayWithoutValue

protected static int appendKeyToByteArrayWithoutValue(Cell cell,
                                                      byte[] output,
                                                      int offset)

appendToByteArray

public static int appendToByteArray(Cell cell,
                                    byte[] output,
                                    int offset)
copy key and value


copyToNewByteBuffer

public static ByteBuffer copyToNewByteBuffer(Cell cell)

appendToByteBuffer

public static void appendToByteBuffer(ByteBuffer bb,
                                      KeyValue kv,
                                      boolean includeMvccVersion)

nextShallowCopy

public static KeyValue nextShallowCopy(ByteBuffer bb,
                                       boolean includesMvccVersion,
                                       boolean includesTags)
Creates a new KeyValue object positioned in the supplied ByteBuffer and sets the ByteBuffer's position to the start of the next KeyValue. Does not allocate a new array or copy data.

Parameters:
bb -
includesMvccVersion -
includesTags -

createFirstKeyInNextRow

public static KeyValue createFirstKeyInNextRow(Cell in)
Append single byte 0x00 to the end of the input row key


createFirstKeyInIncrementedRow

public static KeyValue createFirstKeyInIncrementedRow(Cell in)
Increment the row bytes and clear the other fields


previousKey

public static KeyValue previousKey(KeyValue in)
Decrement the timestamp. For tests (currently wasteful) Remember timestamps are sorted reverse chronologically.

Parameters:
in -
Returns:
previous key

createLastOnRow

public static KeyValue createLastOnRow(byte[] row,
                                       int roffset,
                                       int rlength,
                                       byte[] family,
                                       int foffset,
                                       int flength,
                                       byte[] qualifier,
                                       int qoffset,
                                       int qlength)
Create a KeyValue for the specified row, family and qualifier that would be larger than or equal to all other possible KeyValues that have the same row, family, qualifier. Used for reseeking.

Parameters:
row - row key
roffset - row offset
rlength - row length
family - family name
foffset - family offset
flength - family length
qualifier - column qualifier
qoffset - qualifier offset
qlength - qualifier length
Returns:
Last possible key on passed row, family, qualifier.

createLastOnRow

public static KeyValue createLastOnRow(Cell kv)
Creates a keyValue for the specified keyvalue larger than or equal to all other possible KeyValues that have the same row, family, qualifer. Used for reseeking

Parameters:
kv -
Returns:
KeyValue

createLastOnRowCol

public static KeyValue createLastOnRowCol(Cell kv)
Similar to createLastOnRow(byte[], int, int, byte[], int, int, byte[], int, int) but creates the last key on the row/column of this KV (the value part of the returned KV is always empty). Used in creating "fake keys" for the multi-column Bloom filter optimization to skip the row/column we already know is not in the file.

Parameters:
kv - - cell
Returns:
the last key on the row/column of the given key-value pair

createFirstOnRowColTS

public static KeyValue createFirstOnRowColTS(Cell kv,
                                             long ts)
Creates the first KV with the row/family/qualifier of this KV and the given timestamp. Uses the "maximum" KV type that guarantees that the new KV is the lowest possible for this combination of row, family, qualifier, and timestamp. This KV's own timestamp is ignored. While this function copies the value from this KV, it is normally used on key-only KVs.

Parameters:
kv - - cell
ts -

createFirstOnRow

public static KeyValue createFirstOnRow(byte[] row,
                                        int roffset,
                                        short rlength)
Create a KeyValue that is smaller than all other possible KeyValues for the given row. That is any (valid) KeyValue on 'row' would sort _after_ the result.

Parameters:
row - - row key (arbitrary byte array)
Returns:
First possible KeyValue on passed row

createLastOnRow

public static KeyValue createLastOnRow(byte[] row)
Creates a KeyValue that is last on the specified row id. That is, every other possible KeyValue for the given row would compareTo() less than the result of this call.

Parameters:
row - row key
Returns:
Last possible KeyValue on passed row

createFirstOnRow

public static KeyValue createFirstOnRow(byte[] row)
Create a KeyValue that is smaller than all other possible KeyValues for the given row. That is any (valid) KeyValue on 'row' would sort _after_ the result.

Parameters:
row - - row key (arbitrary byte array)
Returns:
First possible KeyValue on passed row

createFirstOnRow

public static KeyValue createFirstOnRow(byte[] row,
                                        long ts)
Creates a KeyValue that is smaller than all other KeyValues that are older than the passed timestamp.

Parameters:
row - - row key (arbitrary byte array)
ts - - timestamp
Returns:
First possible key on passed row and timestamp.

createFirstOnRow

public static KeyValue createFirstOnRow(byte[] row,
                                        byte[] family,
                                        byte[] qualifier)
Create a KeyValue for the specified row, family and qualifier that would be smaller than all other possible KeyValues that have the same row,family,qualifier. Used for seeking.

Parameters:
row - - row key (arbitrary byte array)
family - - family name
qualifier - - column qualifier
Returns:
First possible key on passed row, and column.

createFirstDeleteFamilyOnRow

public static KeyValue createFirstDeleteFamilyOnRow(byte[] row,
                                                    byte[] family)
Create a Delete Family KeyValue for the specified row and family that would be smaller than all other possible Delete Family KeyValues that have the same row and family. Used for seeking.

Parameters:
row - - row key (arbitrary byte array)
family - - family name
Returns:
First Delete Family possible key on passed row.

createFirstOnRow

public static KeyValue createFirstOnRow(byte[] row,
                                        byte[] f,
                                        byte[] q,
                                        long ts)
Parameters:
row - - row key (arbitrary byte array)
f - - family name
q - - column qualifier
ts - - timestamp
Returns:
First possible key on passed row, column and timestamp

createFirstOnRow

public static KeyValue createFirstOnRow(byte[] row,
                                        int roffset,
                                        int rlength,
                                        byte[] family,
                                        int foffset,
                                        int flength,
                                        byte[] qualifier,
                                        int qoffset,
                                        int qlength)
Create a KeyValue for the specified row, family and qualifier that would be smaller than all other possible KeyValues that have the same row, family, qualifier. Used for seeking.

Parameters:
row - row key
roffset - row offset
rlength - row length
family - family name
foffset - family offset
flength - family length
qualifier - column qualifier
qoffset - qualifier offset
qlength - qualifier length
Returns:
First possible key on passed Row, Family, Qualifier.

createFirstOnRow

public static KeyValue createFirstOnRow(byte[] buffer,
                                        byte[] row,
                                        byte[] family,
                                        byte[] qualifier)
                                 throws IllegalArgumentException
Create a KeyValue for the specified row, family and qualifier that would be smaller than all other possible KeyValues that have the same row, family, qualifier. Used for seeking.

Parameters:
buffer - the buffer to use for the new KeyValue object
row - the value key
family - family name
qualifier - column qualifier
Returns:
First possible key on passed Row, Family, Qualifier.
Throws:
IllegalArgumentException - The resulting KeyValue object would be larger than the provided buffer or than Integer.MAX_VALUE

createFirstOnRow

public static KeyValue createFirstOnRow(byte[] buffer,
                                        int boffset,
                                        byte[] row,
                                        int roffset,
                                        int rlength,
                                        byte[] family,
                                        int foffset,
                                        int flength,
                                        byte[] qualifier,
                                        int qoffset,
                                        int qlength)
                                 throws IllegalArgumentException
Create a KeyValue for the specified row, family and qualifier that would be smaller than all other possible KeyValues that have the same row, family, qualifier. Used for seeking.

Parameters:
buffer - the buffer to use for the new KeyValue object
boffset - buffer offset
row - the value key
roffset - row offset
rlength - row length
family - family name
foffset - family offset
flength - family length
qualifier - column qualifier
qoffset - qualifier offset
qlength - qualifier length
Returns:
First possible key on passed Row, Family, Qualifier.
Throws:
IllegalArgumentException - The resulting KeyValue object would be larger than the provided buffer or than Integer.MAX_VALUE

createFirstOnRowColTS

public static KeyValue createFirstOnRowColTS(KeyValue kv,
                                             long ts)
Creates the first KV with the row/family/qualifier of this KV and the given timestamp. Uses the "maximum" KV type that guarantees that the new KV is the lowest possible for this combination of row, family, qualifier, and timestamp. This KV's own timestamp is ignored. While this function copies the value from this KV, it is normally used on key-only KVs.


ensureKeyValue

public static KeyValue ensureKeyValue(Cell cell)
Parameters:
cell -
Returns:
cell if it is an instance of KeyValue else we will return a new KeyValue instance made from cell

ensureKeyValues

public static List<KeyValue> ensureKeyValues(List<Cell> cells)


Copyright © 2007-2016 The Apache Software Foundation. All Rights Reserved.