Search in sources :

Example 26 with ArrayBackedTag

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

the class TestDataBlockEncoders method testZeroByte.

@Test
public void testZeroByte() throws IOException {
    List<KeyValue> kvList = new ArrayList<>();
    byte[] row = Bytes.toBytes("abcd");
    byte[] family = new byte[] { 'f' };
    byte[] qualifier0 = new byte[] { 'b' };
    byte[] qualifier1 = new byte[] { 'c' };
    byte[] value0 = new byte[] { 'd' };
    byte[] value1 = new byte[] { 0x00 };
    if (includesTags) {
        kvList.add(new KeyValue(row, family, qualifier0, 0, value0, new Tag[] { new ArrayBackedTag((byte) 1, "value1") }));
        kvList.add(new KeyValue(row, family, qualifier1, 0, value1, new Tag[] { new ArrayBackedTag((byte) 1, "value1") }));
    } else {
        kvList.add(new KeyValue(row, family, qualifier0, 0, Type.Put, value0));
        kvList.add(new KeyValue(row, family, qualifier1, 0, Type.Put, value1));
    }
    testEncodersOnDataset(kvList, includesMemstoreTS, includesTags);
}
Also used : 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) Test(org.junit.Test)

Example 27 with ArrayBackedTag

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

the class TestDataBlockEncoders method testEmptyKeyValues.

/**
   * Test data block encoding of empty KeyValue.
   * 
   * @throws IOException
   *           On test failure.
   */
@Test
public void testEmptyKeyValues() throws IOException {
    List<KeyValue> kvList = new ArrayList<>();
    byte[] row = new byte[0];
    byte[] family = new byte[0];
    byte[] qualifier = new byte[0];
    byte[] value = new byte[0];
    if (!includesTags) {
        kvList.add(new KeyValue(row, family, qualifier, 0l, value));
        kvList.add(new KeyValue(row, family, qualifier, 0l, value));
    } else {
        byte[] metaValue1 = Bytes.toBytes("metaValue1");
        byte[] metaValue2 = Bytes.toBytes("metaValue2");
        kvList.add(new KeyValue(row, family, qualifier, 0l, value, new Tag[] { new ArrayBackedTag((byte) 1, metaValue1) }));
        kvList.add(new KeyValue(row, family, qualifier, 0l, value, new Tag[] { new ArrayBackedTag((byte) 1, metaValue2) }));
    }
    testEncodersOnDataset(kvList, includesMemstoreTS, includesTags);
}
Also used : 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) Test(org.junit.Test)

Example 28 with ArrayBackedTag

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

the class TestPrefixTreeEncoding method generateRandomTestData.

private static void generateRandomTestData(ConcurrentSkipListSet<Cell> kvset, int batchId, boolean useTags, PrefixTreeCodec encoder, HFileBlockEncodingContext blkEncodingCtx, DataOutputStream userDataStream) throws Exception {
    Random random = new Random();
    for (int i = 0; i < NUM_ROWS_PER_BATCH; ++i) {
        if (random.nextInt(100) < 50)
            continue;
        for (int j = 0; j < NUM_COLS_PER_ROW; ++j) {
            if (random.nextInt(100) < 50)
                continue;
            if (!useTags) {
                KeyValue kv = new KeyValue(getRowKey(batchId, i), CF_BYTES, getQualifier(j), getValue(batchId, i, j));
                kvset.add(kv);
            } else {
                KeyValue kv = new KeyValue(getRowKey(batchId, i), CF_BYTES, getQualifier(j), 0l, getValue(batchId, i, j), new Tag[] { new ArrayBackedTag((byte) 1, "metaValue1") });
                kvset.add(kv);
            }
        }
    }
    encoder.startBlockEncoding(blkEncodingCtx, userDataStream);
    for (Cell kv : kvset) {
        encoder.encode(kv, blkEncodingCtx, userDataStream);
    }
    encoder.endBlockEncoding(blkEncodingCtx, userDataStream, null);
}
Also used : KeyValue(org.apache.hadoop.hbase.KeyValue) Random(java.util.Random) ArrayBackedTag(org.apache.hadoop.hbase.ArrayBackedTag) Cell(org.apache.hadoop.hbase.Cell)

Example 29 with ArrayBackedTag

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

the class TestPrefixTreeEncoding method generateFixedTestData.

private static void generateFixedTestData(ConcurrentSkipListSet<Cell> kvset, int batchId, boolean partial, boolean useTags, PrefixTreeCodec encoder, HFileBlockEncodingContext blkEncodingCtx, DataOutputStream userDataStream) throws Exception {
    for (int i = 0; i < NUM_ROWS_PER_BATCH; ++i) {
        if (partial && i / 10 % 2 == 1)
            continue;
        for (int j = 0; j < NUM_COLS_PER_ROW; ++j) {
            if (!useTags) {
                KeyValue kv = new KeyValue(getRowKey(batchId, i), CF_BYTES, getQualifier(j), getValue(batchId, i, j));
                kvset.add(kv);
            } else {
                KeyValue kv = new KeyValue(getRowKey(batchId, i), CF_BYTES, getQualifier(j), 0l, getValue(batchId, i, j), new Tag[] { new ArrayBackedTag((byte) 1, "metaValue1") });
                kvset.add(kv);
            }
        }
    }
    encoder.startBlockEncoding(blkEncodingCtx, userDataStream);
    for (Cell kv : kvset) {
        encoder.encode(kv, blkEncodingCtx, userDataStream);
    }
    encoder.endBlockEncoding(blkEncodingCtx, userDataStream, null);
}
Also used : KeyValue(org.apache.hadoop.hbase.KeyValue) ArrayBackedTag(org.apache.hadoop.hbase.ArrayBackedTag) Cell(org.apache.hadoop.hbase.Cell)

