Search in sources :

Example 1 with TimestampRange

use of com.google.bigtable.v2.TimestampRange in project simple-bigtable by spotify.

the class CellsReadImplTest method testLatest.

@Test
public void testLatest() throws Exception {
    // Test Plain Latest
    CellWithinCellsRead.ReadImpl cellRead = (CellWithinCellsRead.ReadImpl) this.cellsRead.latest();
    ReadRowsRequest.Builder readRequest = cellRead.readRequest();
    verifyReadRequest(readRequest);
    assertEquals(4, readRequest.getFilter().getChain().getFiltersCount());
    assertEquals(1, readRequest.getFilter().getChain().getFilters(3).getCellsPerColumnLimitFilter());
    assertEquals(RowFilter.getDefaultInstance(), readRequest.getFilter().toBuilder().clearChain().build());
    // Test A Filter Then A Latest
    final TimestampRange timestampRange = TimestampRange.newBuilder().setStartTimestampMicros(12345).build();
    cellRead = (CellWithinCellsRead.ReadImpl) this.cellsRead.startTimestampMicros(timestampRange.getStartTimestampMicros()).valueRegex(ByteString.copyFromUtf8("regex")).latest();
    readRequest = cellRead.readRequest();
    verifyReadRequest(readRequest);
    assertEquals(6, readRequest.getFilter().getChain().getFiltersCount());
    assertEquals(timestampRange, readRequest.getFilter().getChain().getFilters(3).getTimestampRangeFilter());
    assertEquals("regex", readRequest.getFilter().getChain().getFilters(4).getValueRegexFilter().toStringUtf8());
    assertEquals(1, readRequest.getFilter().getChain().getFilters(5).getCellsPerColumnLimitFilter());
    assertEquals(RowFilter.getDefaultInstance(), readRequest.getFilter().toBuilder().clearChain().build());
    // Need to make sure that the ColumnRead (CellsRead's parent) did not get the filters added as well.
    // This is necessary to reuse the objects.
    assertEquals(3, cellsRead.parentRead.readRequest().getFilter().getChain().getFiltersCount());
}
Also used : CellWithinCellsRead(com.spotify.bigtable.read.ReadCell.CellWithinCellsRead) ReadRowsRequest(com.google.bigtable.v2.ReadRowsRequest) TimestampRange(com.google.bigtable.v2.TimestampRange) Test(org.junit.Test)

Example 2 with TimestampRange

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

the class TestDeleteAdapter method testDeleteColumnBeforeTimestamp.

@Test
public void testDeleteColumnBeforeTimestamp() {
    byte[] rowKey = randomHelper.randomData("rk1-");
    byte[] family = randomHelper.randomData("family1-");
    byte[] qualifier = randomHelper.randomData("qualifier");
    long hbaseTimestamp = 1000L;
    long bigtableTimestamp = TimeUnit.MILLISECONDS.toMicros(hbaseTimestamp + 1);
    Delete delete = new Delete(rowKey);
    delete.addColumns(family, qualifier, hbaseTimestamp);
    MutateRowRequest request = adapt(delete);
    Assert.assertArrayEquals(rowKey, request.getRowKey().toByteArray());
    Assert.assertEquals(1, request.getMutationsCount());
    Assert.assertEquals(MutationCase.DELETE_FROM_COLUMN, request.getMutations(0).getMutationCase());
    Mutation.DeleteFromColumn deleteFromColumn = request.getMutations(0).getDeleteFromColumn();
    Assert.assertArrayEquals(qualifier, deleteFromColumn.getColumnQualifier().toByteArray());
    Assert.assertTrue(request.getMutations(0).getDeleteFromColumn().hasTimeRange());
    TimestampRange timeRange = deleteFromColumn.getTimeRange();
    Assert.assertEquals(0L, timeRange.getStartTimestampMicros());
    Assert.assertEquals(bigtableTimestamp, timeRange.getEndTimestampMicros());
}
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) TimestampRange(com.google.bigtable.v2.TimestampRange) Test(org.junit.Test)

Example 3 with TimestampRange

use of com.google.bigtable.v2.TimestampRange 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 4 with TimestampRange

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

the class TestTimestampRangeFilterAdapter method timestampFiltersAreAdapted.

@Test
public void timestampFiltersAreAdapted() {
    TimestampRangeFilter filter = new TimestampRangeFilter(10L, 20L);
    Filters.Filter expectedFilter = filterAdapter.adapt(emptyScanContext, filter);
    TimestampRange expectedTimestampFilter = expectedFilter.toProto().getTimestampRangeFilter();
    Assert.assertEquals(10000L, expectedTimestampFilter.getStartTimestampMicros());
    Assert.assertEquals(20000L, expectedTimestampFilter.getEndTimestampMicros());
}
Also used : Filters(com.google.cloud.bigtable.data.v2.models.Filters) TimestampRangeFilter(com.google.cloud.bigtable.hbase.filter.TimestampRangeFilter) TimestampRange(com.google.bigtable.v2.TimestampRange) Test(org.junit.Test)

Example 5 with TimestampRange

use of com.google.bigtable.v2.TimestampRange in project java-bigtable by googleapis.

the class RowMutationTest method toBulkProtoTest.

@Test
public void toBulkProtoTest() {
    long timestampMin = System.currentTimeMillis() * 1_000;
    RowMutation rowMutation = RowMutation.create("fake-table", "fake-key").setCell("fake-family", "fake-qualifier", "fake-value");
    MutateRowsRequest actualRowMutation = rowMutation.toBulkProto(REQUEST_CONTEXT);
    com.google.common.collect.Range<Long> timestampRange = com.google.common.collect.Range.closed(timestampMin, System.currentTimeMillis() * 1_000);
    assertThat(actualRowMutation.getTableName()).isEqualTo(NameUtil.formatTableName(PROJECT_ID, INSTANCE_ID, TABLE_ID));
    assertThat(actualRowMutation.getAppProfileId()).isEqualTo(APP_PROFILE_ID);
    assertThat(actualRowMutation.getEntriesList()).hasSize(1);
    assertThat(actualRowMutation.getEntries(0).getMutationsList()).hasSize(1);
    assertThat(actualRowMutation.getEntries(0).getMutations(0).getSetCell().getValue()).isEqualTo(ByteString.copyFromUtf8("fake-value"));
    assertThat(actualRowMutation.getEntries(0).getMutations(0).getSetCell().getTimestampMicros()).isIn(timestampRange);
}
Also used : MutateRowsRequest(com.google.bigtable.v2.MutateRowsRequest) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)10 TimestampRange (com.google.bigtable.v2.TimestampRange)7 ReadRowsRequest (com.google.bigtable.v2.ReadRowsRequest)4 MutateRowRequest (com.google.bigtable.v2.MutateRowRequest)3 CellsWithinColumnRead (com.spotify.bigtable.read.ReadCells.CellsWithinColumnRead)3 Mutation (com.google.bigtable.v2.Mutation)2 RowMutation (com.google.cloud.bigtable.data.v2.models.RowMutation)2 Delete (org.apache.hadoop.hbase.client.Delete)2 MutateRowsRequest (com.google.bigtable.v2.MutateRowsRequest)1 MutationCase (com.google.bigtable.v2.Mutation.MutationCase)1 RowFilter (com.google.bigtable.v2.RowFilter)1 Filters (com.google.cloud.bigtable.data.v2.models.Filters)1 TimestampRangeFilter (com.google.cloud.bigtable.hbase.filter.TimestampRangeFilter)1 CellWithinCellsRead (com.spotify.bigtable.read.ReadCell.CellWithinCellsRead)1