Search in sources :

Example 1 with TimestampRangeFilter

use of com.google.cloud.bigtable.hbase.filter.TimestampRangeFilter 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 2 with TimestampRangeFilter

use of com.google.cloud.bigtable.hbase.filter.TimestampRangeFilter in project java-bigtable-hbase by googleapis.

the class TestFilters method testTimestampRangeFilterWithMaxVal.

/**
 * This test case is used to validate TimestampRangeFilter with Integer.MAX_VALUE #1552
 *
 * @throws IOException
 */
@Test
public void testTimestampRangeFilterWithMaxVal() throws IOException {
    // Initialize
    long numCols = Integer.MAX_VALUE;
    long start = Integer.MAX_VALUE - 2;
    String goodValue = "includeThisValue";
    Table table = getDefaultTable();
    byte[] rowKey = dataHelper.randomData("testRow-TimestampRange-");
    Put put = new Put(rowKey);
    for (long i = start; i < numCols; ++i) {
        put.addColumn(COLUMN_FAMILY, dataHelper.randomData(""), i, Bytes.toBytes(goodValue));
    }
    table.put(put);
    Filter filter = new TimestampRangeFilter(start, Integer.MAX_VALUE);
    Get get = new Get(rowKey).setFilter(filter);
    Result result = table.get(get);
    Cell[] cells = result.rawCells();
    Assert.assertEquals("Should have all cells.", 2, cells.length);
    long[] timestamps = new long[] { cells[0].getTimestamp(), cells[1].getTimestamp() };
    Arrays.sort(timestamps);
    Assert.assertArrayEquals(new long[] { start, Integer.MAX_VALUE - 1 }, timestamps);
    table.close();
}
Also used : Table(org.apache.hadoop.hbase.client.Table) TimestampRangeFilter(com.google.cloud.bigtable.hbase.filter.TimestampRangeFilter) BigtableFilter(com.google.cloud.bigtable.hbase.filter.BigtableFilter) Filter(org.apache.hadoop.hbase.filter.Filter) Get(org.apache.hadoop.hbase.client.Get) TimestampRangeFilter(com.google.cloud.bigtable.hbase.filter.TimestampRangeFilter) Cell(org.apache.hadoop.hbase.Cell) Put(org.apache.hadoop.hbase.client.Put) Result(org.apache.hadoop.hbase.client.Result) Test(org.junit.Test)

Example 3 with TimestampRangeFilter

use of com.google.cloud.bigtable.hbase.filter.TimestampRangeFilter in project java-bigtable-hbase by googleapis.

the class TestFilters method testTimestampRangeFilter.

@Test
public void testTimestampRangeFilter() throws IOException {
    // Initialize
    int numCols = 10;
    String goodValue = "includeThisValue";
    Table table = getDefaultTable();
    byte[] rowKey = dataHelper.randomData("testRow-TimestampRange-");
    Put put = new Put(rowKey);
    for (int i = 0; i < numCols; ++i) {
        put.addColumn(COLUMN_FAMILY, dataHelper.randomData(""), i, Bytes.toBytes(goodValue));
    }
    table.put(put);
    // Filter for results
    Filter filter = new TimestampRangeFilter(4, 6);
    Get get = new Get(rowKey).setFilter(filter);
    Result result = table.get(get);
    Cell[] cells = result.rawCells();
    Assert.assertEquals("Should have three cells, timestamps 4 and 5.", 2, cells.length);
    // Since the qualifiers are random, ignore the order of the returned cells.
    long[] timestamps = new long[] { cells[0].getTimestamp(), cells[1].getTimestamp() };
    Arrays.sort(timestamps);
    Assert.assertArrayEquals(new long[] { 4L, 5L }, timestamps);
    table.close();
}
Also used : Table(org.apache.hadoop.hbase.client.Table) TimestampRangeFilter(com.google.cloud.bigtable.hbase.filter.TimestampRangeFilter) BigtableFilter(com.google.cloud.bigtable.hbase.filter.BigtableFilter) Filter(org.apache.hadoop.hbase.filter.Filter) Get(org.apache.hadoop.hbase.client.Get) TimestampRangeFilter(com.google.cloud.bigtable.hbase.filter.TimestampRangeFilter) Cell(org.apache.hadoop.hbase.Cell) Put(org.apache.hadoop.hbase.client.Put) Result(org.apache.hadoop.hbase.client.Result) Test(org.junit.Test)

Aggregations

TimestampRangeFilter (com.google.cloud.bigtable.hbase.filter.TimestampRangeFilter)3 Test (org.junit.Test)3 BigtableFilter (com.google.cloud.bigtable.hbase.filter.BigtableFilter)2 Cell (org.apache.hadoop.hbase.Cell)2 Get (org.apache.hadoop.hbase.client.Get)2 Put (org.apache.hadoop.hbase.client.Put)2 Result (org.apache.hadoop.hbase.client.Result)2 Table (org.apache.hadoop.hbase.client.Table)2 Filter (org.apache.hadoop.hbase.filter.Filter)2 TimestampRange (com.google.bigtable.v2.TimestampRange)1 Filters (com.google.cloud.bigtable.data.v2.models.Filters)1