Search in sources :

Example 21 with KeyValue

use of org.apache.hadoop.hbase.KeyValue in project hbase by apache.

the class TestPrefixTreeSearcher method testRandomSeekMisses.

@Test
public void testRandomSeekMisses() throws IOException {
    CellSearcher searcher = null;
    List<Integer> rowStartIndexes = rows.getRowStartIndexes();
    try {
        searcher = DecoderFactory.checkOut(block, true);
        //test both the positionAtOrBefore and positionAtOrAfter methods
        for (boolean beforeVsAfterOnMiss : new boolean[] { true, false }) {
            for (int i = 0; i < rows.getInputs().size(); ++i) {
                KeyValue kv = rows.getInputs().get(i);
                //nextRow
                Cell inputNextRow = CellUtil.createFirstOnNextRow(kv);
                CellScannerPosition position = beforeVsAfterOnMiss ? searcher.positionAtOrBefore(inputNextRow) : searcher.positionAtOrAfter(inputNextRow);
                boolean isFirstInRow = rowStartIndexes.contains(i);
                if (isFirstInRow) {
                    int rowIndex = rowStartIndexes.indexOf(i);
                    if (rowIndex < rowStartIndexes.size() - 1) {
                        if (beforeVsAfterOnMiss) {
                            Assert.assertEquals(CellScannerPosition.BEFORE, position);
                        } else {
                            Assert.assertEquals(CellScannerPosition.AFTER, position);
                        }
                        int expectedInputIndex = beforeVsAfterOnMiss ? rowStartIndexes.get(rowIndex + 1) - 1 : rowStartIndexes.get(rowIndex + 1);
                        Assert.assertEquals(rows.getInputs().get(expectedInputIndex), searcher.current());
                    }
                }
                //previous KV
                KeyValue inputPreviousKv = KeyValueUtil.previousKey(kv);
                boolean hit = searcher.positionAt(inputPreviousKv);
                Assert.assertFalse(hit);
                position = searcher.positionAtOrAfter(inputPreviousKv);
                if (CollectionUtils.isLastIndex(rows.getInputs(), i)) {
                    Assert.assertTrue(CellScannerPosition.AFTER_LAST == position);
                } else {
                    Assert.assertTrue(CellScannerPosition.AFTER == position);
                    /*
             * TODO: why i+1 instead of i?
             */
                    Assert.assertEquals(rows.getInputs().get(i + 1), searcher.current());
                }
            }
        }
    } finally {
        DecoderFactory.checkIn(searcher);
    }
}
Also used : CellSearcher(org.apache.hadoop.hbase.codec.prefixtree.scanner.CellSearcher) KeyValue(org.apache.hadoop.hbase.KeyValue) CellScannerPosition(org.apache.hadoop.hbase.codec.prefixtree.scanner.CellScannerPosition) Cell(org.apache.hadoop.hbase.Cell) Test(org.junit.Test)

Example 22 with KeyValue

use of org.apache.hadoop.hbase.KeyValue in project hbase by apache.

the class TestPrefixTreeSearcher method testRandomSeekHits.

@Test
public void testRandomSeekHits() throws IOException {
    CellSearcher searcher = null;
    try {
        searcher = DecoderFactory.checkOut(block, true);
        for (KeyValue kv : rows.getInputs()) {
            boolean hit = searcher.positionAt(kv);
            Assert.assertTrue(hit);
            Cell foundKv = searcher.current();
            Assert.assertTrue(CellUtil.equals(kv, foundKv));
        }
    } 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 23 with KeyValue

use of org.apache.hadoop.hbase.KeyValue in project hbase by apache.

the class TestPrefixTreeSearcher method testScanBackwards.

@Test
public void testScanBackwards() throws IOException {
    CellSearcher searcher = null;
    try {
        searcher = DecoderFactory.checkOut(block, true);
        searcher.positionAfterLastCell();
        int i = -1;
        while (searcher.previous()) {
            ++i;
            int oppositeIndex = rows.getInputs().size() - i - 1;
            KeyValue inputKv = rows.getInputs().get(oppositeIndex);
            KeyValue outputKv = KeyValueUtil.copyToNewKeyValue(searcher.current());
            Assert.assertEquals(inputKv, outputKv);
        }
        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) Test(org.junit.Test)

Example 24 with KeyValue

use of org.apache.hadoop.hbase.KeyValue 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 25 with KeyValue

use of org.apache.hadoop.hbase.KeyValue 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

KeyValue (org.apache.hadoop.hbase.KeyValue)552 Test (org.junit.Test)289 Cell (org.apache.hadoop.hbase.Cell)193 ArrayList (java.util.ArrayList)172 Put (org.apache.hadoop.hbase.client.Put)98 Scan (org.apache.hadoop.hbase.client.Scan)85 Result (org.apache.hadoop.hbase.client.Result)70 Configuration (org.apache.hadoop.conf.Configuration)64 Path (org.apache.hadoop.fs.Path)55 ArrayBackedTag (org.apache.hadoop.hbase.ArrayBackedTag)36 Tag (org.apache.hadoop.hbase.Tag)35 ByteBuffer (java.nio.ByteBuffer)34 List (java.util.List)34 HColumnDescriptor (org.apache.hadoop.hbase.HColumnDescriptor)34 IOException (java.io.IOException)32 TableName (org.apache.hadoop.hbase.TableName)32 TreeMap (java.util.TreeMap)29 HBaseConfiguration (org.apache.hadoop.hbase.HBaseConfiguration)28 HRegionInfo (org.apache.hadoop.hbase.HRegionInfo)28 WALEdit (org.apache.hadoop.hbase.regionserver.wal.WALEdit)27