Java Code Examples for org.apache.hadoop.hbase.util.Order

The following examples show how to use org.apache.hadoop.hbase.util.Order. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: hbase   Source File: TestRawString.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testReadWrite() {
  for (final Order ord : new Order[] { Order.ASCENDING, Order.DESCENDING }) {
    final RawString type =
        Order.ASCENDING == ord ? new RawString(Order.ASCENDING) : new RawString(Order.DESCENDING);
    for (final String val : VALUES) {
      final PositionedByteRange buff =
          new SimplePositionedMutableByteRange(Bytes.toBytes(val).length);
      assertEquals(buff.getLength(), type.encode(buff, val));
      final 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());
    }
  }
}
 
Example 2
Source Project: hbase   Source File: TestTerminatedWrapper.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testReadWriteNonSkippable() {
  PositionedByteRange buff = new SimplePositionedMutableByteRange(12);
  for (Order ord : new Order[] { Order.ASCENDING, Order.DESCENDING }) {
    for (byte[] term : TERMINATORS) {
      for (byte[] val : VALUES_BYTES) {
        buff.setPosition(0);
        DataType<byte[]> type = new TerminatedWrapper<>(new RawBytes(ord), term);
        assertEquals(val.length + term.length, type.encode(buff, val));
        buff.setPosition(0);
        assertArrayEquals(val, type.decode(buff));
        assertEquals(val.length + term.length, buff.getPosition());
      }
    }
  }
}
 
Example 3
Source Project: hbase   Source File: TestTerminatedWrapper.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testSkipNonSkippable() {
  PositionedByteRange buff = new SimplePositionedMutableByteRange(12);
  for (Order ord : new Order[] { Order.ASCENDING, Order.DESCENDING }) {
    for (byte[] term : TERMINATORS) {
      for (byte[] val : VALUES_BYTES) {
        buff.setPosition(0);
        DataType<byte[]> type = new TerminatedWrapper<>(new RawBytes(ord), term);
        int expected = type.encode(buff, val);
        buff.setPosition(0);
        assertEquals(expected, type.skip(buff));
        assertEquals(expected, buff.getPosition());
      }
    }
  }
}
 
Example 4
Source Project: hbase   Source File: TestTerminatedWrapper.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testReadWriteSkippable() {
  final PositionedByteRange buff = new SimplePositionedMutableByteRange(14);
  for (final OrderedString t : new OrderedString[] {
    new OrderedString(Order.ASCENDING), new OrderedString(Order.DESCENDING)
  }) {
    for (final byte[] term : TERMINATORS) {
      for (final String val : VALUES_STRINGS) {
        buff.setPosition(0);
        final DataType<String> type = new TerminatedWrapper<>(t, term);
        assertEquals(val.length() + 2 + term.length, type.encode(buff, val));
        buff.setPosition(0);
        assertEquals(val, type.decode(buff));
        assertEquals(val.length() + 2 + term.length, buff.getPosition());
      }
    }
  }
}
 
Example 5
Source Project: hbase   Source File: TestTerminatedWrapper.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testSkipSkippable() {
  final PositionedByteRange buff = new SimplePositionedMutableByteRange(14);
  for (final OrderedString t : new OrderedString[] {
    new OrderedString(Order.ASCENDING), new OrderedString(Order.DESCENDING)
  }) {
    for (final byte[] term : TERMINATORS) {
      for (final String val : VALUES_STRINGS) {
        buff.setPosition(0);
        final DataType<String> type = new TerminatedWrapper<>(t, term);
        final int expected = val.length() + 2 + term.length;
        assertEquals(expected, type.encode(buff, val));
        buff.setPosition(0);
        assertEquals(expected, type.skip(buff));
        assertEquals(expected, buff.getPosition());
      }
    }
  }
}
 
