/** * Increment the column from the specific family with the specified qualifier * by the specified amount. * <p> * Overrides previous calls to addColumn for this family and qualifier. * @param family family name * @param qualifier column qualifier * @param amount amount to increment by * @return the Increment object */ public Increment addColumn(byte [] family, byte [] qualifier, long amount) { if (family == null) { throw new IllegalArgumentException("family cannot be null"); } List<Cell> list = getCellList(family); KeyValue kv = createPutKeyValue(family, qualifier, ts, Bytes.toBytes(amount)); list.add(kv); return this; }
@Test public void testIncrementCopyConstructor() throws IOException { Increment origin = new Increment(Bytes.toBytes("ROW-01")); origin.setPriority(100); byte[] family = Bytes.toBytes("CF-01"); origin.add(CellBuilderFactory.create(CellBuilderType.SHALLOW_COPY) .setRow(origin.getRow()) .setFamily(family) .setQualifier(Bytes.toBytes("q")) .setType(Cell.Type.Put) .setValue(Bytes.toBytes(100)) .build()); origin.addColumn(family, Bytes.toBytes("q0"), 4); origin.setTimeRange(100, 1000); Increment clone = new Increment(origin); assertEquals(origin, clone); origin.addColumn(family, Bytes.toBytes("q1"), 3); //They should have different cell lists assertNotEquals(origin.getCellList(family), clone.getCellList(family)); }
/** * Increment the column from the specific family with the specified qualifier * by the specified amount. * <p> * Overrides previous calls to addColumn for this family and qualifier. * @param family family name * @param qualifier column qualifier * @param amount amount to increment by * @return the Increment object */ public Increment addColumn(byte [] family, byte [] qualifier, long amount) { if (family == null) { throw new IllegalArgumentException("family cannot be null"); } List<Cell> list = getCellList(family); KeyValue kv = createPutKeyValue(family, qualifier, ts, Bytes.toBytes(amount)); list.add(kv); return this; }
@Test public void testIncrementCopyConstructor() throws IOException { Increment origin = new Increment(Bytes.toBytes("ROW-01")); origin.setPriority(100); byte[] family = Bytes.toBytes("CF-01"); origin.add(CellBuilderFactory.create(CellBuilderType.SHALLOW_COPY) .setRow(origin.getRow()) .setFamily(family) .setQualifier(Bytes.toBytes("q")) .setType(Cell.Type.Put) .setValue(Bytes.toBytes(100)) .build()); origin.addColumn(family, Bytes.toBytes("q0"), 4); origin.setTimeRange(100, 1000); Increment clone = new Increment(origin); assertEquals(origin, clone); origin.addColumn(family, Bytes.toBytes("q1"), 3); //They should have different cell lists assertNotEquals(origin.getCellList(family), clone.getCellList(family)); }
/** * Increment the column from the specific family with the specified qualifier * by the specified amount. * <p> * Overrides previous calls to addColumn for this family and qualifier. * @param family family name * @param qualifier column qualifier * @param amount amount to increment by * @return the Increment object */ public Increment addColumn(byte [] family, byte [] qualifier, long amount) { if (family == null) { throw new IllegalArgumentException("family cannot be null"); } List<Cell> list = getCellList(family); KeyValue kv = createPutKeyValue(family, qualifier, ts, Bytes.toBytes(amount)); list.add(kv); return this; }
/** * Increment the column from the specific family with the specified qualifier * by the specified amount. * <p> * Overrides previous calls to addColumn for this family and qualifier. * @param family family name * @param qualifier column qualifier * @param amount amount to increment by * @return the Increment object */ public Increment addColumn(byte [] family, byte [] qualifier, long amount) { if (family == null) { throw new IllegalArgumentException("family cannot be null"); } if (qualifier == null) { throw new IllegalArgumentException("qualifier cannot be null"); } List<Cell> list = getCellList(family); KeyValue kv = createPutKeyValue(family, qualifier, ts, Bytes.toBytes(amount)); list.add(kv); familyMap.put(CellUtil.cloneFamily(kv), list); return this; }
/** * Add the specified KeyValue to this operation. * @param cell individual Cell * @return this * @throws java.io.IOException e */ public Increment add(Cell cell) throws IOException{ byte [] family = CellUtil.cloneFamily(cell); List<Cell> list = getCellList(family); //Checking that the row of the kv is the same as the put int res = Bytes.compareTo(this.row, 0, row.length, cell.getRowArray(), cell.getRowOffset(), cell.getRowLength()); if (res != 0) { throw new WrongRowIOException("The row in " + cell + " doesn't match the original one " + Bytes.toStringBinary(this.row)); } list.add(cell); familyMap.put(family, list); return this; }