Search in sources :

Example 21 with ByteBufferKeyValue

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

the class TestSingleColumnValueFilter method regexPatternFilterTests.

private void regexPatternFilterTests(Filter filter) throws Exception {
    KeyValue cell = new KeyValue(ROW, COLUMN_FAMILY, COLUMN_QUALIFIER, FULLSTRING_1);
    assertTrue("regexTrue", filter.filterCell(cell) == Filter.ReturnCode.INCLUDE);
    byte[] buffer = cell.getBuffer();
    Cell c = new ByteBufferKeyValue(ByteBuffer.wrap(buffer), 0, buffer.length);
    assertTrue("regexTrue", filter.filterCell(c) == Filter.ReturnCode.INCLUDE);
    assertFalse("regexFilterAllRemaining", filter.filterAllRemaining());
    assertFalse("regexFilterNotNull", filter.filterRow());
}
Also used : ByteBufferKeyValue(org.apache.hadoop.hbase.ByteBufferKeyValue) ByteBufferKeyValue(org.apache.hadoop.hbase.ByteBufferKeyValue) KeyValue(org.apache.hadoop.hbase.KeyValue) Cell(org.apache.hadoop.hbase.Cell)

Example 22 with ByteBufferKeyValue

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

the class TestSingleColumnValueFilter method testLongComparator.

@Test
public void testLongComparator() throws IOException {
    Filter filter = new SingleColumnValueFilter(COLUMN_FAMILY, COLUMN_QUALIFIER, CompareOperator.GREATER, new LongComparator(100L));
    KeyValue cell = new KeyValue(ROW, COLUMN_FAMILY, COLUMN_QUALIFIER, Bytes.toBytes(1L));
    assertTrue("less than", filter.filterCell(cell) == Filter.ReturnCode.NEXT_ROW);
    filter.reset();
    byte[] buffer = cell.getBuffer();
    Cell c = new ByteBufferKeyValue(ByteBuffer.wrap(buffer), 0, buffer.length);
    assertTrue("less than", filter.filterCell(c) == Filter.ReturnCode.NEXT_ROW);
    filter.reset();
    cell = new KeyValue(ROW, COLUMN_FAMILY, COLUMN_QUALIFIER, Bytes.toBytes(100L));
    assertTrue("Equals 100", filter.filterCell(cell) == Filter.ReturnCode.NEXT_ROW);
    filter.reset();
    buffer = cell.getBuffer();
    c = new ByteBufferKeyValue(ByteBuffer.wrap(buffer), 0, buffer.length);
    assertTrue("Equals 100", filter.filterCell(c) == Filter.ReturnCode.NEXT_ROW);
    filter.reset();
    cell = new KeyValue(ROW, COLUMN_FAMILY, COLUMN_QUALIFIER, Bytes.toBytes(120L));
    assertTrue("include 120", filter.filterCell(cell) == Filter.ReturnCode.INCLUDE);
    filter.reset();
    buffer = cell.getBuffer();
    c = new ByteBufferKeyValue(ByteBuffer.wrap(buffer), 0, buffer.length);
    assertTrue("include 120", filter.filterCell(c) == Filter.ReturnCode.INCLUDE);
}
Also used : ByteBufferKeyValue(org.apache.hadoop.hbase.ByteBufferKeyValue) ByteBufferKeyValue(org.apache.hadoop.hbase.ByteBufferKeyValue) KeyValue(org.apache.hadoop.hbase.KeyValue) Cell(org.apache.hadoop.hbase.Cell) Test(org.junit.Test)

Example 23 with ByteBufferKeyValue

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

the class RedundantKVGenerator method generateTestExtendedOffheapKeyValues.

/**
 * Generate test data useful to test encoders.
 * @param howMany How many Key values should be generated.
 * @return sorted list of key values
 */