Example 6
Source Project: hbase   Source File: TestOrderedInt8.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void testEncodedLength() {
  final PositionedByteRange buffer = new SimplePositionedMutableByteRange(20);
  for (final DataType<Byte> type : new OrderedInt8[] { new OrderedInt8(Order.ASCENDING),
    new OrderedInt8(Order.DESCENDING) }) {
    for (final Byte val : VALUES) {
      buffer.setPosition(0);
      type.encode(buffer, val);
      assertEquals("encodedLength does not match actual, " + val,
          buffer.getPosition(), type.encodedLength(val));
    }
  }
}
 
Example 7
Source Project: hbase   Source File: TestOrderedNumeric.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void testEncodedLongLength() {
  final PositionedByteRange buffer = new SimplePositionedMutableByteRange(20);
  for (final OrderedNumeric type : new OrderedNumeric[] { new OrderedNumeric(Order.ASCENDING),
    new OrderedNumeric(Order.DESCENDING) }) {
    for (final Long val : LONG_VALUES) {
      buffer.setPosition(0);
      type.encodeLong(buffer, val);
      assertEquals("encodedLength does not match actual, " + val,
          buffer.getPosition(), type.encodedLength(val));
    }
  }
}
 
Example 8
Source Project: hbase   Source File: TestOrderedInt32.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void testEncodedLength() {
  final PositionedByteRange buffer = new SimplePositionedMutableByteRange(20);
  for (final DataType<Integer> type : new OrderedInt32[] { new OrderedInt32(Order.ASCENDING),
    new OrderedInt32(Order.DESCENDING) }) {
    for (final Integer val : VALUES) {
      buffer.setPosition(0);
      type.encode(buffer, val);
      assertEquals(
          "encodedLength does not match actual, " + val,
          buffer.getPosition(), type.encodedLength(val));
    }
  }
}
 
Example 9
Source Project: hbase   Source File: TestOrderedNumeric.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void testEncodedBigIntegerLength() {
  final PositionedByteRange buffer = new SimplePositionedMutableByteRange(20);
  for (final DataType<Number> type : new OrderedNumeric[] { new OrderedNumeric(Order.ASCENDING),
    new OrderedNumeric(Order.DESCENDING) }) {
    for (final Number val : BIG_INTEGER_VALUES) {
      buffer.setPosition(0);
      type.encode(buffer, val);
      assertEquals("encodedLength does not match actual, " + val,
          buffer.getPosition(), type.encodedLength(val));
    }
  }
}
 
Example 10
Source Project: hbase   Source File: RawString.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public String decode(PositionedByteRange src) {
  if (Order.ASCENDING == this.order) {
    // avoid unnecessary array copy for ASC case.
    String val =
        Bytes.toString(src.getBytes(), src.getOffset() + src.getPosition(), src.getRemaining());
    src.setPosition(src.getLength());
    return val;
  } else {
    byte[] b = new byte[src.getRemaining()];
    src.get(b);
    order.apply(b, 0, b.length);
    return Bytes.toString(b);
  }
}
 
Example 11
Source Project: hbase   Source File: TestOrderedInt32.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void testEncodedFloatLength() {
  final PositionedByteRange buffer = new SimplePositionedMutableByteRange(20);
  for (final OrderedInt32 type : new OrderedInt32[] { new OrderedInt32(Order.ASCENDING),
    new OrderedInt32(Order.DESCENDING) }) {
    for (final Integer val : VALUES) {
      buffer.setPosition(0);
      type.encodeInt(buffer, val);
      assertEquals("encodedLength does not match actual, " + val,
          buffer.getPosition(), type.encodedLength(val));
    }
  }
}
 
Example 12
Source Project: hbase   Source File: TestOrderedInt8.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void testEncodeNoSupportForNull() {
  exception.expect(IllegalArgumentException.class);

  final DataType<Byte> type = new OrderedInt8(Order.ASCENDING);

  type.encode(new SimplePositionedMutableByteRange(20), null);
}
 
