Search in sources :

Example 1 with MutationCase

use of com.google.bigtable.v2.Mutation.MutationCase in project java-bigtable-hbase by googleapis.

the class TestDeleteAdapter method testDeleteColumnAtTimestamp.

@Test
public void testDeleteColumnAtTimestamp() {
    byte[] rowKey = randomHelper.randomData("rk1-");
    byte[] family = randomHelper.randomData("family1-");
    byte[] qualifier = randomHelper.randomData("qualifier");
    long hbaseTimestamp = 1000L;
    long bigtableStartTimestamp = TimeUnit.MILLISECONDS.toMicros(hbaseTimestamp);
    long bigtableEndTimestamp = TimeUnit.MILLISECONDS.toMicros(hbaseTimestamp + 1);
    Delete delete = new Delete(rowKey);
    delete.addColumn(family, qualifier, hbaseTimestamp);
    MutateRowRequest request = adapt(delete);
    Assert.assertArrayEquals(rowKey, request.getRowKey().toByteArray());
    Assert.assertEquals(1, request.getMutationsCount());
    MutationCase mutationCase = request.getMutations(0).getMutationCase();
    Assert.assertEquals(MutationCase.DELETE_FROM_COLUMN, mutationCase);
    Mutation.DeleteFromColumn deleteFromColumn = request.getMutations(0).getDeleteFromColumn();
    Assert.assertArrayEquals(family, deleteFromColumn.getFamilyNameBytes().toByteArray());
    Assert.assertArrayEquals(qualifier, deleteFromColumn.getColumnQualifier().toByteArray());
    Assert.assertTrue(request.getMutations(0).getDeleteFromColumn().hasTimeRange());
    TimestampRange timeStampRange = deleteFromColumn.getTimeRange();
    Assert.assertEquals(bigtableStartTimestamp, timeStampRange.getStartTimestampMicros());
    Assert.assertEquals(bigtableEndTimestamp, timeStampRange.getEndTimestampMicros());
}
Also used : Delete(org.apache.hadoop.hbase.client.Delete) MutateRowRequest(com.google.bigtable.v2.MutateRowRequest) MutationCase(com.google.bigtable.v2.Mutation.MutationCase) Mutation(com.google.bigtable.v2.Mutation) RowMutation(com.google.cloud.bigtable.data.v2.models.RowMutation) TimestampRange(com.google.bigtable.v2.TimestampRange) Test(org.junit.Test)

Example 2 with MutationCase

use of com.google.bigtable.v2.Mutation.MutationCase in project java-bigtable-hbase by googleapis.

the class TestDeleteAdapter method testFullRowDelete.

@Test
public void testFullRowDelete() {
    byte[] rowKey = randomHelper.randomData("rk1-");
    Delete delete = new Delete(rowKey);
    MutateRowRequest request = adapt(delete);
    Assert.assertArrayEquals(rowKey, request.getRowKey().toByteArray());
    Assert.assertEquals(1, request.getMutationsCount());
    Mutation.MutationCase mutationCase = request.getMutations(0).getMutationCase();
    Assert.assertEquals(MutationCase.DELETE_FROM_ROW, mutationCase);
}
Also used : Delete(org.apache.hadoop.hbase.client.Delete) MutateRowRequest(com.google.bigtable.v2.MutateRowRequest) Mutation(com.google.bigtable.v2.Mutation) RowMutation(com.google.cloud.bigtable.data.v2.models.RowMutation) MutationCase(com.google.bigtable.v2.Mutation.MutationCase) Test(org.junit.Test)

Example 3 with MutationCase

use of com.google.bigtable.v2.Mutation.MutationCase in project java-bigtable-hbase by googleapis.

the class TestDeleteAdapter method testColumnFamilyDelete.

@Test
public void testColumnFamilyDelete() {
    byte[] rowKey = randomHelper.randomData("rk1-");
    byte[] family = randomHelper.randomData("family1-");
    Delete delete = new Delete(rowKey);
    delete.addFamily(family);
    MutateRowRequest request = adapt(delete);
    Assert.assertArrayEquals(rowKey, request.getRowKey().toByteArray());
    Assert.assertEquals(1, request.getMutationsCount());
    MutationCase mutationCase = request.getMutations(0).getMutationCase();
    Assert.assertEquals(MutationCase.DELETE_FROM_FAMILY, mutationCase);
    Mutation.DeleteFromFamily deleteFromFamily = request.getMutations(0).getDeleteFromFamily();
    Assert.assertArrayEquals(family, deleteFromFamily.getFamilyNameBytes().toByteArray());
}
Also used : Delete(org.apache.hadoop.hbase.client.Delete) MutateRowRequest(com.google.bigtable.v2.MutateRowRequest) MutationCase(com.google.bigtable.v2.Mutation.MutationCase) Mutation(com.google.bigtable.v2.Mutation) RowMutation(com.google.cloud.bigtable.data.v2.models.RowMutation) Test(org.junit.Test)

Aggregations

MutateRowRequest (com.google.bigtable.v2.MutateRowRequest)3 Mutation (com.google.bigtable.v2.Mutation)3 MutationCase (com.google.bigtable.v2.Mutation.MutationCase)3 RowMutation (com.google.cloud.bigtable.data.v2.models.RowMutation)3 Delete (org.apache.hadoop.hbase.client.Delete)3 Test (org.junit.Test)3 TimestampRange (com.google.bigtable.v2.TimestampRange)1