public List<Cell> generateTestExtendedOffheapKeyValues(int howMany, boolean useTags) {
    List<Cell> result = new ArrayList<>();
    List<byte[]> rows = generateRows();
    Map<Integer, List<byte[]>> rowsToQualifier = new HashMap<>();
    if (family == null) {
        family = new byte[columnFamilyLength];
        randomizer.nextBytes(family);
    }
    long baseTimestamp = Math.abs(randomizer.nextInt()) / baseTimestampDivide;
    byte[] value = new byte[valueLength];
    for (int i = 0; i < howMany; ++i) {
        long timestamp = baseTimestamp;
        if (timestampDiffSize > 0) {
            timestamp += randomizer.nextInt(timestampDiffSize);
        }
        Integer rowId = randomizer.nextInt(rows.size());
        byte[] row = rows.get(rowId);
        // generate qualifier, sometimes it is same, sometimes similar,
        // occasionally completely different
        byte[] qualifier;
        float qualifierChance = randomizer.nextFloat();
        if (!rowsToQualifier.containsKey(rowId) || qualifierChance > chanceForSameQualifier + chanceForSimilarQualifier) {
            int qualifierLength = averageQualifierLength;
            qualifierLength += randomizer.nextInt(2 * qualifierLengthVariance + 1) - qualifierLengthVariance;
            qualifier = new byte[qualifierLength];
            randomizer.nextBytes(qualifier);
            // add it to map
            if (!rowsToQualifier.containsKey(rowId)) {
                rowsToQualifier.put(rowId, new ArrayList<>());
            }
            rowsToQualifier.get(rowId).add(qualifier);
        } else if (qualifierChance > chanceForSameQualifier) {
            // similar qualifier
            List<byte[]> previousQualifiers = rowsToQualifier.get(rowId);
            byte[] originalQualifier = previousQualifiers.get(randomizer.nextInt(previousQualifiers.size()));
            qualifier = new byte[originalQualifier.length];
            int commonPrefix = randomizer.nextInt(qualifier.length);
            System.arraycopy(originalQualifier, 0, qualifier, 0, commonPrefix);
            for (int j = commonPrefix; j < qualifier.length; ++j) {
                qualifier[j] = (byte) (randomizer.nextInt() & 0xff);
            }
            rowsToQualifier.get(rowId).add(qualifier);
        } else {
            // same qualifier
            List<byte[]> previousQualifiers = rowsToQualifier.get(rowId);
            qualifier = previousQualifiers.get(randomizer.nextInt(previousQualifiers.size()));
        }
        if (randomizer.nextFloat() < chanceForZeroValue) {
            Arrays.fill(value, (byte) 0);
        } else {
            randomizer.nextBytes(value);
        }
        if (useTags) {
            KeyValue keyValue = new KeyValue(row, family, qualifier, timestamp, value, new Tag[] { new ArrayBackedTag((byte) 1, "value1") });
            ByteBuffer offheapKVBB = ByteBuffer.allocateDirect(keyValue.getLength());
            ByteBufferUtils.copyFromArrayToBuffer(offheapKVBB, keyValue.getBuffer(), keyValue.getOffset(), keyValue.getLength());
            ByteBufferKeyValue offheapKV = new ExtendedOffheapKeyValue(offheapKVBB, 0, keyValue.getLength(), 0);
            result.add(offheapKV);
        } else {
            KeyValue keyValue = new KeyValue(row, family, qualifier, timestamp, value);
            ByteBuffer offheapKVBB = ByteBuffer.allocateDirect(keyValue.getLength());
            ByteBufferUtils.copyFromArrayToBuffer(offheapKVBB, keyValue.getBuffer(), keyValue.getOffset(), keyValue.getLength());
            ByteBufferKeyValue offheapKV = new ExtendedOffheapKeyValue(offheapKVBB, 0, keyValue.getLength(), 0);
            result.add(offheapKV);
        }
    }
    result.sort(CellComparator.getInstance());
    return result;
}
Also used : ByteBufferKeyValue(org.apache.hadoop.hbase.ByteBufferKeyValue) KeyValue(org.apache.hadoop.hbase.KeyValue) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) ArrayBackedTag(org.apache.hadoop.hbase.ArrayBackedTag) ByteBuffer(java.nio.ByteBuffer) ByteBufferKeyValue(org.apache.hadoop.hbase.ByteBufferKeyValue) ArrayList(java.util.ArrayList) List(java.util.List) Cell(org.apache.hadoop.hbase.Cell)

Example 24 with ByteBufferKeyValue

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

the class TestTagCompressionContext method createOffheapKVWithTags.

