Search in sources :

Example 61 with KeyValue

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

the class TestHFileDataBlockEncoder method createBlockOnDisk.

private HFileBlock createBlockOnDisk(List<KeyValue> kvs, HFileBlock block, boolean useTags) throws IOException {
    int size;
    HFileBlockEncodingContext context = new HFileBlockDefaultEncodingContext(blockEncoder.getDataBlockEncoding(), HConstants.HFILEBLOCK_DUMMY_HEADER, block.getHFileContext());
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    baos.write(block.getDummyHeaderForVersion());
    DataOutputStream dos = new DataOutputStream(baos);
    blockEncoder.startBlockEncoding(context, dos);
    for (KeyValue kv : kvs) {
        blockEncoder.encode(kv, context, dos);
    }
    blockEncoder.endBlockEncoding(context, dos, baos.getBuffer(), BlockType.DATA);
    byte[] encodedBytes = baos.toByteArray();
    size = encodedBytes.length - block.getDummyHeaderForVersion().length;
    return new HFileBlock(context.getBlockType(), size, size, -1, ByteBuffer.wrap(encodedBytes), HFileBlock.FILL_HEADER, 0, block.getOnDiskDataSizeWithHeader(), -1, block.getHFileContext());
}
Also used : KeyValue(org.apache.hadoop.hbase.KeyValue) DataOutputStream(java.io.DataOutputStream) HFileBlockDefaultEncodingContext(org.apache.hadoop.hbase.io.encoding.HFileBlockDefaultEncodingContext) HFileBlockEncodingContext(org.apache.hadoop.hbase.io.encoding.HFileBlockEncodingContext) ByteArrayOutputStream(org.apache.hadoop.hbase.io.ByteArrayOutputStream)

Example 62 with KeyValue

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

the class TestSeekToBlockWithEncoders method testSeekToBlockWithDiffQualiferOnSameRow.

@Test
public void testSeekToBlockWithDiffQualiferOnSameRow() throws IOException {
    List<KeyValue> sampleKv = new ArrayList<>();
    KeyValue kv1 = new KeyValue(Bytes.toBytes("aaa"), Bytes.toBytes("f1"), Bytes.toBytes("q1"), Bytes.toBytes("val"));
    sampleKv.add(kv1);
    KeyValue kv2 = new KeyValue(Bytes.toBytes("aaa"), Bytes.toBytes("f1"), Bytes.toBytes("q2"), Bytes.toBytes("val"));
    sampleKv.add(kv2);
    KeyValue kv4 = new KeyValue(Bytes.toBytes("aaa"), Bytes.toBytes("f1"), Bytes.toBytes("q3"), Bytes.toBytes("val"));
    sampleKv.add(kv4);
    KeyValue kv5 = new KeyValue(Bytes.toBytes("aaa"), Bytes.toBytes("f1"), Bytes.toBytes("q4"), Bytes.toBytes("val"));
    sampleKv.add(kv5);
    KeyValue kv6 = new KeyValue(Bytes.toBytes("aaa"), Bytes.toBytes("f1"), Bytes.toBytes("q5"), Bytes.toBytes("val"));
    sampleKv.add(kv6);
    KeyValue toSeek = new KeyValue(Bytes.toBytes("aaa"), Bytes.toBytes("f1"), Bytes.toBytes("q5"), Bytes.toBytes("val"));
    seekToTheKey(kv6, sampleKv, toSeek);
}
Also used : KeyValue(org.apache.hadoop.hbase.KeyValue) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Example 63 with KeyValue

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

the class TestSeekToBlockWithEncoders method testSeekToBlockWithDecreasingCommonPrefix.

/**
   * Test seeking while file is encoded.
   */
