Search in sources :

Example 1 with KeyOnlyByteBufferExtendedCell

use of org.apache.hadoop.hbase.filter.KeyOnlyFilter.KeyOnlyByteBufferExtendedCell in project hbase by apache.

the class TestKeyOnlyFilter method testKeyOnly.

@Test
public void testKeyOnly() throws Exception {
    byte[] r = Bytes.toBytes("row1");
    byte[] f = Bytes.toBytes("cf1");
    byte[] q = Bytes.toBytes("qual1");
    byte[] v = Bytes.toBytes("val1");
    byte[] tags = Bytes.toBytes("tag1");
    KeyValue kv = new KeyValue(r, f, q, 0, q.length, 1234L, Type.Put, v, 0, v.length, tags);
    ByteBuffer buffer = ByteBuffer.wrap(kv.getBuffer());
    ByteBufferKeyValue bbCell = new ByteBufferKeyValue(buffer, 0, buffer.remaining());
    // KV format: <keylen:4><valuelen:4><key:keylen><value:valuelen>
    // Rebuild as: <keylen:4><0:4><key:keylen>
    int dataLen = lenAsVal ? Bytes.SIZEOF_INT : 0;
    int keyOffset = (2 * Bytes.SIZEOF_INT);
    int keyLen = KeyValueUtil.keyLength(kv);
    byte[] newBuffer = new byte[keyLen + keyOffset + dataLen];
    Bytes.putInt(newBuffer, 0, keyLen);
    Bytes.putInt(newBuffer, Bytes.SIZEOF_INT, dataLen);
    KeyValueUtil.appendKeyTo(kv, newBuffer, keyOffset);
    if (lenAsVal) {
        Bytes.putInt(newBuffer, newBuffer.length - dataLen, kv.getValueLength());
    }
    KeyValue KeyOnlyKeyValue = new KeyValue(newBuffer);
    KeyOnlyCell keyOnlyCell = new KeyOnlyCell(kv, lenAsVal);
    KeyOnlyByteBufferExtendedCell keyOnlyByteBufferedCell = new KeyOnlyByteBufferExtendedCell(bbCell, lenAsVal);
    assertTrue(CellUtil.matchingRows(KeyOnlyKeyValue, keyOnlyCell));
    assertTrue(CellUtil.matchingRows(KeyOnlyKeyValue, keyOnlyByteBufferedCell));
    assertTrue(CellUtil.matchingFamily(KeyOnlyKeyValue, keyOnlyCell));
    assertTrue(CellUtil.matchingFamily(KeyOnlyKeyValue, keyOnlyByteBufferedCell));
    assertTrue(CellUtil.matchingQualifier(KeyOnlyKeyValue, keyOnlyCell));
    assertTrue(CellUtil.matchingQualifier(KeyOnlyKeyValue, keyOnlyByteBufferedCell));
    assertTrue(CellUtil.matchingValue(KeyOnlyKeyValue, keyOnlyCell));
    assertTrue(KeyOnlyKeyValue.getValueLength() == keyOnlyByteBufferedCell.getValueLength());
    assertEquals(8 + keyLen + (lenAsVal ? 4 : 0), KeyOnlyKeyValue.getSerializedSize());
    assertEquals(8 + keyLen + (lenAsVal ? 4 : 0), keyOnlyCell.getSerializedSize());
    if (keyOnlyByteBufferedCell.getValueLength() > 0) {
        assertTrue(CellUtil.matchingValue(KeyOnlyKeyValue, keyOnlyByteBufferedCell));
    }
    assertTrue(KeyOnlyKeyValue.getTimestamp() == keyOnlyCell.getTimestamp());
    assertTrue(KeyOnlyKeyValue.getTimestamp() == keyOnlyByteBufferedCell.getTimestamp());
    assertTrue(KeyOnlyKeyValue.getTypeByte() == keyOnlyCell.getTypeByte());
    assertTrue(KeyOnlyKeyValue.getTypeByte() == keyOnlyByteBufferedCell.getTypeByte());
    assertTrue(KeyOnlyKeyValue.getTagsLength() == keyOnlyCell.getTagsLength());
    assertTrue(KeyOnlyKeyValue.getTagsLength() == keyOnlyByteBufferedCell.getTagsLength());
}
Also used : ByteBufferKeyValue(org.apache.hadoop.hbase.ByteBufferKeyValue) ByteBufferKeyValue(org.apache.hadoop.hbase.ByteBufferKeyValue) KeyValue(org.apache.hadoop.hbase.KeyValue) KeyOnlyByteBufferExtendedCell(org.apache.hadoop.hbase.filter.KeyOnlyFilter.KeyOnlyByteBufferExtendedCell) KeyOnlyCell(org.apache.hadoop.hbase.filter.KeyOnlyFilter.KeyOnlyCell) ByteBuffer(java.nio.ByteBuffer) Test(org.junit.Test)

Aggregations

ByteBuffer (java.nio.ByteBuffer)1 ByteBufferKeyValue (org.apache.hadoop.hbase.ByteBufferKeyValue)1 KeyValue (org.apache.hadoop.hbase.KeyValue)1 KeyOnlyByteBufferExtendedCell (org.apache.hadoop.hbase.filter.KeyOnlyFilter.KeyOnlyByteBufferExtendedCell)1 KeyOnlyCell (org.apache.hadoop.hbase.filter.KeyOnlyFilter.KeyOnlyCell)1 Test (org.junit.Test)1