Search in sources :

Example 6 with CellSearcher

use of org.apache.hadoop.hbase.codec.prefixtree.scanner.CellSearcher in project hbase by apache.

the class TestPrefixTreeSearcher method testScanForwards.

@Test
public void testScanForwards() throws IOException {
    CellSearcher searcher = null;
    try {
        searcher = DecoderFactory.checkOut(block, true);
        int i = -1;
        while (searcher.advance()) {
            ++i;
            KeyValue inputCell = rows.getInputs().get(i);
            Cell outputCell = searcher.current();
            // check all 3 permutations of equals()
            Assert.assertEquals(inputCell, outputCell);
            Assert.assertEquals(outputCell, inputCell);
            Assert.assertTrue(CellUtil.equals(inputCell, outputCell));
        }
        Assert.assertEquals(rows.getInputs().size(), i + 1);
    } finally {
        DecoderFactory.checkIn(searcher);
    }
}
Also used : CellSearcher(org.apache.hadoop.hbase.codec.prefixtree.scanner.CellSearcher) KeyValue(org.apache.hadoop.hbase.KeyValue) Cell(org.apache.hadoop.hbase.Cell) Test(org.junit.Test)

Example 7 with CellSearcher

use of org.apache.hadoop.hbase.codec.prefixtree.scanner.CellSearcher in project hbase by apache.

the class TestPrefixTreeSearcher method testSeekWithPrefix.

@Test
public void testSeekWithPrefix() throws IOException {
    if (!(rows instanceof TestRowDataSearchWithPrefix)) {
        return;
    }
    CellSearcher searcher = null;
    try {
        searcher = DecoderFactory.checkOut(block, true);
        // seek with half bytes of second row key, should return second row
        KeyValue kv = rows.getInputs().get(1);
        KeyValue firstKVOnRow = KeyValueUtil.createFirstOnRow(Arrays.copyOfRange(kv.getRowArray(), kv.getRowOffset(), kv.getRowOffset() + kv.getRowLength() / 2));
        CellScannerPosition position = searcher.positionAtOrAfter(firstKVOnRow);
        Assert.assertEquals(CellScannerPosition.AFTER, position);
        Assert.assertEquals(kv, searcher.current());
    } finally {
        DecoderFactory.checkIn(searcher);
    }
}
Also used : CellSearcher(org.apache.hadoop.hbase.codec.prefixtree.scanner.CellSearcher) KeyValue(org.apache.hadoop.hbase.KeyValue) TestRowDataSearchWithPrefix(org.apache.hadoop.hbase.codec.prefixtree.row.data.TestRowDataSearchWithPrefix) CellScannerPosition(org.apache.hadoop.hbase.codec.prefixtree.scanner.CellScannerPosition) Test(org.junit.Test)

Aggregations

CellSearcher (org.apache.hadoop.hbase.codec.prefixtree.scanner.CellSearcher)7 KeyValue (org.apache.hadoop.hbase.KeyValue)6 Test (org.junit.Test)6 Cell (org.apache.hadoop.hbase.Cell)3 CellScannerPosition (org.apache.hadoop.hbase.codec.prefixtree.scanner.CellScannerPosition)2 ByteBuffer (java.nio.ByteBuffer)1 TestRowDataSearchWithPrefix (org.apache.hadoop.hbase.codec.prefixtree.row.data.TestRowDataSearchWithPrefix)1 SingleByteBuff (org.apache.hadoop.hbase.nio.SingleByteBuff)1