org.apache.hadoop.hbase.util.Order Java Examples
The following examples show how to use
org.apache.hadoop.hbase.util.Order.
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 File: TestTerminatedWrapper.java From hbase with Apache License 2.0 | 6 votes |
@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 #2
Source File: TestTerminatedWrapper.java From hbase with Apache License 2.0 | 6 votes |
@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 #3
Source File: TestTerminatedWrapper.java From hbase with Apache License 2.0 | 6 votes |
@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 #4
Source File: TestRawString.java From hbase with Apache License 2.0 | 6 votes |
@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 #5
Source File: TestTerminatedWrapper.java From hbase with Apache License 2.0 | 6 votes |
@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 File: TestOrderedFloat32.java From hbase with Apache License 2.0 | 5 votes |
@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 #7
Source File: TestOrderedNumeric.java From hbase with Apache License 2.0 | 5 votes |
@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 #8
Source File: TestOrderedInt8.java From hbase with Apache License 2.0 | 5 votes |
@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 #9
Source File: TestRawBytes.java From hbase with Apache License 2.0 | 5 votes |
@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 #10
Source File: TestOrderedString.java From hbase with Apache License 2.0 | 5 votes |
@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 #11
Source File: TestOrderedInt32.java From hbase with Apache License 2.0 | 5 votes |
@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 File: TestOrderedInt16.java From hbase with Apache License 2.0 | 5 votes |
@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 #13
Source File: TestOrderedInt8.java From hbase with Apache License 2.0 | 5 votes |
@Test public void testEncodeNoSupportForNull() { exception.expect(IllegalArgumentException.class); final DataType<Byte> type = new OrderedInt8(Order.ASCENDING); type.encode(new SimplePositionedMutableByteRange(20), null); }
Example #14
Source File: TestOrderedInt64.java From hbase with Apache License 2.0 | 5 votes |
@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 #15
Source File: TestOrderedFloat32.java From hbase with Apache License 2.0 | 5 votes |
@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 #16
Source File: RawString.java From hbase with Apache License 2.0 | 5 votes |
@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 #17
Source File: TestOrderedInt32.java From hbase with Apache License 2.0 | 5 votes |
@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 #18
Source File: TestOrderedBlobVar.java From hbase with Apache License 2.0 | 5 votes |
@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 #19
Source File: TestOrderedNumeric.java From hbase with Apache License 2.0 | 5 votes |
@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 #20
Source File: TestOrderedFloat64.java From hbase with Apache License 2.0 | 5 votes |
@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 #21
Source File: TestOrderedInt16.java From hbase with Apache License 2.0 | 5 votes |
@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 #22
Source File: TestOrderedFloat64.java From hbase with Apache License 2.0 | 5 votes |
@Test public void testEncodeNoSupportForNull() { exception.expect(IllegalArgumentException.class); final DataType<Double> type = new OrderedFloat64(Order.ASCENDING); type.encode(new SimplePositionedMutableByteRange(20), null); }
Example #23
Source File: TestOrderedBlob.java From hbase with Apache License 2.0 | 5 votes |
@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 #24
Source File: RawShort.java From hbase with Apache License 2.0 | 4 votes |
@Override public Order getOrder() { return null; }
Example #25
Source File: RawBytes.java From hbase with Apache License 2.0 | 4 votes |
@Override public Order getOrder() { return order; }
Example #26
Source File: TestOrderedInt16.java From hbase with Apache License 2.0 | 4 votes |
@Test public void testEncodedClassIsShort() { final DataType<Short> type = new OrderedInt16(Order.ASCENDING); assertEquals(Short.class, type.encodedClass()); }
Example #27
Source File: TestStructNullExtension.java From hbase with Apache License 2.0 | 4 votes |
/** * Positive cases for null extension. */ @Test public void testNullableNullExtension() { // the following field members are used because they're all nullable final StructBuilder builder = new StructBuilder() .add(new OrderedNumeric(Order.ASCENDING)) .add(new OrderedString(Order.ASCENDING)); Struct shorter = builder.toStruct(); final Struct longer = builder // intentionally include a wrapped instance to test wrapper behavior. .add(new TerminatedWrapper<>(new OrderedString(Order.ASCENDING), "/")) .add(new OrderedNumeric(Order.ASCENDING)) .toStruct(); PositionedByteRange buf1 = new SimplePositionedMutableByteRange(7); Object[] val1 = new Object[] { BigDecimal.ONE, "foo" }; // => 2 bytes + 5 bytes assertEquals("Encoding shorter value wrote a surprising number of bytes.", buf1.getLength(), shorter.encode(buf1, val1)); int shortLen = buf1.getLength(); // test iterator buf1.setPosition(0); StructIterator it = longer.iterator(buf1); it.skip(); it.skip(); assertEquals("Position should be at end. Broken test.", buf1.getLength(), buf1.getPosition()); assertEquals("Failed to skip null element with extended struct.", 0, it.skip()); assertEquals("Failed to skip null element with extended struct.", 0, it.skip()); buf1.setPosition(0); it = longer.iterator(buf1); assertEquals(BigDecimal.ONE, it.next()); assertEquals("foo", it.next()); assertEquals("Position should be at end. Broken test.", buf1.getLength(), buf1.getPosition()); assertNull("Failed to skip null element with extended struct.", it.next()); assertNull("Failed to skip null element with extended struct.", it.next()); // test Struct buf1.setPosition(0); assertArrayEquals("Simple struct decoding is broken.", val1, shorter.decode(buf1)); buf1.setPosition(0); assertArrayEquals("Decoding short value with extended struct should append null elements.", Arrays.copyOf(val1, 4), longer.decode(buf1)); // test omission of trailing members PositionedByteRange buf2 = new SimplePositionedMutableByteRange(7); buf1.setPosition(0); assertEquals( "Encoding a short value with extended struct should have same result as using short struct.", shortLen, longer.encode(buf2, val1)); assertArrayEquals( "Encoding a short value with extended struct should have same result as using short struct", buf1.getBytes(), buf2.getBytes()); // test null trailing members // all fields are nullable, so nothing should hit the buffer. val1 = new Object[] { null, null, null, null }; // => 0 bytes buf1.set(0); buf2.set(0); assertEquals("Encoding null-truncated value wrote a surprising number of bytes.", buf1.getLength(), longer.encode(buf1, new Object[0])); assertEquals("Encoding null-extended value wrote a surprising number of bytes.", buf1.getLength(), longer.encode(buf1, val1)); assertArrayEquals("Encoded unexpected result.", buf1.getBytes(), buf2.getBytes()); assertArrayEquals("Decoded unexpected result.", val1, longer.decode(buf2)); // all fields are nullable, so only 1 should hit the buffer. Object[] val2 = new Object[] { BigDecimal.ONE, null, null, null }; // => 2 bytes buf1.set(2); buf2.set(2); assertEquals("Encoding null-truncated value wrote a surprising number of bytes.", buf1.getLength(), longer.encode(buf1, Arrays.copyOf(val2, 1))); assertEquals("Encoding null-extended value wrote a surprising number of bytes.", buf2.getLength(), longer.encode(buf2, val2)); assertArrayEquals("Encoded unexpected result.", buf1.getBytes(), buf2.getBytes()); buf2.setPosition(0); assertArrayEquals("Decoded unexpected result.", val2, longer.decode(buf2)); // all fields are nullable, so only 1, null, "foo" should hit the buffer. // => 2 bytes + 1 byte + 6 bytes Object[] val3 = new Object[] { BigDecimal.ONE, null, "foo", null }; buf1.set(9); buf2.set(9); assertEquals("Encoding null-truncated value wrote a surprising number of bytes.", buf1.getLength(), longer.encode(buf1, Arrays.copyOf(val3, 3))); assertEquals("Encoding null-extended value wrote a surprising number of bytes.", buf2.getLength(), longer.encode(buf2, val3)); assertArrayEquals("Encoded unexpected result.", buf1.getBytes(), buf2.getBytes()); buf2.setPosition(0); assertArrayEquals("Decoded unexpected result.", val3, longer.decode(buf2)); }
Example #28
Source File: TestRawString.java From hbase with Apache License 2.0 | 4 votes |
@Test public void testIsSkippableIsFalse() { final DataType<String> type = new RawString(Order.ASCENDING); assertFalse(type.isSkippable()); }
Example #29
Source File: TerminatedWrapper.java From hbase with Apache License 2.0 | 4 votes |
@Override public Order getOrder() { return wrapped.getOrder(); }
Example #30
Source File: PUnsignedLong.java From phoenix with Apache License 2.0 | 4 votes |
@Override public Order getOrder() { return Order.ASCENDING; }