Example 13
Source Project: hbase   Source File: TestOrderedBlob.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void testEncodedLength() {
  PositionedByteRange buff = new SimplePositionedMutableByteRange(20);
  for (final DataType<byte[]> type : new OrderedBlob[] { new OrderedBlob(Order.ASCENDING),
    new OrderedBlob(Order.DESCENDING) }) {
    for (final byte[] val : VALUES) {
      buff.setPosition(0);
      type.encode(buff, val);
      assertEquals("encodedLength does not match actual, " + Bytes.toStringBinary(val),
        buff.getPosition(), type.encodedLength(val));
    }
  }
}
 
Example 14
Source Project: hbase   Source File: TestOrderedFloat64.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void testEncodedLength() {
  final PositionedByteRange buffer = new SimplePositionedMutableByteRange(20);
  for (final DataType<Double> type : new OrderedFloat64[] { new OrderedFloat64(Order.ASCENDING),
    new OrderedFloat64(Order.DESCENDING) }) {
    for (final Double val : VALUES) {
      buffer.setPosition(0);
      type.encode(buffer, val);
      assertEquals("encodedLength does not match actual, " + val,
          buffer.getPosition(), type.encodedLength(val));
    }
  }
}
 
Example 15
Source Project: hbase   Source File: TestOrderedFloat64.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void testEncodeNoSupportForNull() {
  exception.expect(IllegalArgumentException.class);

  final DataType<Double> type = new OrderedFloat64(Order.ASCENDING);

  type.encode(new SimplePositionedMutableByteRange(20), null);
}
 
Example 16
Source Project: hbase   Source File: TestOrderedInt16.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void testEncodedFloatLength() {
  final PositionedByteRange buffer = new SimplePositionedMutableByteRange(20);
  for (final OrderedInt16 type : new OrderedInt16[] { new OrderedInt16(Order.ASCENDING),
    new OrderedInt16(Order.DESCENDING) }) {
    for (final Short val : VALUES) {
      buffer.setPosition(0);
      type.encodeShort(buffer, val);
      assertEquals("encodedLength does not match actual, " + val,
          buffer.getPosition(), type.encodedLength(val));
    }
  }
}
 
Example 17
Source Project: hbase   Source File: TestOrderedBlobVar.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void testEncodedLength() {
  final PositionedByteRange buff = new SimplePositionedMutableByteRange(20);
  for (final DataType<byte[]> type :
    new OrderedBlobVar[] { new OrderedBlobVar(Order.ASCENDING),
      new OrderedBlobVar(Order.DESCENDING) }) {
    for (final byte[] val : VALUES) {
      buff.setPosition(0);
      type.encode(buff, val);
      assertEquals("encodedLength does not match actual, " + Bytes.toStringBinary(val),
        buff.getPosition(), type.encodedLength(val));
    }
  }
}
 
Example 18
Source Project: hbase   Source File: TestOrderedFloat32.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void testEncodedLength() {
  final PositionedByteRange buffer = new SimplePositionedMutableByteRange(20);
  for (final DataType<Float> type : new OrderedFloat32[] { new OrderedFloat32(Order.ASCENDING),
    new OrderedFloat32(Order.DESCENDING) }) {
    for (final Float val : VALUES) {
      buffer.setPosition(0);
      type.encode(buffer, val);
      assertEquals("encodedLength does not match actual, " + val,
          buffer.getPosition(), type.encodedLength(val));
    }
  }
}
 
Example 19
Source Project: hbase   Source File: TestOrderedInt64.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void testEncodedFloatLength() {
  final PositionedByteRange buffer = new SimplePositionedMutableByteRange(20);
  for (final OrderedInt64 type : new OrderedInt64[] { new OrderedInt64(Order.ASCENDING),
    new OrderedInt64(Order.DESCENDING) }) {
    for (final Long val : VALUES) {
      buffer.setPosition(0);
      type.encodeLong(buffer, val);
      assertEquals("encodedLength does not match actual, " + val,
          buffer.getPosition(), type.encodedLength(val));
    }
  }
}
 
