Search in sources :

Example 1 with LongComparator

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

the class TestFromClientSide method testFilterWithLongCompartor.

@Test
public void testFilterWithLongCompartor() throws Exception {
    final TableName tableName = TableName.valueOf(name.getMethodName());
    Table ht = TEST_UTIL.createTable(tableName, FAMILY);
    byte[][] ROWS = makeN(ROW, 10);
    byte[][] values = new byte[10][];
    for (int i = 0; i < 10; i++) {
        values[i] = Bytes.toBytes(100L * i);
    }
    for (int i = 0; i < 10; i++) {
        Put put = new Put(ROWS[i]);
        put.setDurability(Durability.SKIP_WAL);
        put.addColumn(FAMILY, QUALIFIER, values[i]);
        ht.put(put);
    }
    Scan scan = new Scan();
    scan.addFamily(FAMILY);
    Filter filter = new SingleColumnValueFilter(FAMILY, QUALIFIER, CompareOp.GREATER, new LongComparator(500));
    scan.setFilter(filter);
    ResultScanner scanner = ht.getScanner(scan);
    int expectedIndex = 0;
    for (Result result : ht.getScanner(scan)) {
        assertEquals(result.size(), 1);
        assertTrue(Bytes.toLong(result.getValue(FAMILY, QUALIFIER)) > 500);
        expectedIndex++;
    }
    assertEquals(expectedIndex, 4);
    scanner.close();
}
Also used : TableName(org.apache.hadoop.hbase.TableName) SingleColumnValueFilter(org.apache.hadoop.hbase.filter.SingleColumnValueFilter) FirstKeyOnlyFilter(org.apache.hadoop.hbase.filter.FirstKeyOnlyFilter) WhileMatchFilter(org.apache.hadoop.hbase.filter.WhileMatchFilter) PrefixFilter(org.apache.hadoop.hbase.filter.PrefixFilter) QualifierFilter(org.apache.hadoop.hbase.filter.QualifierFilter) KeyOnlyFilter(org.apache.hadoop.hbase.filter.KeyOnlyFilter) CompareFilter(org.apache.hadoop.hbase.filter.CompareFilter) InclusiveStopFilter(org.apache.hadoop.hbase.filter.InclusiveStopFilter) RowFilter(org.apache.hadoop.hbase.filter.RowFilter) Filter(org.apache.hadoop.hbase.filter.Filter) SingleColumnValueFilter(org.apache.hadoop.hbase.filter.SingleColumnValueFilter) LongComparator(org.apache.hadoop.hbase.filter.LongComparator) MultiRowMutationEndpoint(org.apache.hadoop.hbase.coprocessor.MultiRowMutationEndpoint) Test(org.junit.Test)

Aggregations

TableName (org.apache.hadoop.hbase.TableName)1 MultiRowMutationEndpoint (org.apache.hadoop.hbase.coprocessor.MultiRowMutationEndpoint)1 CompareFilter (org.apache.hadoop.hbase.filter.CompareFilter)1 Filter (org.apache.hadoop.hbase.filter.Filter)1 FirstKeyOnlyFilter (org.apache.hadoop.hbase.filter.FirstKeyOnlyFilter)1 InclusiveStopFilter (org.apache.hadoop.hbase.filter.InclusiveStopFilter)1 KeyOnlyFilter (org.apache.hadoop.hbase.filter.KeyOnlyFilter)1 LongComparator (org.apache.hadoop.hbase.filter.LongComparator)1 PrefixFilter (org.apache.hadoop.hbase.filter.PrefixFilter)1 QualifierFilter (org.apache.hadoop.hbase.filter.QualifierFilter)1 RowFilter (org.apache.hadoop.hbase.filter.RowFilter)1 SingleColumnValueFilter (org.apache.hadoop.hbase.filter.SingleColumnValueFilter)1 WhileMatchFilter (org.apache.hadoop.hbase.filter.WhileMatchFilter)1 Test (org.junit.Test)1