Search in sources :

Example 1 with ColumnCountGetFilter

use of org.apache.hadoop.hbase.filter.ColumnCountGetFilter in project hbase by apache.

the class TestHRegion method testGet_Basic.

@Test
public void testGet_Basic() throws IOException {
    byte[] row1 = Bytes.toBytes("row1");
    byte[] fam1 = Bytes.toBytes("fam1");
    byte[] col1 = Bytes.toBytes("col1");
    byte[] col2 = Bytes.toBytes("col2");
    byte[] col3 = Bytes.toBytes("col3");
    byte[] col4 = Bytes.toBytes("col4");
    byte[] col5 = Bytes.toBytes("col5");
    // Setting up region
    this.region = initHRegion(tableName, method, CONF, fam1);
    try {
        // Add to memstore
        Put put = new Put(row1);
        put.addColumn(fam1, col1, null);
        put.addColumn(fam1, col2, null);
        put.addColumn(fam1, col3, null);
        put.addColumn(fam1, col4, null);
        put.addColumn(fam1, col5, null);
        region.put(put);
        Get get = new Get(row1);
        get.addColumn(fam1, col2);
        get.addColumn(fam1, col4);
        // Expected result
        KeyValue kv1 = new KeyValue(row1, fam1, col2);
        KeyValue kv2 = new KeyValue(row1, fam1, col4);
        KeyValue[] expected = { kv1, kv2 };
        // Test
        Result res = region.get(get);
        assertEquals(expected.length, res.size());
        for (int i = 0; i < res.size(); i++) {
            assertTrue(CellUtil.matchingRow(expected[i], res.rawCells()[i]));
            assertTrue(CellUtil.matchingFamily(expected[i], res.rawCells()[i]));
            assertTrue(CellUtil.matchingQualifier(expected[i], res.rawCells()[i]));
        }
        // Test using a filter on a Get
        Get g = new Get(row1);
        final int count = 2;
        g.setFilter(new ColumnCountGetFilter(count));
        res = region.get(g);
        assertEquals(count, res.size());
    } finally {
        HBaseTestingUtility.closeRegionAndWAL(this.region);
        this.region = null;
    }
}
Also used : KeyValue(org.apache.hadoop.hbase.KeyValue) ColumnCountGetFilter(org.apache.hadoop.hbase.filter.ColumnCountGetFilter) Get(org.apache.hadoop.hbase.client.Get) Put(org.apache.hadoop.hbase.client.Put) Result(org.apache.hadoop.hbase.client.Result) Test(org.junit.Test)

Aggregations

KeyValue (org.apache.hadoop.hbase.KeyValue)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 ColumnCountGetFilter (org.apache.hadoop.hbase.filter.ColumnCountGetFilter)1 Test (org.junit.Test)1