Search in sources :

Example 16 with PositionedByteRange

use of org.apache.hadoop.hbase.util.PositionedByteRange in project hbase by apache.

the class TestUnion2 method testEncodeDecode.

@Test
public void testEncodeDecode() {
    Integer intVal = Integer.valueOf(10);
    String strVal = "hello";
    PositionedByteRange buff = new SimplePositionedMutableByteRange(10);
    SampleUnion1 type = new SampleUnion1();
    type.encode(buff, intVal);
    buff.setPosition(0);
    assertTrue(0 == intVal.compareTo(type.decodeA(buff)));
    buff.setPosition(0);
    type.encode(buff, strVal);
    buff.setPosition(0);
    assertTrue(0 == strVal.compareTo(type.decodeB(buff)));
}
Also used : SimplePositionedMutableByteRange(org.apache.hadoop.hbase.util.SimplePositionedMutableByteRange) PositionedByteRange(org.apache.hadoop.hbase.util.PositionedByteRange) Test(org.junit.Test)

Example 17 with PositionedByteRange

use of org.apache.hadoop.hbase.util.PositionedByteRange in project hbase by apache.

the class FixedLengthWrapper method decode.

@Override
public T decode(PositionedByteRange src) {
    if (src.getRemaining() < length) {
        throw new IllegalArgumentException("Not enough buffer remaining. src.offset: " + src.getOffset() + " src.length: " + src.getLength() + " src.position: " + src.getPosition() + " max length: " + length);
    }
    // create a copy range limited to length bytes. boo.
    PositionedByteRange b = new SimplePositionedMutableByteRange(length);
    src.get(b.getBytes());
    return base.decode(b);
}
Also used : SimplePositionedMutableByteRange(org.apache.hadoop.hbase.util.SimplePositionedMutableByteRange) PositionedByteRange(org.apache.hadoop.hbase.util.PositionedByteRange)

Example 18 with PositionedByteRange

use of org.apache.hadoop.hbase.util.PositionedByteRange in project hbase by apache.

the class TestFixedLengthWrapper method testInsufficientRemainingWrite.

@Test(expected = IllegalArgumentException.class)
public void testInsufficientRemainingWrite() {
    PositionedByteRange buff = new SimplePositionedMutableByteRange(0);
    DataType<byte[]> type = new FixedLengthWrapper<>(new RawBytes(), 3);
    type.encode(buff, Bytes.toBytes(""));
}
Also used : SimplePositionedMutableByteRange(org.apache.hadoop.hbase.util.SimplePositionedMutableByteRange) PositionedByteRange(org.apache.hadoop.hbase.util.PositionedByteRange) Test(org.junit.Test)

Example 19 with PositionedByteRange

use of org.apache.hadoop.hbase.util.PositionedByteRange in project hbase by apache.

the class TestFixedLengthWrapper method testReadWrite.

@Test
public void testReadWrite() {
    for (int limit : limits) {
        PositionedByteRange buff = new SimplePositionedMutableByteRange(limit);
        for (Order ord : new Order[] { Order.ASCENDING, Order.DESCENDING }) {
            for (byte[] val : VALUES) {
                buff.setPosition(0);
                DataType<byte[]> type = new FixedLengthWrapper<>(new RawBytes(ord), limit);
                assertEquals(limit, type.encode(buff, val));
                buff.setPosition(0);
                byte[] actual = type.decode(buff);
                assertTrue("Decoding output differs from expected", Bytes.equals(val, 0, val.length, actual, 0, val.length));
                buff.setPosition(0);
                assertEquals(limit, type.skip(buff));
            }
        }
    }
}
Also used : Order(org.apache.hadoop.hbase.util.Order) SimplePositionedMutableByteRange(org.apache.hadoop.hbase.util.SimplePositionedMutableByteRange) PositionedByteRange(org.apache.hadoop.hbase.util.PositionedByteRange) Test(org.junit.Test)

Example 20 with PositionedByteRange

use of org.apache.hadoop.hbase.util.PositionedByteRange in project hbase by apache.

the class TestFixedLengthWrapper method testInsufficientRemainingRead.

@Test(expected = IllegalArgumentException.class)
public void testInsufficientRemainingRead() {
    PositionedByteRange buff = new SimplePositionedMutableByteRange(0);
    DataType<byte[]> type = new FixedLengthWrapper<>(new RawBytes(), 3);
    type.decode(buff);
}
Also used : SimplePositionedMutableByteRange(org.apache.hadoop.hbase.util.SimplePositionedMutableByteRange) PositionedByteRange(org.apache.hadoop.hbase.util.PositionedByteRange) Test(org.junit.Test)

Aggregations

PositionedByteRange (org.apache.hadoop.hbase.util.PositionedByteRange)32 SimplePositionedMutableByteRange (org.apache.hadoop.hbase.util.SimplePositionedMutableByteRange)30 Test (org.junit.Test)20 HColumnDescriptor (org.apache.hadoop.hbase.HColumnDescriptor)8 HTableDescriptor (org.apache.hadoop.hbase.HTableDescriptor)8 BufferedMutator (org.apache.hadoop.hbase.client.BufferedMutator)8 Put (org.apache.hadoop.hbase.client.Put)8 Order (org.apache.hadoop.hbase.util.Order)4 ByteBuf (io.netty.buffer.ByteBuf)2 FunctionCall (org.apache.drill.common.expression.FunctionCall)2 LogicalExpression (org.apache.drill.common.expression.LogicalExpression)2 SchemaPath (org.apache.drill.common.expression.SchemaPath)2 BooleanExpression (org.apache.drill.common.expression.ValueExpressions.BooleanExpression)2 DateExpression (org.apache.drill.common.expression.ValueExpressions.DateExpression)2 DoubleExpression (org.apache.drill.common.expression.ValueExpressions.DoubleExpression)2 FloatExpression (org.apache.drill.common.expression.ValueExpressions.FloatExpression)2 IntExpression (org.apache.drill.common.expression.ValueExpressions.IntExpression)2 LongExpression (org.apache.drill.common.expression.ValueExpressions.LongExpression)2 QuotedString (org.apache.drill.common.expression.ValueExpressions.QuotedString)2 TimeExpression (org.apache.drill.common.expression.ValueExpressions.TimeExpression)2