@Test
 public void testEncodedLength() {
   PositionedByteRange buff = new SimplePositionedMutableByteRange(20);
   for (DataType<byte[]> type :
       new OrderedBlobVar[] {OrderedBlobVar.ASCENDING, OrderedBlobVar.DESCENDING}) {
     for (byte[] val : VALUES) {
       buff.setPosition(0);
       type.encode(buff, val);
       assertEquals(
           "encodedLength does not match actual, " + Bytes.toStringBinary(val),
           buff.getPosition(),
           type.encodedLength(val));
     }
   }
 }
 @Test
 public void testEncodedLength() {
   PositionedByteRange buff = new SimplePositionedMutableByteRange(20);
   for (DataType<String> type :
       new OrderedString[] {OrderedString.ASCENDING, OrderedString.DESCENDING}) {
     for (String val : VALUES) {
       buff.setPosition(0);
       type.encode(buff, val);
       assertEquals(
           "encodedLength does not match actual, " + val,
           buff.getPosition(),
           type.encodedLength(val));
     }
   }
 }
 @Override
 public void eval() {
   org.apache.drill.exec.util.ByteBufUtil.checkBufferLength(in.buffer, in.start, in.end, 5);
   in.buffer.getBytes(in.start, bytes, 0, 5);
   br.set(bytes);
   out.value = org.apache.hadoop.hbase.util.OrderedBytes.decodeFloat32(br);
 }
 @Override
 public int encode(PositionedByteRange dst, T val) {
   if (dst.getRemaining() < length) {
     throw new IllegalArgumentException(
         "Not enough buffer remaining. dst.offset: "
             + dst.getOffset()
             + " dst.length: "
             + dst.getLength()
             + " dst.position: "
             + dst.getPosition()
             + " max length: "
             + length);
   }
   int written = base.encode(dst, val);
   if (written > length) {
     throw new IllegalArgumentException(
         "Length of encoded value (" + written + ") exceeds max length (" + length + ").");
   }
   // TODO: is the zero-padding appropriate?
   for (; written < length; written++) {
     dst.put((byte) 0x00);
   }
   return written;
 }
Exemple #5
0
 @Test
 public void testReadWrite() {
   for (Order ord : new Order[] {Order.ASCENDING, Order.DESCENDING}) {
     RawString type = Order.ASCENDING == ord ? RawString.ASCENDING : RawString.DESCENDING;
     for (String val : VALUES) {
       PositionedByteRange buff = new SimplePositionedByteRange(Bytes.toBytes(val).length);
       assertEquals(buff.getLength(), type.encode(buff, val));
       byte[] expected = Bytes.toBytes(val);
       ord.apply(expected);
       assertArrayEquals(expected, buff.getBytes());
       buff.setPosition(0);
       assertEquals(val, type.decode(buff));
       buff.setPosition(0);
       assertEquals(buff.getLength(), type.skip(buff));
       assertEquals(buff.getLength(), buff.getPosition());
     }
   }
 }
 @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 SimplePositionedByteRange(length);
   src.get(b.getBytes());
   return base.decode(b);
 }
Exemple #7
0
 @Override
 public int encode(PositionedByteRange dst, Double val) {
   Bytes.putDouble(dst.getBytes(), dst.getOffset() + dst.getPosition(), val);
   return skip(dst);
 }
Exemple #8
0
 @Override
 public Double decode(PositionedByteRange src) {
   double val = Bytes.toDouble(src.getBytes(), src.getOffset() + src.getPosition());
   skip(src);
   return val;
 }
Exemple #9
0
 @Override
 public int skip(PositionedByteRange src) {
   src.setPosition(src.getPosition() + Bytes.SIZEOF_DOUBLE);
   return Bytes.SIZEOF_DOUBLE;
 }
Exemple #10
0
 @Override
 public int skip(PositionedByteRange src) {
   src.setPosition(src.getPosition() + this.length);
   return this.length;
 }