Search in sources :

Example 1 with BigtableFilter

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

the class TestFilters method testBigtableFilter.

@Test
public void testBigtableFilter() throws IOException {
    if (!sharedTestEnv.isBigtable()) {
        return;
    }
    byte[] rowKey = dataHelper.randomData("cbt-filter-");
    byte[] qualA = Bytes.toBytes("a");
    byte[] qualB = Bytes.toBytes("b");
    byte[] valA = dataHelper.randomData("a");
    byte[] valB = dataHelper.randomData("b");
    try (Table table = getDefaultTable()) {
        table.put(new Put(rowKey).addColumn(COLUMN_FAMILY, qualA, valA).addColumn(COLUMN_FAMILY, qualB, valB));
        Filters.Filter qualAFilter = Filters.FILTERS.qualifier().exactMatch(new String(qualA));
        BigtableFilter bigtableFilter = new BigtableFilter(qualAFilter);
        Result result = table.get(new Get(rowKey).setFilter(bigtableFilter));
        Assert.assertEquals(1, result.size());
        Assert.assertTrue(CellUtil.matchingValue(result.rawCells()[0], valA));
    }
}
Also used : Filters(com.google.cloud.bigtable.data.v2.models.Filters) Table(org.apache.hadoop.hbase.client.Table) Get(org.apache.hadoop.hbase.client.Get) BigtableFilter(com.google.cloud.bigtable.hbase.filter.BigtableFilter) Put(org.apache.hadoop.hbase.client.Put) Result(org.apache.hadoop.hbase.client.Result) Test(org.junit.Test)

Aggregations

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