Example 20
Source Project: hbase   Source File: TestOrderedFloat32.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void testEncodedFloatLength() {
  final PositionedByteRange buffer = new SimplePositionedMutableByteRange(20);
  for (final OrderedFloat32 type : new OrderedFloat32[] { new OrderedFloat32(Order.ASCENDING),
    new OrderedFloat32(Order.DESCENDING) }) {
    for (final Float val : VALUES) {
      buffer.setPosition(0);
      type.encodeFloat(buffer, val);
      assertEquals("encodedLength does not match actual, " + val,
          buffer.getPosition(), type.encodedLength(val));
    }
  }
}
 
Example 21
Source Project: hbase   Source File: TestRawBytes.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void testEncodedLength() {
  final PositionedByteRange buffer = new SimplePositionedMutableByteRange(20);
  for (final DataType<byte[]> type : new RawBytes[] { new RawBytes(Order.ASCENDING),
    new RawBytes(Order.DESCENDING) }) {
    for (final byte[] val : VALUES) {
      buffer.setPosition(0);
      type.encode(buffer, val);
      assertEquals("encodedLength does not match actual, " + Arrays.toString(val),
          buffer.getPosition(), type.encodedLength(val));
    }
  }
}
 
Example 22
Source Project: hbase   Source File: TestOrderedString.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void testEncodedLength() {
  PositionedByteRange buff = new SimplePositionedMutableByteRange(20);
  for (final DataType<String> type : new OrderedString[] { new OrderedString(Order.ASCENDING),
    new OrderedString(Order.DESCENDING) }) {
    for (final String val : VALUES) {
      buff.setPosition(0);
      type.encode(buff, val);
      assertEquals("encodedLength does not match actual, " + val,
        buff.getPosition(), type.encodedLength(val));
    }
  }
}
 
Example 23
Source Project: hbase   Source File: TestOrderedInt16.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void testEncodedLength() {
  final PositionedByteRange buffer = new SimplePositionedMutableByteRange(20);
  for (final DataType<Short> type : new OrderedInt16[] { new OrderedInt16(Order.ASCENDING),
    new OrderedInt16(Order.DESCENDING) }) {
    for (final Short val : VALUES) {
      buffer.setPosition(0);
      type.encode(buffer, val);
      assertEquals("encodedLength does not match actual, " + val,
          buffer.getPosition(), type.encodedLength(val));
    }
  }
}
 
Example 24
Source Project: hbase   Source File: TestTerminatedWrapper.java    License: Apache License 2.0 4 votes vote down vote up
@Test(expected = IllegalArgumentException.class)
public void testEncodedValueContainsTerm() {
  final DataType<byte[]> type = new TerminatedWrapper<>(new RawBytes(Order.ASCENDING), "foo");
  final PositionedByteRange buff = new SimplePositionedMutableByteRange(16);
  type.encode(buff, Bytes.toBytes("hello foobar!"));
}
 
Example 25
Source Project: phoenix   Source File: PUnsignedLong.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public Order getOrder() {
  return Order.ASCENDING;
}
 
Example 26
Source Project: phoenix   Source File: PUnsignedInt.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public Order getOrder() {
  return Order.ASCENDING;
}
 
Example 27
Source Project: hbase   Source File: RawDouble.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public Order getOrder() {
  return null;
}
 
Example 28
Source Project: hbase   Source File: RawBytesFixedLength.java    License: Apache License 2.0 4 votes vote down vote up
/**
 * Create a {@code RawBytesFixedLength} of the specified {@code length}.
 */
public RawBytesFixedLength(int length) {
  super(new RawBytes(Order.ASCENDING), length);
}
 
Example 29
Source Project: hbase   Source File: Union4.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public Order getOrder() {
  return null;
}
 
Example 30
Source Project: hbase   Source File: FixedLengthWrapper.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public Order getOrder() {
  return base.getOrder();
}