private Cell createOffheapKVWithTags(int noOfTags) {
    List<Tag> tags = new ArrayList<>();
    for (int i = 0; i < noOfTags; i++) {
        tags.add(new ArrayBackedTag((byte) i, "tagValue" + i));
    }
    KeyValue kv = new KeyValue(ROW, CF, Q, 1234L, V, tags);
    ByteBuffer dbb = ByteBuffer.allocateDirect(kv.getBuffer().length);
    ByteBufferUtils.copyFromArrayToBuffer(dbb, kv.getBuffer(), 0, kv.getBuffer().length);
    ByteBufferKeyValue offheapKV = new ByteBufferKeyValue(dbb, 0, kv.getBuffer().length, 0);
    return offheapKV;
}
Also used : ByteBufferKeyValue(org.apache.hadoop.hbase.ByteBufferKeyValue) ByteBufferKeyValue(org.apache.hadoop.hbase.ByteBufferKeyValue) KeyValue(org.apache.hadoop.hbase.KeyValue) ArrayList(java.util.ArrayList) ArrayBackedTag(org.apache.hadoop.hbase.ArrayBackedTag) Tag(org.apache.hadoop.hbase.Tag) ArrayBackedTag(org.apache.hadoop.hbase.ArrayBackedTag) ByteBuffer(java.nio.ByteBuffer)

Example 25 with ByteBufferKeyValue

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

the class TestMemStoreLAB method testLABRandomAllocation.

/**
 * Test a bunch of random allocations
 */
@Test
public void testLABRandomAllocation() {
    Random rand = new Random();
    MemStoreLAB mslab = new MemStoreLABImpl();
    int expectedOff = 0;
    ByteBuffer lastBuffer = null;
    int lastChunkId = -1;
    // behavior
    for (int i = 0; i < 100000; i++) {
        int valSize = rand.nextInt(3);
        KeyValue kv = new KeyValue(rk, cf, q, new byte[valSize]);
        int size = kv.getSerializedSize();
        ByteBufferKeyValue newKv = (ByteBufferKeyValue) mslab.copyCellInto(kv);
        if (newKv.getBuffer() != lastBuffer) {
            // since we add the chunkID at the 0th offset of the chunk and the
            // chunkid is an int we need to account for those 4 bytes
            expectedOff = Bytes.SIZEOF_INT;
            lastBuffer = newKv.getBuffer();
            int chunkId = newKv.getBuffer().getInt(0);
            assertTrue("chunkid should be different", chunkId != lastChunkId);
            lastChunkId = chunkId;
        }
        assertEquals(expectedOff, newKv.getOffset());
        assertTrue("Allocation overruns buffer", newKv.getOffset() + size <= newKv.getBuffer().capacity());
        expectedOff += size;
    }
}
Also used : ByteBufferKeyValue(org.apache.hadoop.hbase.ByteBufferKeyValue) ByteBufferKeyValue(org.apache.hadoop.hbase.ByteBufferKeyValue) KeyValue(org.apache.hadoop.hbase.KeyValue) Random(java.util.Random) ByteBuffer(java.nio.ByteBuffer) Test(org.junit.Test)

Aggregations

ByteBufferKeyValue (org.apache.hadoop.hbase.ByteBufferKeyValue)26 KeyValue (org.apache.hadoop.hbase.KeyValue)22 ByteBuffer (java.nio.ByteBuffer)16 Cell (org.apache.hadoop.hbase.Cell)14 Test (org.junit.Test)11 ArrayList (java.util.ArrayList)6 ArrayBackedTag (org.apache.hadoop.hbase.ArrayBackedTag)6 Random (java.util.Random)4 Tag (org.apache.hadoop.hbase.Tag)4 List (java.util.List)3 Configuration (org.apache.hadoop.conf.Configuration)3 Path (org.apache.hadoop.fs.Path)3 HashMap (java.util.HashMap)2 ExtendedCell (org.apache.hadoop.hbase.ExtendedCell)2 CellProtos (org.apache.hadoop.hbase.shaded.protobuf.generated.CellProtos)2 IOException (java.io.IOException)1 Map (java.util.Map)1 TreeMap (java.util.TreeMap)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 FileSystem (org.apache.hadoop.fs.FileSystem)1