@Test
public void testSeekToBlockWithDecreasingCommonPrefix() throws IOException {
    List<KeyValue> sampleKv = new ArrayList<>();
    KeyValue kv1 = new KeyValue(Bytes.toBytes("row10aaa"), Bytes.toBytes("f1"), Bytes.toBytes("q1"), Bytes.toBytes("val"));
    sampleKv.add(kv1);
    KeyValue kv2 = new KeyValue(Bytes.toBytes("row10aaa"), Bytes.toBytes("f1"), Bytes.toBytes("q2"), Bytes.toBytes("val"));
    sampleKv.add(kv2);
    KeyValue kv3 = new KeyValue(Bytes.toBytes("row10aaa"), Bytes.toBytes("f1"), Bytes.toBytes("q3"), Bytes.toBytes("val"));
    sampleKv.add(kv3);
    KeyValue kv4 = new KeyValue(Bytes.toBytes("row11baa"), Bytes.toBytes("f1"), Bytes.toBytes("q1"), Bytes.toBytes("val"));
    sampleKv.add(kv4);
    Cell toSeek = CellUtil.createLastOnRow(kv3);
    seekToTheKey(kv3, sampleKv, toSeek);
}
Also used : KeyValue(org.apache.hadoop.hbase.KeyValue) ArrayList(java.util.ArrayList) Cell(org.apache.hadoop.hbase.Cell) Test(org.junit.Test)

Example 64 with KeyValue

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

the class TestSeekToBlockWithEncoders method testSeekingToBlockWithBiggerNonLength1.

/**
   * Test seeking while file is encoded.
   */
@Test
public void testSeekingToBlockWithBiggerNonLength1() throws IOException {
    List<KeyValue> sampleKv = new ArrayList<>();
    KeyValue kv1 = new KeyValue(Bytes.toBytes("aaa"), Bytes.toBytes("f1"), Bytes.toBytes("q1"), Bytes.toBytes("val"));
    sampleKv.add(kv1);
    KeyValue kv2 = new KeyValue(Bytes.toBytes("aab"), Bytes.toBytes("f1"), Bytes.toBytes("q1"), Bytes.toBytes("val"));
    sampleKv.add(kv2);
    KeyValue kv3 = new KeyValue(Bytes.toBytes("aac"), Bytes.toBytes("f1"), Bytes.toBytes("q1"), Bytes.toBytes("val"));
    sampleKv.add(kv3);
    KeyValue kv4 = new KeyValue(Bytes.toBytes("aad"), Bytes.toBytes("f1"), Bytes.toBytes("q1"), Bytes.toBytes("val"));
    sampleKv.add(kv4);
    KeyValue kv5 = new KeyValue(Bytes.toBytes("aaddd"), Bytes.toBytes("f1"), Bytes.toBytes("q1"), Bytes.toBytes("val"));
    sampleKv.add(kv5);
    KeyValue toSeek = new KeyValue(Bytes.toBytes("aaaa"), Bytes.toBytes("f1"), Bytes.toBytes("q1"), Bytes.toBytes("val"));
    seekToTheKey(kv1, sampleKv, toSeek);
}
Also used : KeyValue(org.apache.hadoop.hbase.KeyValue) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Example 65 with KeyValue

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

the class TestSeekToBlockWithEncoders method testSeekToBlockWithDiffQualiferOnSameRow1.

@Test
public void testSeekToBlockWithDiffQualiferOnSameRow1() throws IOException {
    List<KeyValue> sampleKv = new ArrayList<>();
    KeyValue kv1 = new KeyValue(Bytes.toBytes("aaa"), Bytes.toBytes("f1"), Bytes.toBytes("q1"), Bytes.toBytes("val"));
    sampleKv.add(kv1);
    KeyValue kv2 = new KeyValue(Bytes.toBytes("aaa"), Bytes.toBytes("f1"), Bytes.toBytes("q2"), Bytes.toBytes("val"));
    sampleKv.add(kv2);
    KeyValue kv4 = new KeyValue(Bytes.toBytes("aaa"), Bytes.toBytes("f1"), Bytes.toBytes("q3"), Bytes.toBytes("val"));
    sampleKv.add(kv4);
    KeyValue kv5 = new KeyValue(Bytes.toBytes("aaa"), Bytes.toBytes("f1"), Bytes.toBytes("q4"), Bytes.toBytes("val"));
    sampleKv.add(kv5);
    KeyValue kv6 = new KeyValue(Bytes.toBytes("aaa"), Bytes.toBytes("f1"), Bytes.toBytes("z5"), Bytes.toBytes("val"));
    sampleKv.add(kv6);
    KeyValue toSeek = new KeyValue(Bytes.toBytes("aaa"), Bytes.toBytes("f1"), Bytes.toBytes("q5"), Bytes.toBytes("val"));
    seekToTheKey(kv5, sampleKv, toSeek);
}
Also used : KeyValue(org.apache.hadoop.hbase.KeyValue) ArrayList(java.util.ArrayList) 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