Example 30 with ArrayBackedTag

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

the class TestReseekTo method testReseekToInternals.

private void testReseekToInternals(TagUsage tagUsage) throws IOException {
    Path ncTFile = new Path(TEST_UTIL.getDataTestDir(), "basic.hfile");
    FSDataOutputStream fout = TEST_UTIL.getTestFileSystem().create(ncTFile);
    if (tagUsage != TagUsage.NO_TAG) {
        TEST_UTIL.getConfiguration().setInt("hfile.format.version", 3);
    }
    CacheConfig cacheConf = new CacheConfig(TEST_UTIL.getConfiguration());
    HFileContext context = new HFileContextBuilder().withBlockSize(4000).build();
    HFile.Writer writer = HFile.getWriterFactory(TEST_UTIL.getConfiguration(), cacheConf).withOutputStream(fout).withFileContext(context).withComparator(CellComparator.COMPARATOR).create();
    int numberOfKeys = 1000;
    String valueString = "Value";
    List<Integer> keyList = new ArrayList<>();
    List<String> valueList = new ArrayList<>();
    for (int key = 0; key < numberOfKeys; key++) {
        String value = valueString + key;
        KeyValue kv;
        keyList.add(key);
        valueList.add(value);
        if (tagUsage == TagUsage.NO_TAG) {
            kv = new KeyValue(Bytes.toBytes(key), Bytes.toBytes("family"), Bytes.toBytes("qual"), Bytes.toBytes(value));
            writer.append(kv);
        } else if (tagUsage == TagUsage.ONLY_TAG) {
            Tag t = new ArrayBackedTag((byte) 1, "myTag1");
            Tag[] tags = new Tag[1];
            tags[0] = t;
            kv = new KeyValue(Bytes.toBytes(key), Bytes.toBytes("family"), Bytes.toBytes("qual"), HConstants.LATEST_TIMESTAMP, Bytes.toBytes(value), tags);
            writer.append(kv);
        } else {
            if (key % 4 == 0) {
                Tag t = new ArrayBackedTag((byte) 1, "myTag1");
                Tag[] tags = new Tag[1];
                tags[0] = t;
                kv = new KeyValue(Bytes.toBytes(key), Bytes.toBytes("family"), Bytes.toBytes("qual"), HConstants.LATEST_TIMESTAMP, Bytes.toBytes(value), tags);
                writer.append(kv);
            } else {
                kv = new KeyValue(Bytes.toBytes(key), Bytes.toBytes("family"), Bytes.toBytes("qual"), HConstants.LATEST_TIMESTAMP, Bytes.toBytes(value));
                writer.append(kv);
            }
        }
    }
    writer.close();
    fout.close();
    HFile.Reader reader = HFile.createReader(TEST_UTIL.getTestFileSystem(), ncTFile, cacheConf, TEST_UTIL.getConfiguration());
    reader.loadFileInfo();
    HFileScanner scanner = reader.getScanner(false, true);
    scanner.seekTo();
    for (int i = 0; i < keyList.size(); i++) {
        Integer key = keyList.get(i);
        String value = valueList.get(i);
        long start = System.nanoTime();
        scanner.seekTo(new KeyValue(Bytes.toBytes(key), Bytes.toBytes("family"), Bytes.toBytes("qual"), Bytes.toBytes(value)));
        assertEquals(value, scanner.getValueString());
    }
    scanner.seekTo();
    for (int i = 0; i < keyList.size(); i += 10) {
        Integer key = keyList.get(i);
        String value = valueList.get(i);
        long start = System.nanoTime();
        scanner.reseekTo(new KeyValue(Bytes.toBytes(key), Bytes.toBytes("family"), Bytes.toBytes("qual"), Bytes.toBytes(value)));
        assertEquals("i is " + i, value, scanner.getValueString());
    }
    reader.close();
}
Also used : Path(org.apache.hadoop.fs.Path) KeyValue(org.apache.hadoop.hbase.KeyValue) ArrayList(java.util.ArrayList) ArrayBackedTag(org.apache.hadoop.hbase.ArrayBackedTag) FSDataOutputStream(org.apache.hadoop.fs.FSDataOutputStream) ArrayBackedTag(org.apache.hadoop.hbase.ArrayBackedTag) Tag(org.apache.hadoop.hbase.Tag)

Aggregations

ArrayBackedTag (org.apache.hadoop.hbase.ArrayBackedTag)37 KeyValue (org.apache.hadoop.hbase.KeyValue)31 Tag (org.apache.hadoop.hbase.Tag)31 ArrayList (java.util.ArrayList)23 Cell (org.apache.hadoop.hbase.Cell)14 Test (org.junit.Test)9 Put (org.apache.hadoop.hbase.client.Put)7 IOException (java.io.IOException)6 ByteBufferKeyValue (org.apache.hadoop.hbase.ByteBufferKeyValue)6 ByteArrayOutputStream (java.io.ByteArrayOutputStream)4 DataOutputStream (java.io.DataOutputStream)4 Path (org.apache.hadoop.fs.Path)4 ByteArrayInputStream (java.io.ByteArrayInputStream)3 DataInputStream (java.io.DataInputStream)3 ByteBuffer (java.nio.ByteBuffer)3 HashMap (java.util.HashMap)3 List (java.util.List)3 Random (java.util.Random)3 CountingInputStream (com.google.common.io.CountingInputStream)2 CountingOutputStream (com.google.common.io.CountingOutputStream)2