org.apache.hadoop.hbase.client
Class Increment

java.lang.Object
  extended by org.apache.hadoop.hbase.client.Operation
      extended by org.apache.hadoop.hbase.client.OperationWithAttributes
          extended by org.apache.hadoop.hbase.client.Mutation
              extended by org.apache.hadoop.hbase.client.Increment
All Implemented Interfaces:
Comparable<Row>, CellScannable, Attributes, Row, HeapSize

@InterfaceAudience.Public
@InterfaceStability.Stable
public class Increment
extends Mutation
implements Comparable<Row>

Used to perform Increment operations on a single row.

This operation does not appear atomic to readers. Increments are done under a single row lock, so write operations to a row are synchronized, but readers do not take row locks so get and scan operations can see this operation partially completed.

To increment columns of a row, instantiate an Increment object with the row to increment. At least one column to increment must be specified using the addColumn(byte[], byte[], long) method.


Field Summary
 
Fields inherited from class org.apache.hadoop.hbase.client.Mutation
durability, familyMap, MUTATION_OVERHEAD, row, ts
 
Fields inherited from class org.apache.hadoop.hbase.client.OperationWithAttributes
ID_ATRIBUTE
 
Constructor Summary
Increment(byte[] row)
          Create a Increment operation for the specified row.
Increment(byte[] row, int offset, int length)
          Create a Increment operation for the specified row.
 
Method Summary
 Increment add(Cell cell)
          Add the specified KeyValue to this operation.
 Increment addColumn(byte[] family, byte[] qualifier, long amount)
          Increment the column from the specific family with the specified qualifier by the specified amount.
 int compareTo(Row i)
           
 boolean equals(Object obj)
           
protected  long extraHeapSize()
          Subclasses should override this method to add the heap size of their own fields.
 Map<byte[],NavigableMap<byte[],Long>> getFamilyMapOfLongs()
          Before 0.95, when you called Increment#getFamilyMap(), you got back a map of families to a list of Longs.
 TimeRange getTimeRange()
          Gets the TimeRange used for this increment.
 boolean hasFamilies()
          Method for checking if any families have been inserted into this Increment
 int hashCode()
           
 int numFamilies()
          Method for retrieving the number of families to increment from
 Increment setTimeRange(long minStamp, long maxStamp)
          Sets the TimeRange to be used on the Get for this increment.
 String toString()
          Produces a string representation of this Operation.
 
Methods inherited from class org.apache.hadoop.hbase.client.Mutation
cellScanner, getClusterIds, getDurability, getFamilyCellMap, getFamilyMap, getFingerprint, getRow, getTimeStamp, getWriteToWAL, heapSize, isEmpty, setClusterIds, setDurability, setFamilyCellMap, setFamilyMap, setWriteToWAL, size, toMap
 
Methods inherited from class org.apache.hadoop.hbase.client.OperationWithAttributes
getAttribute, getAttributeSize, getAttributesMap, getId, setAttribute, setId
 
Methods inherited from class org.apache.hadoop.hbase.client.Operation
toJSON, toJSON, toMap, toString
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Increment

public Increment(byte[] row)
Create a Increment operation for the specified row.

At least one column must be incremented.

Parameters:
row - row key (we will make a copy of this).

Increment

public Increment(byte[] row,
                 int offset,
                 int length)
Create a Increment operation for the specified row.

At least one column must be incremented.

Parameters:
row - row key (we will make a copy of this).
Method Detail

add

public Increment add(Cell cell)
              throws IOException
Add the specified KeyValue to this operation.

Parameters:
cell - individual Cell
Returns:
this
Throws:
IOException - e

addColumn

public Increment addColumn(byte[] family,
                           byte[] qualifier,
                           long amount)
Increment the column from the specific family with the specified qualifier by the specified amount.

Overrides previous calls to addColumn for this family and qualifier.

Parameters:
family - family name
qualifier - column qualifier
amount - amount to increment by
Returns:
the Increment object

getTimeRange

public TimeRange getTimeRange()
Gets the TimeRange used for this increment.

Returns:
TimeRange

setTimeRange

public Increment setTimeRange(long minStamp,
                              long maxStamp)
                       throws IOException
Sets the TimeRange to be used on the Get for this increment.

This is useful for when you have counters that only last for specific periods of time (ie. counters that are partitioned by time). By setting the range of valid times for this increment, you can potentially gain some performance with a more optimal Get operation.

This range is used as [minStamp, maxStamp).

Parameters:
minStamp - minimum timestamp value, inclusive
maxStamp - maximum timestamp value, exclusive
Returns:
this
Throws:
IOException - if invalid time range

numFamilies

public int numFamilies()
Method for retrieving the number of families to increment from

Overrides:
numFamilies in class Mutation
Returns:
number of families

hasFamilies

public boolean hasFamilies()
Method for checking if any families have been inserted into this Increment

Returns:
true if familyMap is non empty false otherwise

getFamilyMapOfLongs

public Map<byte[],NavigableMap<byte[],Long>> getFamilyMapOfLongs()
Before 0.95, when you called Increment#getFamilyMap(), you got back a map of families to a list of Longs. Now, Mutation.getFamilyCellMap() returns families by list of Cells. This method has been added so you can have the old behavior.

Returns:
Map of families to a Map of qualifers and their Long increments.
Since:
0.95.0

toString

public String toString()
Description copied from class: Operation
Produces a string representation of this Operation. It defaults to a JSON representation, but falls back to a string representation of the fingerprint and details in the case of a JSON encoding failure.

Overrides:
toString in class Operation
Returns:
String

compareTo

public int compareTo(Row i)
Specified by:
compareTo in interface Comparable<Row>
Overrides:
compareTo in class Mutation

hashCode

public int hashCode()
Overrides:
hashCode in class Object

equals

public boolean equals(Object obj)
Overrides:
equals in class Object

extraHeapSize

protected long extraHeapSize()
Description copied from class: Mutation
Subclasses should override this method to add the heap size of their own fields.

Overrides:
extraHeapSize in class Mutation
Returns:
the heap size to add (will be aligned).


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