Index: src/main/java/org/apache/hadoop/hbase/client/Increment.java =================================================================== --- src/main/java/org/apache/hadoop/hbase/client/Increment.java (revision 1035956) +++ src/main/java/org/apache/hadoop/hbase/client/Increment.java (working copy) @@ -82,10 +82,14 @@ } /** - * Increment the column from the specific family with the specified qualifier + * Increment the column from the specified family with the specified qualifier * by the specified amount. *

- * Overrides previous calls to addColumn for this family and qualifier. + * For a single instance of Increment, method overrides previous calls to + * addColumn for this family and qualifier. Use + * {@link #incrementColumn(byte[], byte[], long)} to have multiple calls for + * the same column summed rather than replaced. + * * @param family family name * @param qualifier column qualifier * @param amount amount to increment by @@ -95,12 +99,39 @@ NavigableMap set = familyMap.get(family); if(set == null) { set = new TreeMap(Bytes.BYTES_COMPARATOR); + familyMap.put(family, set); } set.put(qualifier, amount); - familyMap.put(family, set); return this; } + /** + * Increment the column from the specified family with the specified qualifier + * by the specified amount. + *

+ * For a single instance of Increment, method sums the amount with any + * previous calls to incrementColumn for this family and qualifier. Use + * {@link #addColumn(byte[], byte[], long)} if you want to replace any + * existing amounts set in this instance of Increment. + * + * @param family family name + * @param qualifier column qualifier + * @param amount amount to increment by + * @return the Increment object + */ + public Increment incrementColumn(byte [] family, byte [] qualifier, + long amount) { + NavigableMap set = familyMap.get(family); + if(set == null) { + set = new TreeMap(Bytes.BYTES_COMPARATOR); + familyMap.put(family, set); + } + Long previousAmount = set.get(qualifier); + if (previousAmount != null) amount += previousAmount; + set.put(qualifier, amount); + return this; + } + /* Accessors */ /**