Search in sources :

Example 36 with RowMutations

use of org.apache.hadoop.hbase.client.RowMutations in project hbase by apache.

the class TestHRegion method testMutateRow.

@Test
public void testMutateRow() throws Exception {
    final byte[] row = Bytes.toBytes("row");
    final byte[] q1 = Bytes.toBytes("q1");
    final byte[] q2 = Bytes.toBytes("q2");
    final byte[] q3 = Bytes.toBytes("q3");
    final byte[] q4 = Bytes.toBytes("q4");
    final String v1 = "v1";
    region = initHRegion(tableName, method, CONF, fam1);
    // Initial values
    region.batchMutate(new Mutation[] { new Put(row).addColumn(fam1, q2, Bytes.toBytes("toBeDeleted")), new Put(row).addColumn(fam1, q3, Bytes.toBytes(5L)), new Put(row).addColumn(fam1, q4, Bytes.toBytes("a")) });
    // Do mutateRow
    Result result = region.mutateRow(new RowMutations(row).add(Arrays.asList(new Put(row).addColumn(fam1, q1, Bytes.toBytes(v1)), new Delete(row).addColumns(fam1, q2), new Increment(row).addColumn(fam1, q3, 1), new Append(row).addColumn(fam1, q4, Bytes.toBytes("b")))));
    assertNotNull(result);
    assertEquals(6L, Bytes.toLong(result.getValue(fam1, q3)));
    assertEquals("ab", Bytes.toString(result.getValue(fam1, q4)));
    // Verify the value
    result = region.get(new Get(row));
    assertEquals(v1, Bytes.toString(result.getValue(fam1, q1)));
    assertNull(result.getValue(fam1, q2));
    assertEquals(6L, Bytes.toLong(result.getValue(fam1, q3)));
    assertEquals("ab", Bytes.toString(result.getValue(fam1, q4)));
}
Also used : Delete(org.apache.hadoop.hbase.client.Delete) Append(org.apache.hadoop.hbase.client.Append) Increment(org.apache.hadoop.hbase.client.Increment) Get(org.apache.hadoop.hbase.client.Get) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) ByteString(org.apache.hbase.thirdparty.com.google.protobuf.ByteString) Put(org.apache.hadoop.hbase.client.Put) CheckAndMutateResult(org.apache.hadoop.hbase.client.CheckAndMutateResult) Result(org.apache.hadoop.hbase.client.Result) RowMutations(org.apache.hadoop.hbase.client.RowMutations) Test(org.junit.Test)

Aggregations

RowMutations (org.apache.hadoop.hbase.client.RowMutations)36 Put (org.apache.hadoop.hbase.client.Put)28 Test (org.junit.Test)19 Delete (org.apache.hadoop.hbase.client.Delete)18 Get (org.apache.hadoop.hbase.client.Get)18 Result (org.apache.hadoop.hbase.client.Result)14 Append (org.apache.hadoop.hbase.client.Append)10 CheckAndMutateResult (org.apache.hadoop.hbase.client.CheckAndMutateResult)10 Increment (org.apache.hadoop.hbase.client.Increment)9 Mutation (org.apache.hadoop.hbase.client.Mutation)9 DoNotRetryIOException (org.apache.hadoop.hbase.DoNotRetryIOException)8 Table (org.apache.hadoop.hbase.client.Table)8 TableName (org.apache.hadoop.hbase.TableName)5 CheckAndMutate (org.apache.hadoop.hbase.client.CheckAndMutate)5 SingleColumnValueFilter (org.apache.hadoop.hbase.filter.SingleColumnValueFilter)5 ByteString (org.apache.hbase.thirdparty.com.google.protobuf.ByteString)4 Action (org.apache.hadoop.hbase.client.Action)3 BinaryComparator (org.apache.hadoop.hbase.filter.BinaryComparator)3 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)3 IOException (java.io.IOException)2