You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hbase.apache.org by ja...@apache.org on 2019/06/24 20:32:26 UTC
[hbase] branch master updated: HBASE-16002 Made constructors of
DataType subclasses public
This is an automated email from the ASF dual-hosted git repository.
janh pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/hbase.git
The following commit(s) were added to refs/heads/master by this push:
new 10032a1 HBASE-16002 Made constructors of DataType subclasses public
10032a1 is described below
commit 10032a11ba89bb2d7d85637274824744bd670f45
Author: Jan Hentschel <ja...@ultratendency.com>
AuthorDate: Mon Jun 24 22:32:18 2019 +0200
HBASE-16002 Made constructors of DataType subclasses public
Signed-off-by: stack <st...@apache.org>
---
.../org/apache/hadoop/hbase/types/OrderedBlob.java | 21 ++-
.../apache/hadoop/hbase/types/OrderedBlobVar.java | 19 ++-
.../hadoop/hbase/types/OrderedBytesBase.java | 2 +-
.../apache/hadoop/hbase/types/OrderedFloat32.java | 23 ++-
.../apache/hadoop/hbase/types/OrderedFloat64.java | 23 ++-
.../apache/hadoop/hbase/types/OrderedInt16.java | 23 ++-
.../apache/hadoop/hbase/types/OrderedInt32.java | 23 ++-
.../apache/hadoop/hbase/types/OrderedInt64.java | 23 ++-
.../org/apache/hadoop/hbase/types/OrderedInt8.java | 23 ++-
.../apache/hadoop/hbase/types/OrderedNumeric.java | 30 +++-
.../apache/hadoop/hbase/types/OrderedString.java | 16 ++-
.../org/apache/hadoop/hbase/types/RawBytes.java | 33 ++++-
.../hadoop/hbase/types/RawBytesFixedLength.java | 2 +-
.../hadoop/hbase/types/RawBytesTerminated.java | 4 +-
.../org/apache/hadoop/hbase/types/RawString.java | 23 ++-
.../hadoop/hbase/types/RawStringFixedLength.java | 2 +-
.../hadoop/hbase/types/RawStringTerminated.java | 4 +-
.../hadoop/hbase/types/TestFixedLengthWrapper.java | 12 +-
.../apache/hadoop/hbase/types/TestOrderedBlob.java | 27 +++-
.../hadoop/hbase/types/TestOrderedBlobVar.java | 23 +--
.../hadoop/hbase/types/TestOrderedFloat32.java | 98 +++++++++++++
.../hadoop/hbase/types/TestOrderedFloat64.java | 98 +++++++++++++
.../hadoop/hbase/types/TestOrderedInt16.java | 98 +++++++++++++
.../hadoop/hbase/types/TestOrderedInt32.java | 99 +++++++++++++
.../hadoop/hbase/types/TestOrderedInt64.java | 98 +++++++++++++
.../apache/hadoop/hbase/types/TestOrderedInt8.java | 98 +++++++++++++
.../hadoop/hbase/types/TestOrderedNumeric.java | 154 +++++++++++++++++++++
.../hadoop/hbase/types/TestOrderedString.java | 21 ++-
.../apache/hadoop/hbase/types/TestRawBytes.java | 101 ++++++++++++++
.../apache/hadoop/hbase/types/TestRawString.java | 53 +++++--
.../org/apache/hadoop/hbase/types/TestStruct.java | 2 +-
.../hbase/types/TestStructNullExtension.java | 13 +-
.../hadoop/hbase/types/TestTerminatedWrapper.java | 37 ++---
33 files changed, 1232 insertions(+), 94 deletions(-)
diff --git a/hbase-common/src/main/java/org/apache/hadoop/hbase/types/OrderedBlob.java b/hbase-common/src/main/java/org/apache/hadoop/hbase/types/OrderedBlob.java
index cdb1173..5e28dcd 100644
--- a/hbase-common/src/main/java/org/apache/hadoop/hbase/types/OrderedBlob.java
+++ b/hbase-common/src/main/java/org/apache/hadoop/hbase/types/OrderedBlob.java
@@ -29,10 +29,23 @@ import org.apache.yetus.audience.InterfaceAudience;
@InterfaceAudience.Public
public class OrderedBlob extends OrderedBytesBase<byte[]> {
+ /**
+ * @deprecated since 3.0.0 and will be removed in 4.0.0
+ */
+ @Deprecated
public static final OrderedBlob ASCENDING = new OrderedBlob(Order.ASCENDING);
+ /**
+ * @deprecated since 3.0.0 and will b removed in 4.0.0
+ */
+ @Deprecated
public static final OrderedBlob DESCENDING = new OrderedBlob(Order.DESCENDING);
- protected OrderedBlob(Order order) {
+ /**
+ * Creates a new {@code byte[]} with variable length.
+ *
+ * @param order the {@link Order} to use
+ */
+ public OrderedBlob(Order order) {
super(order);
}
@@ -65,6 +78,12 @@ public class OrderedBlob extends OrderedBytesBase<byte[]> {
/**
* Write a subset of {@code val} to {@code dst}.
+ *
+ * @param dst the {@link PositionedByteRange} to write to
+ * @param val the value to write to {@code dst}
+ * @param voff the offset in {@code dst} where to write {@code val} to
+ * @param vlen the lenght of {@code val}
+ * @return the number of bytes written
*/
public int encode(PositionedByteRange dst, byte[] val, int voff, int vlen) {
return OrderedBytes.encodeBlobCopy(dst, val, voff, vlen, order);
diff --git a/hbase-common/src/main/java/org/apache/hadoop/hbase/types/OrderedBlobVar.java b/hbase-common/src/main/java/org/apache/hadoop/hbase/types/OrderedBlobVar.java
index 44621bf..b2bbf75 100644
--- a/hbase-common/src/main/java/org/apache/hadoop/hbase/types/OrderedBlobVar.java
+++ b/hbase-common/src/main/java/org/apache/hadoop/hbase/types/OrderedBlobVar.java
@@ -29,11 +29,18 @@ import org.apache.yetus.audience.InterfaceAudience;
*/
@InterfaceAudience.Public
public class OrderedBlobVar extends OrderedBytesBase<byte[]> {
-
+ /**
+ * @deprecated since 3.0.0 and will be removed in 4.0.0
+ */
+ @Deprecated
public static final OrderedBlobVar ASCENDING = new OrderedBlobVar(Order.ASCENDING);
+ /**
+ * @deprecated since 3.0.0 and will be removed in 4.0.0
+ */
+ @Deprecated
public static final OrderedBlobVar DESCENDING = new OrderedBlobVar(Order.DESCENDING);
- protected OrderedBlobVar(Order order) {
+ public OrderedBlobVar(Order order) {
super(order);
}
@@ -58,7 +65,13 @@ public class OrderedBlobVar extends OrderedBytesBase<byte[]> {
}
/**
- * Write a subset of {@code val} to {@code buff}.
+ * Write a subset of {@code val} to {@code dst}.
+ *
+ * @param dst the {@link PositionedByteRange} to write to
+ * @param val the value to write to {@code dst}
+ * @param voff the offset in {@code dst} where to write {@code val} to
+ * @param vlen the lenght of {@code val}
+ * @return the number of bytes written
*/
public int encode(PositionedByteRange dst, byte[] val, int voff, int vlen) {
return OrderedBytes.encodeBlobVar(dst, val, voff, vlen, order);
diff --git a/hbase-common/src/main/java/org/apache/hadoop/hbase/types/OrderedBytesBase.java b/hbase-common/src/main/java/org/apache/hadoop/hbase/types/OrderedBytesBase.java
index a4b63de..b01e2c9 100644
--- a/hbase-common/src/main/java/org/apache/hadoop/hbase/types/OrderedBytesBase.java
+++ b/hbase-common/src/main/java/org/apache/hadoop/hbase/types/OrderedBytesBase.java
@@ -31,7 +31,7 @@ public abstract class OrderedBytesBase<T> implements DataType<T> {
protected final Order order;
- protected OrderedBytesBase(Order order) {
+ public OrderedBytesBase(Order order) {
this.order = order;
}
diff --git a/hbase-common/src/main/java/org/apache/hadoop/hbase/types/OrderedFloat32.java b/hbase-common/src/main/java/org/apache/hadoop/hbase/types/OrderedFloat32.java
index 966b60d..ce3f538 100644
--- a/hbase-common/src/main/java/org/apache/hadoop/hbase/types/OrderedFloat32.java
+++ b/hbase-common/src/main/java/org/apache/hadoop/hbase/types/OrderedFloat32.java
@@ -28,11 +28,23 @@ import org.apache.yetus.audience.InterfaceAudience;
*/
@InterfaceAudience.Public
public class OrderedFloat32 extends OrderedBytesBase<Float> {
-
+ /**
+ * @deprecated since 3.0.0 and will be removed in 4.0.0
+ */
+ @Deprecated
public static final OrderedFloat32 ASCENDING = new OrderedFloat32(Order.ASCENDING);
+ /**
+ * @deprecated since 3.0.0 and will be removed in 4.0.0
+ */
+ @Deprecated
public static final OrderedFloat32 DESCENDING = new OrderedFloat32(Order.DESCENDING);
- protected OrderedFloat32(Order order) {
+ /**
+ * Creates a new 32-bit {@code float} with a fixed-length encoding.
+ *
+ * @param order the {@link Order} to use
+ */
+ public OrderedFloat32(Order order) {
super(order);
}
@@ -66,6 +78,9 @@ public class OrderedFloat32 extends OrderedBytesBase<Float> {
/**
* Read a {@code float} value from the buffer {@code dst}.
+ *
+ * @param dst the {@link PositionedByteRange} to read the {@code float} from
+ * @return the {@code float} read from the buffer
*/
public float decodeFloat(PositionedByteRange dst) {
return OrderedBytes.decodeFloat32(dst);
@@ -73,6 +88,10 @@ public class OrderedFloat32 extends OrderedBytesBase<Float> {
/**
* Write instance {@code val} into buffer {@code buff}.
+ *
+ * @param dst the {@link PositionedByteRange} to write to
+ * @param val the value to write to {@code dst}
+ * @return the number of bytes written
*/
public int encodeFloat(PositionedByteRange dst, float val) {
return OrderedBytes.encodeFloat32(dst, val, order);
diff --git a/hbase-common/src/main/java/org/apache/hadoop/hbase/types/OrderedFloat64.java b/hbase-common/src/main/java/org/apache/hadoop/hbase/types/OrderedFloat64.java
index 2c0eb71..a184192 100644
--- a/hbase-common/src/main/java/org/apache/hadoop/hbase/types/OrderedFloat64.java
+++ b/hbase-common/src/main/java/org/apache/hadoop/hbase/types/OrderedFloat64.java
@@ -28,11 +28,23 @@ import org.apache.yetus.audience.InterfaceAudience;
*/
@InterfaceAudience.Public
public class OrderedFloat64 extends OrderedBytesBase<Double> {
-
+ /**
+ * @deprecated since 3.0.0 and will be removed in 4.0.0
+ */
+ @Deprecated
public static final OrderedFloat64 ASCENDING = new OrderedFloat64(Order.ASCENDING);
+ /**
+ * @deprecated since 3.0.0 and will be removed in 4.0.0
+ */
+ @Deprecated
public static final OrderedFloat64 DESCENDING = new OrderedFloat64(Order.DESCENDING);
- protected OrderedFloat64(Order order) {
+ /**
+ * Creates a new 64-bite {@code double} with a fixed-length encoding.
+ *
+ * @param order the {@link Order} to use
+ */
+ public OrderedFloat64(Order order) {
super(order);
}
@@ -66,6 +78,9 @@ public class OrderedFloat64 extends OrderedBytesBase<Double> {
/**
* Read a {@code double} value from the buffer {@code src}.
+ *
+ * @param src the {@link PositionedByteRange} to read the {@code double} from
+ * @return the {@code double} floating-point value with the same bit pattern
*/
public double decodeDouble(PositionedByteRange src) {
return OrderedBytes.decodeFloat64(src);
@@ -73,6 +88,10 @@ public class OrderedFloat64 extends OrderedBytesBase<Double> {
/**
* Write instance {@code val} into buffer {@code dst}.
+ *
+ * @param dst the {@link PositionedByteRange} to write to
+ * @param val the value to write to {@code dst}
+ * @return the number of bytes written
*/
public int encodeDouble(PositionedByteRange dst, double val) {
return OrderedBytes.encodeFloat64(dst, val, order);
diff --git a/hbase-common/src/main/java/org/apache/hadoop/hbase/types/OrderedInt16.java b/hbase-common/src/main/java/org/apache/hadoop/hbase/types/OrderedInt16.java
index 1840fbc..10c34a2 100644
--- a/hbase-common/src/main/java/org/apache/hadoop/hbase/types/OrderedInt16.java
+++ b/hbase-common/src/main/java/org/apache/hadoop/hbase/types/OrderedInt16.java
@@ -28,11 +28,23 @@ import org.apache.yetus.audience.InterfaceAudience;
*/
@InterfaceAudience.Public
public class OrderedInt16 extends OrderedBytesBase<Short> {
-
+ /**
+ * @deprecated since 3.0.0 and will be removed in 4.0.0
+ */
+ @Deprecated
public static final OrderedInt16 ASCENDING = new OrderedInt16(Order.ASCENDING);
+ /**
+ * @deprecated since 3.0.0 and will be removed in 4.0.0
+ */
+ @Deprecated
public static final OrderedInt16 DESCENDING = new OrderedInt16(Order.DESCENDING);
- protected OrderedInt16(Order order) {
+ /**
+ * Creates a new 16-bit {@code short} with a fixed-length encoding.
+ *
+ * @param order the {@link Order} to use
+ */
+ public OrderedInt16(Order order) {
super(order);
}
@@ -66,6 +78,9 @@ public class OrderedInt16 extends OrderedBytesBase<Short> {
/**
* Read a {@code short} value from the buffer {@code src}.
+ *
+ * @param src the {@link PositionedByteRange} to read the {@code float} from
+ * @return the {@code short} read from buffer
*/
public short decodeShort(PositionedByteRange src) {
return OrderedBytes.decodeInt16(src);
@@ -73,6 +88,10 @@ public class OrderedInt16 extends OrderedBytesBase<Short> {
/**
* Write instance {@code val} into buffer {@code dst}.
+ *
+ * @param dst the {@link PositionedByteRange} to write to
+ * @param val the value to write to {@code dst}
+ * @return the number of bytes written
*/
public int encodeShort(PositionedByteRange dst, short val) {
return OrderedBytes.encodeInt16(dst, val, order);
diff --git a/hbase-common/src/main/java/org/apache/hadoop/hbase/types/OrderedInt32.java b/hbase-common/src/main/java/org/apache/hadoop/hbase/types/OrderedInt32.java
index e45aa5b..b8449c3 100644
--- a/hbase-common/src/main/java/org/apache/hadoop/hbase/types/OrderedInt32.java
+++ b/hbase-common/src/main/java/org/apache/hadoop/hbase/types/OrderedInt32.java
@@ -28,11 +28,23 @@ import org.apache.yetus.audience.InterfaceAudience;
*/
@InterfaceAudience.Public
public class OrderedInt32 extends OrderedBytesBase<Integer> {
-
+ /**
+ * @deprecated since 3.0.0 and will be removed in 4.0.0
+ */
+ @Deprecated
public static final OrderedInt32 ASCENDING = new OrderedInt32(Order.ASCENDING);
+ /**
+ * @deprecated since 3.0.0 and will be removed in 4.0.0
+ */
+ @Deprecated
public static final OrderedInt32 DESCENDING = new OrderedInt32(Order.DESCENDING);
- protected OrderedInt32(Order order) {
+ /**
+ * Creates a new 32-bit {@code int} with a fixed-length encoding.
+ *
+ * @param order the {@link Order} to use
+ */
+ public OrderedInt32(Order order) {
super(order);
}
@@ -66,6 +78,9 @@ public class OrderedInt32 extends OrderedBytesBase<Integer> {
/**
* Read an {@code int} value from the buffer {@code src}.
+ *
+ * @param src the {@link PositionedByteRange} to read the {@code int} from
+ * @return the {@code int} read from the buffer
*/
public int decodeInt(PositionedByteRange src) {
return OrderedBytes.decodeInt32(src);
@@ -73,6 +88,10 @@ public class OrderedInt32 extends OrderedBytesBase<Integer> {
/**
* Write instance {@code val} into buffer {@code dst}.
+ *
+ * @param dst the {@link PositionedByteRange} to write to
+ * @param val the value to write to {@code dst}
+ * @return the number of bytes written
*/
public int encodeInt(PositionedByteRange dst, int val) {
return OrderedBytes.encodeInt32(dst, val, order);
diff --git a/hbase-common/src/main/java/org/apache/hadoop/hbase/types/OrderedInt64.java b/hbase-common/src/main/java/org/apache/hadoop/hbase/types/OrderedInt64.java
index 3a409d3..dc1396b 100644
--- a/hbase-common/src/main/java/org/apache/hadoop/hbase/types/OrderedInt64.java
+++ b/hbase-common/src/main/java/org/apache/hadoop/hbase/types/OrderedInt64.java
@@ -28,11 +28,23 @@ import org.apache.yetus.audience.InterfaceAudience;
*/
@InterfaceAudience.Public
public class OrderedInt64 extends OrderedBytesBase<Long> {
-
+ /**
+ * @deprecated since 3.0.0 and will be removed in 4.0.0
+ */
+ @Deprecated
public static final OrderedInt64 ASCENDING = new OrderedInt64(Order.ASCENDING);
+ /**
+ * @deprecated since 3.0.0 and will be removed in 4.0.0
+ */
+ @Deprecated
public static final OrderedInt64 DESCENDING = new OrderedInt64(Order.DESCENDING);
- protected OrderedInt64(Order order) {
+ /**
+ * Creates a new 64-bit {@code long} with a fixed-length encoding.
+ *
+ * @param order the {@link Order} to use
+ */
+ public OrderedInt64(Order order) {
super(order);
}
@@ -66,6 +78,9 @@ public class OrderedInt64 extends OrderedBytesBase<Long> {
/**
* Read a {@code long} value from the buffer {@code src}.
+ *
+ * @param src the {@link PositionedByteRange} to read the {@code long} from
+ * @return the {@code long} read from the buffer
*/
public long decodeLong(PositionedByteRange src) {
return OrderedBytes.decodeInt64(src);
@@ -73,6 +88,10 @@ public class OrderedInt64 extends OrderedBytesBase<Long> {
/**
* Write instance {@code val} into buffer {@code dst}.
+ *
+ * @param dst the {@link PositionedByteRange} to write to
+ * @param val the value to write to {@code dst}
+ * @return the number of bytes written
*/
public int encodeLong(PositionedByteRange dst, long val) {
return OrderedBytes.encodeInt64(dst, val, order);
diff --git a/hbase-common/src/main/java/org/apache/hadoop/hbase/types/OrderedInt8.java b/hbase-common/src/main/java/org/apache/hadoop/hbase/types/OrderedInt8.java
index 4a7b47b..6e09f69 100644
--- a/hbase-common/src/main/java/org/apache/hadoop/hbase/types/OrderedInt8.java
+++ b/hbase-common/src/main/java/org/apache/hadoop/hbase/types/OrderedInt8.java
@@ -28,11 +28,23 @@ import org.apache.yetus.audience.InterfaceAudience;
*/
@InterfaceAudience.Public
public class OrderedInt8 extends OrderedBytesBase<Byte> {
-
+ /**
+ * @deprecated since 3.0.0 and will be removed in 4.0.0
+ */
+ @Deprecated
public static final OrderedInt8 ASCENDING = new OrderedInt8(Order.ASCENDING);
+ /**
+ * @deprecated since 3.0.0 and will be removed in 4.0.0
+ */
+ @Deprecated
public static final OrderedInt8 DESCENDING = new OrderedInt8(Order.DESCENDING);
- protected OrderedInt8(Order order) {
+ /**
+ * Creates a new 8-bit {@code byte} with a fixed-length encoding.
+ *
+ * @param order the {@link Order} to use
+ */
+ public OrderedInt8(Order order) {
super(order);
}
@@ -66,6 +78,9 @@ public class OrderedInt8 extends OrderedBytesBase<Byte> {
/**
* Read a {@code byte} value from the buffer {@code src}.
+ *
+ * @param src the {@link PositionedByteRange} to read the {@code byte} from
+ * @return the {@code byte} read from the buffer
*/
public byte decodeByte(PositionedByteRange src) {
return OrderedBytes.decodeInt8(src);
@@ -73,6 +88,10 @@ public class OrderedInt8 extends OrderedBytesBase<Byte> {
/**
* Write instance {@code val} into buffer {@code dst}.
+ *
+ * @param dst the {@link PositionedByteRange} to write to
+ * @param val the value to write to {@code dst}
+ * @return the number of bytes written
*/
public int encodeByte(PositionedByteRange dst, byte val) {
return OrderedBytes.encodeInt8(dst, val, order);
diff --git a/hbase-common/src/main/java/org/apache/hadoop/hbase/types/OrderedNumeric.java b/hbase-common/src/main/java/org/apache/hadoop/hbase/types/OrderedNumeric.java
index 3cdb7cc..ed0df8e 100644
--- a/hbase-common/src/main/java/org/apache/hadoop/hbase/types/OrderedNumeric.java
+++ b/hbase-common/src/main/java/org/apache/hadoop/hbase/types/OrderedNumeric.java
@@ -36,11 +36,23 @@ import org.apache.yetus.audience.InterfaceAudience;
*/
@InterfaceAudience.Public
public class OrderedNumeric extends OrderedBytesBase<Number> {
-
+ /**
+ * @deprecated since 3.0.0 and will be removed in 4.0.0
+ */
+ @Deprecated
public static final OrderedNumeric ASCENDING = new OrderedNumeric(Order.ASCENDING);
+ /**
+ * @deprecated since 3.0.0 and will be removed in 4.0.0
+ */
+ @Deprecated
public static final OrderedNumeric DESCENDING = new OrderedNumeric(Order.DESCENDING);
- protected OrderedNumeric(Order order) {
+ /**
+ * Creates a new {@link Number} of arbitrary precision and variable-length encoding.
+ *
+ * @param order the {@link Order} to use
+ */
+ public OrderedNumeric(Order order) {
super(order);
}
@@ -82,6 +94,9 @@ public class OrderedNumeric extends OrderedBytesBase<Number> {
/**
* Read a {@code long} value from the buffer {@code src}.
+ *
+ * @param src the {@link PositionedByteRange} to read the {@code long} from
+ * @return the {@code long} read from the buffer
*/
public long decodeLong(PositionedByteRange src) {
return OrderedBytes.decodeNumericAsLong(src);
@@ -89,6 +104,10 @@ public class OrderedNumeric extends OrderedBytesBase<Number> {
/**
* Write instance {@code val} into buffer {@code dst}.
+ *
+ * @param dst the {@link PositionedByteRange} to write to
+ * @param val the value to write to {@code dst}
+ * @return the number of bytes written
*/
public int encodeLong(PositionedByteRange dst, long val) {
return OrderedBytes.encodeNumeric(dst, val, order);
@@ -96,6 +115,9 @@ public class OrderedNumeric extends OrderedBytesBase<Number> {
/**
* Read a {@code double} value from the buffer {@code src}.
+ *
+ * @param src the {@link PositionedByteRange} to read the {@code double} from
+ * @return the {@code double} read from the buffer
*/
public double decodeDouble(PositionedByteRange src) {
return OrderedBytes.decodeNumericAsLong(src);
@@ -103,6 +125,10 @@ public class OrderedNumeric extends OrderedBytesBase<Number> {
/**
* Write instance {@code val} into buffer {@code dst}.
+ *
+ * @param dst the {@link PositionedByteRange} to write to
+ * @param val the value to write to {@code dst}
+ * @return the number of bytes written
*/
public int encodeDouble(PositionedByteRange dst, double val) {
return OrderedBytes.encodeNumeric(dst, val, order);
diff --git a/hbase-common/src/main/java/org/apache/hadoop/hbase/types/OrderedString.java b/hbase-common/src/main/java/org/apache/hadoop/hbase/types/OrderedString.java
index e687f39..7dfef49 100644
--- a/hbase-common/src/main/java/org/apache/hadoop/hbase/types/OrderedString.java
+++ b/hbase-common/src/main/java/org/apache/hadoop/hbase/types/OrderedString.java
@@ -28,11 +28,23 @@ import org.apache.yetus.audience.InterfaceAudience;
*/
@InterfaceAudience.Public
public class OrderedString extends OrderedBytesBase<String> {
-
+ /**
+ * @deprecated since 3.0.0 and will be removed in 4.0.0
+ */
+ @Deprecated
public static final OrderedString ASCENDING = new OrderedString(Order.ASCENDING);
+ /**
+ * @deprecated since 3.0.0 and will be removed in 4.0.0
+ */
+ @Deprecated
public static final OrderedString DESCENDING = new OrderedString(Order.DESCENDING);
- protected OrderedString(Order order) {
+ /**
+ * Creates a new variable-length {@link String}.
+ *
+ * @param order the {@link Order} to use
+ */
+ public OrderedString(Order order) {
super(order);
}
diff --git a/hbase-common/src/main/java/org/apache/hadoop/hbase/types/RawBytes.java b/hbase-common/src/main/java/org/apache/hadoop/hbase/types/RawBytes.java
index 5f308ed..554f294 100644
--- a/hbase-common/src/main/java/org/apache/hadoop/hbase/types/RawBytes.java
+++ b/hbase-common/src/main/java/org/apache/hadoop/hbase/types/RawBytes.java
@@ -35,17 +35,33 @@ import org.apache.yetus.audience.InterfaceAudience;
*/
@InterfaceAudience.Public
public class RawBytes implements DataType<byte[]> {
-
+ /**
+ * @deprecated since 3.0.0 and will be removed in 4.0.0
+ */
+ @Deprecated
public static final RawBytes ASCENDING = new RawBytes(Order.ASCENDING);
+ /**
+ * @deprecated since 3.0.0 and will be removed in 4.0.0
+ */
+ @Deprecated
public static final RawBytes DESCENDING = new RawBytes(Order.DESCENDING);
protected final Order order;
- protected RawBytes() {
+ /**
+ * @deprecated since 3.0.0 and will be removed in 4.0.0
+ */
+ @Deprecated
+ public RawBytes() {
this.order = Order.ASCENDING;
}
- protected RawBytes(Order order) {
+ /**
+ * Creates a new {@link DataType} with variable-length values.
+ *
+ * @param order the {@link Order} to use
+ */
+ public RawBytes(Order order) {
this.order = order;
}
@@ -98,6 +114,10 @@ public class RawBytes implements DataType<byte[]> {
/**
* Read a {@code byte[]} from the buffer {@code src}.
+ *
+ * @param src the {@link PositionedByteRange} to read the {@code byte[]} from
+ * @param length the length to read from the buffer
+ * @return the {@code byte[]} read from the buffer
*/
public byte[] decode(PositionedByteRange src, int length) {
byte[] val = new byte[length];
@@ -107,7 +127,12 @@ public class RawBytes implements DataType<byte[]> {
/**
* Write {@code val} into {@code dst}, respecting {@code voff} and {@code vlen}.
- * @return number of bytes written.
+ *
+ * @param dst the {@link PositionedByteRange} to write to
+ * @param val the value to write to {@code dst}
+ * @param voff the offset in {@code dst} where to write {@code val} to
+ * @param vlen the length of {@code val}
+ * @return number of bytes written
*/
public int encode(PositionedByteRange dst, byte[] val, int voff, int vlen) {
Bytes.putBytes(dst.getBytes(), dst.getOffset() + dst.getPosition(), val, voff, vlen);
diff --git a/hbase-common/src/main/java/org/apache/hadoop/hbase/types/RawBytesFixedLength.java b/hbase-common/src/main/java/org/apache/hadoop/hbase/types/RawBytesFixedLength.java
index 3de9ee5..cdc2373 100644
--- a/hbase-common/src/main/java/org/apache/hadoop/hbase/types/RawBytesFixedLength.java
+++ b/hbase-common/src/main/java/org/apache/hadoop/hbase/types/RawBytesFixedLength.java
@@ -47,7 +47,7 @@ public class RawBytesFixedLength extends FixedLengthWrapper<byte[]> {
* Create a {@code RawBytesFixedLength} of the specified {@code length}.
*/
public RawBytesFixedLength(int length) {
- super(new RawBytes(), length);
+ super(new RawBytes(Order.ASCENDING), length);
}
/**
diff --git a/hbase-common/src/main/java/org/apache/hadoop/hbase/types/RawBytesTerminated.java b/hbase-common/src/main/java/org/apache/hadoop/hbase/types/RawBytesTerminated.java
index 49f9fff..5758f49 100644
--- a/hbase-common/src/main/java/org/apache/hadoop/hbase/types/RawBytesTerminated.java
+++ b/hbase-common/src/main/java/org/apache/hadoop/hbase/types/RawBytesTerminated.java
@@ -56,7 +56,7 @@ public class RawBytesTerminated extends TerminatedWrapper<byte[]> {
* @throws IllegalArgumentException if {@code term} is {@code null} or empty.
*/
public RawBytesTerminated(byte[] term) {
- super(new RawBytes(), term);
+ super(new RawBytes(Order.ASCENDING), term);
}
/**
@@ -64,7 +64,7 @@ public class RawBytesTerminated extends TerminatedWrapper<byte[]> {
* @throws IllegalArgumentException if {@code term} is {@code null} or empty.
*/
public RawBytesTerminated(String term) {
- super(new RawBytes(), term);
+ super(new RawBytes(Order.ASCENDING), term);
}
/**
diff --git a/hbase-common/src/main/java/org/apache/hadoop/hbase/types/RawString.java b/hbase-common/src/main/java/org/apache/hadoop/hbase/types/RawString.java
index 69034ce..72e8be9 100644
--- a/hbase-common/src/main/java/org/apache/hadoop/hbase/types/RawString.java
+++ b/hbase-common/src/main/java/org/apache/hadoop/hbase/types/RawString.java
@@ -32,17 +32,34 @@ import org.apache.yetus.audience.InterfaceAudience;
*/
@InterfaceAudience.Public
public class RawString implements DataType<String> {
-
+ /**
+ * @deprecated since 3.0.0 and will be removed in 4.0.0
+ */
+ @Deprecated
public static final RawString ASCENDING = new RawString(Order.ASCENDING);
+ /**
+ * @deprecated since 3.0.0 and will be removed in 4.0.0
+ */
+ @Deprecated
public static final RawString DESCENDING = new RawString(Order.DESCENDING);
protected final Order order;
- protected RawString() {
+ /**
+ * @deprecated since 3.0.0 and will be removed in 4.0.0
+ */
+ @Deprecated
+ public RawString() {
this.order = Order.ASCENDING;
}
- protected RawString(Order order) {
+ /**
+ * Creates a new {@link DataType} for interacting with values encoded using
+ * {@link Bytes#toBytes(String)}.
+ *
+ * @param order the {@link Order} to use
+ */
+ public RawString(Order order) {
this.order = order;
}
diff --git a/hbase-common/src/main/java/org/apache/hadoop/hbase/types/RawStringFixedLength.java b/hbase-common/src/main/java/org/apache/hadoop/hbase/types/RawStringFixedLength.java
index e8b99bd..5a68bbe 100644
--- a/hbase-common/src/main/java/org/apache/hadoop/hbase/types/RawStringFixedLength.java
+++ b/hbase-common/src/main/java/org/apache/hadoop/hbase/types/RawStringFixedLength.java
@@ -44,6 +44,6 @@ public class RawStringFixedLength extends FixedLengthWrapper<String> {
* Create a {@code RawStringFixedLength} of the specified {@code length}.
*/
public RawStringFixedLength(int length) {
- super(new RawString(), length);
+ super(new RawString(Order.ASCENDING), length);
}
}
diff --git a/hbase-common/src/main/java/org/apache/hadoop/hbase/types/RawStringTerminated.java b/hbase-common/src/main/java/org/apache/hadoop/hbase/types/RawStringTerminated.java
index 397f443..05e1fc4 100644
--- a/hbase-common/src/main/java/org/apache/hadoop/hbase/types/RawStringTerminated.java
+++ b/hbase-common/src/main/java/org/apache/hadoop/hbase/types/RawStringTerminated.java
@@ -57,7 +57,7 @@ public class RawStringTerminated extends TerminatedWrapper<String> {
* @throws IllegalArgumentException if {@code term} is {@code null} or empty.
*/
public RawStringTerminated(byte[] term) {
- super(new RawString(), term);
+ super(new RawString(Order.ASCENDING), term);
}
/**
@@ -65,6 +65,6 @@ public class RawStringTerminated extends TerminatedWrapper<String> {
* @throws IllegalArgumentException if {@code term} is {@code null} or empty.
*/
public RawStringTerminated(String term) {
- super(new RawString(), term);
+ super(new RawString(Order.ASCENDING), term);
}
}
diff --git a/hbase-common/src/test/java/org/apache/hadoop/hbase/types/TestFixedLengthWrapper.java b/hbase-common/src/test/java/org/apache/hadoop/hbase/types/TestFixedLengthWrapper.java
index d3cb4fb..f7b95b0 100644
--- a/hbase-common/src/test/java/org/apache/hadoop/hbase/types/TestFixedLengthWrapper.java
+++ b/hbase-common/src/test/java/org/apache/hadoop/hbase/types/TestFixedLengthWrapper.java
@@ -72,22 +72,22 @@ public class TestFixedLengthWrapper {
@Test(expected = IllegalArgumentException.class)
public void testInsufficientRemainingRead() {
- PositionedByteRange buff = new SimplePositionedMutableByteRange(0);
- DataType<byte[]> type = new FixedLengthWrapper<>(new RawBytes(), 3);
+ final PositionedByteRange buff = new SimplePositionedMutableByteRange(0);
+ final DataType<byte[]> type = new FixedLengthWrapper<>(new RawBytes(Order.ASCENDING), 3);
type.decode(buff);
}
@Test(expected = IllegalArgumentException.class)
public void testInsufficientRemainingWrite() {
- PositionedByteRange buff = new SimplePositionedMutableByteRange(0);
- DataType<byte[]> type = new FixedLengthWrapper<>(new RawBytes(), 3);
+ final PositionedByteRange buff = new SimplePositionedMutableByteRange(0);
+ final DataType<byte[]> type = new FixedLengthWrapper<>(new RawBytes(Order.ASCENDING), 3);
type.encode(buff, Bytes.toBytes(""));
}
@Test(expected = IllegalArgumentException.class)
public void testOverflowPassthrough() {
- PositionedByteRange buff = new SimplePositionedMutableByteRange(3);
- DataType<byte[]> type = new FixedLengthWrapper<>(new RawBytes(), 0);
+ final PositionedByteRange buff = new SimplePositionedMutableByteRange(3);
+ final DataType<byte[]> type = new FixedLengthWrapper<>(new RawBytes(Order.ASCENDING), 0);
type.encode(buff, Bytes.toBytes("foo"));
}
}
diff --git a/hbase-common/src/test/java/org/apache/hadoop/hbase/types/TestOrderedBlob.java b/hbase-common/src/test/java/org/apache/hadoop/hbase/types/TestOrderedBlob.java
index 448a660..ccca554 100644
--- a/hbase-common/src/test/java/org/apache/hadoop/hbase/types/TestOrderedBlob.java
+++ b/hbase-common/src/test/java/org/apache/hadoop/hbase/types/TestOrderedBlob.java
@@ -18,11 +18,13 @@
package org.apache.hadoop.hbase.types;
import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
import org.apache.hadoop.hbase.HBaseClassTestRule;
import org.apache.hadoop.hbase.testclassification.MiscTests;
import org.apache.hadoop.hbase.testclassification.SmallTests;
import org.apache.hadoop.hbase.util.Bytes;
+import org.apache.hadoop.hbase.util.Order;
import org.apache.hadoop.hbase.util.PositionedByteRange;
import org.apache.hadoop.hbase.util.SimplePositionedMutableByteRange;
import org.junit.ClassRule;
@@ -31,28 +33,41 @@ import org.junit.experimental.categories.Category;
@Category({MiscTests.class, SmallTests.class})
public class TestOrderedBlob {
-
@ClassRule
public static final HBaseClassTestRule CLASS_RULE =
HBaseClassTestRule.forClass(TestOrderedBlob.class);
- static final byte[][] VALUES = new byte[][] {
+ private static final byte[][] VALUES = new byte[][] {
null, Bytes.toBytes(""), Bytes.toBytes("1"), Bytes.toBytes("22"), Bytes.toBytes("333"),
Bytes.toBytes("4444"), Bytes.toBytes("55555"), Bytes.toBytes("666666"),
Bytes.toBytes("7777777"), Bytes.toBytes("88888888"), Bytes.toBytes("999999999"),
};
@Test
+ public void testIsSkippableFalse() {
+ final DataType<byte[]> type = new OrderedBlob(Order.ASCENDING);
+
+ assertFalse(type.isSkippable());
+ }
+
+ @Test
public void testEncodedLength() {
PositionedByteRange buff = new SimplePositionedMutableByteRange(20);
- for (DataType<byte[]> type : new OrderedBlob[] { OrderedBlob.ASCENDING, OrderedBlob.DESCENDING }) {
- for (byte[] val : VALUES) {
+ 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),
+ assertEquals("encodedLength does not match actual, " + Bytes.toStringBinary(val),
buff.getPosition(), type.encodedLength(val));
}
}
}
+
+ @Test
+ public void testEncodedClassByteArray() {
+ final DataType<byte[]> type = new OrderedBlob(Order.ASCENDING);
+
+ assertEquals(byte[].class, type.encodedClass());
+ }
}
diff --git a/hbase-common/src/test/java/org/apache/hadoop/hbase/types/TestOrderedBlobVar.java b/hbase-common/src/test/java/org/apache/hadoop/hbase/types/TestOrderedBlobVar.java
index 99e8fd2..4377c0e 100644
--- a/hbase-common/src/test/java/org/apache/hadoop/hbase/types/TestOrderedBlobVar.java
+++ b/hbase-common/src/test/java/org/apache/hadoop/hbase/types/TestOrderedBlobVar.java
@@ -23,6 +23,7 @@ import org.apache.hadoop.hbase.HBaseClassTestRule;
import org.apache.hadoop.hbase.testclassification.MiscTests;
import org.apache.hadoop.hbase.testclassification.SmallTests;
import org.apache.hadoop.hbase.util.Bytes;
+import org.apache.hadoop.hbase.util.Order;
import org.apache.hadoop.hbase.util.PositionedByteRange;
import org.apache.hadoop.hbase.util.SimplePositionedMutableByteRange;
import org.junit.ClassRule;
@@ -31,12 +32,11 @@ import org.junit.experimental.categories.Category;
@Category({MiscTests.class, SmallTests.class})
public class TestOrderedBlobVar {
-
@ClassRule
public static final HBaseClassTestRule CLASS_RULE =
HBaseClassTestRule.forClass(TestOrderedBlobVar.class);
- static final byte[][] VALUES = new byte[][] {
+ private static final byte[][] VALUES = new byte[][] {
null, Bytes.toBytes(""), Bytes.toBytes("1"), Bytes.toBytes("22"), Bytes.toBytes("333"),
Bytes.toBytes("4444"), Bytes.toBytes("55555"), Bytes.toBytes("666666"),
Bytes.toBytes("7777777"), Bytes.toBytes("88888888"), Bytes.toBytes("999999999"),
@@ -44,16 +44,23 @@ public class TestOrderedBlobVar {
@Test
public void testEncodedLength() {
- PositionedByteRange buff = new SimplePositionedMutableByteRange(20);
- for (DataType<byte[]> type :
- new OrderedBlobVar[] { OrderedBlobVar.ASCENDING, OrderedBlobVar.DESCENDING }) {
- for (byte[] val : VALUES) {
+ 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),
+ assertEquals("encodedLength does not match actual, " + Bytes.toStringBinary(val),
buff.getPosition(), type.encodedLength(val));
}
}
}
+
+ @Test
+ public void testEncodedClassByteArray() {
+ final DataType<byte[]> type = new OrderedBlobVar(Order.ASCENDING);
+
+ assertEquals(byte[].class, type.encodedClass());
+ }
}
diff --git a/hbase-common/src/test/java/org/apache/hadoop/hbase/types/TestOrderedFloat32.java b/hbase-common/src/test/java/org/apache/hadoop/hbase/types/TestOrderedFloat32.java
new file mode 100644
index 0000000..ee6c76e
--- /dev/null
+++ b/hbase-common/src/test/java/org/apache/hadoop/hbase/types/TestOrderedFloat32.java
@@ -0,0 +1,98 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.hadoop.hbase.types;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+
+import org.apache.hadoop.hbase.HBaseClassTestRule;
+import org.apache.hadoop.hbase.testclassification.MiscTests;
+import org.apache.hadoop.hbase.testclassification.SmallTests;
+import org.apache.hadoop.hbase.util.Order;
+import org.apache.hadoop.hbase.util.PositionedByteRange;
+import org.apache.hadoop.hbase.util.SimplePositionedMutableByteRange;
+import org.junit.ClassRule;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.experimental.categories.Category;
+import org.junit.rules.ExpectedException;
+
+@Category({MiscTests.class, SmallTests.class})
+public class TestOrderedFloat32 {
+ private static final Float[] VALUES = new Float[] {
+ Float.NaN, 1f, 22f, 333f, 4444f, 55555f, 666666f, 7777777f, 88888888f, 999999999f
+ };
+
+ @ClassRule
+ public static final HBaseClassTestRule CLASS_RULE =
+ HBaseClassTestRule.forClass(TestOrderedFloat32.class);
+
+ @Rule
+ public ExpectedException exception = ExpectedException.none();
+
+ @Test
+ public void testIsNullableIsFalse() {
+ final DataType<Float> type = new OrderedFloat32(Order.ASCENDING);
+
+ assertFalse(type.isNullable());
+ }
+
+ @Test
+ public void testEncodedClassIsFloat() {
+ final DataType<Float> type = new OrderedFloat32(Order.ASCENDING);
+
+ assertEquals(Float.class, type.encodedClass());
+ }
+
+ @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));
+ }
+ }
+ }
+
+ @Test
+ public void testEncodeNoSupportForNull() {
+ exception.expect(IllegalArgumentException.class);
+
+ final DataType<Float> type = new OrderedFloat32(Order.ASCENDING);
+
+ type.encode(new SimplePositionedMutableByteRange(20), null);
+ }
+
+ @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));
+ }
+ }
+ }
+}
diff --git a/hbase-common/src/test/java/org/apache/hadoop/hbase/types/TestOrderedFloat64.java b/hbase-common/src/test/java/org/apache/hadoop/hbase/types/TestOrderedFloat64.java
new file mode 100644
index 0000000..6bcb564
--- /dev/null
+++ b/hbase-common/src/test/java/org/apache/hadoop/hbase/types/TestOrderedFloat64.java
@@ -0,0 +1,98 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.hadoop.hbase.types;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+
+import org.apache.hadoop.hbase.HBaseClassTestRule;
+import org.apache.hadoop.hbase.testclassification.MiscTests;
+import org.apache.hadoop.hbase.testclassification.SmallTests;
+import org.apache.hadoop.hbase.util.Order;
+import org.apache.hadoop.hbase.util.PositionedByteRange;
+import org.apache.hadoop.hbase.util.SimplePositionedMutableByteRange;
+import org.junit.ClassRule;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.experimental.categories.Category;
+import org.junit.rules.ExpectedException;
+
+@Category({MiscTests.class, SmallTests.class})
+public class TestOrderedFloat64 {
+ private static final Double[] VALUES = new Double[] {
+ Double.NaN, 1.1, 22.2, 333.3, 4444.4, 55555.5, 666666.6, 7777777.7, 88888888.8, 999999999.9
+ };
+
+ @ClassRule
+ public static final HBaseClassTestRule CLASS_RULE =
+ HBaseClassTestRule.forClass(TestOrderedFloat64.class);
+
+ @Rule
+ public ExpectedException exception = ExpectedException.none();
+
+ @Test
+ public void testIsNullableIsFalse() {
+ final DataType<Double> type = new OrderedFloat64(Order.ASCENDING);
+
+ assertFalse(type.isNullable());
+ }
+
+ @Test
+ public void testEncodedClassIsDouble() {
+ final DataType<Double> type = new OrderedFloat64(Order.ASCENDING);
+
+ assertEquals(Double.class, type.encodedClass());
+ }
+
+ @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));
+ }
+ }
+ }
+
+ @Test
+ public void testEncodeNoSupportForNull() {
+ exception.expect(IllegalArgumentException.class);
+
+ final DataType<Double> type = new OrderedFloat64(Order.ASCENDING);
+
+ type.encode(new SimplePositionedMutableByteRange(20), null);
+ }
+
+ @Test
+ public void testEncodedFloatLength() {
+ final PositionedByteRange buffer = new SimplePositionedMutableByteRange(20);
+ for (final OrderedFloat64 type : new OrderedFloat64[] { new OrderedFloat64(Order.ASCENDING),
+ new OrderedFloat64(Order.DESCENDING) }) {
+ for (final Double val : VALUES) {
+ buffer.setPosition(0);
+ type.encodeDouble(buffer, val);
+ assertEquals("encodedLength does not match actual, " + val,
+ buffer.getPosition(), type.encodedLength(val));
+ }
+ }
+ }
+}
diff --git a/hbase-common/src/test/java/org/apache/hadoop/hbase/types/TestOrderedInt16.java b/hbase-common/src/test/java/org/apache/hadoop/hbase/types/TestOrderedInt16.java
new file mode 100644
index 0000000..0d4b8197
--- /dev/null
+++ b/hbase-common/src/test/java/org/apache/hadoop/hbase/types/TestOrderedInt16.java
@@ -0,0 +1,98 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.hadoop.hbase.types;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+
+import org.apache.hadoop.hbase.HBaseClassTestRule;
+import org.apache.hadoop.hbase.testclassification.MiscTests;
+import org.apache.hadoop.hbase.testclassification.SmallTests;
+import org.apache.hadoop.hbase.util.Order;
+import org.apache.hadoop.hbase.util.PositionedByteRange;
+import org.apache.hadoop.hbase.util.SimplePositionedMutableByteRange;
+import org.junit.ClassRule;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.experimental.categories.Category;
+import org.junit.rules.ExpectedException;
+
+@Category({MiscTests.class, SmallTests.class})
+public class TestOrderedInt16 {
+ private static final Short[] VALUES = new Short[] {
+ 1, 22, 333, 4444
+ };
+
+ @ClassRule
+ public static final HBaseClassTestRule CLASS_RULE =
+ HBaseClassTestRule.forClass(TestOrderedInt16.class);
+
+ @Rule
+ public ExpectedException exception = ExpectedException.none();
+
+ @Test
+ public void testIsNullableIsFalse() {
+ final DataType<Short> type = new OrderedInt16(Order.ASCENDING);
+
+ assertFalse(type.isNullable());
+ }
+
+ @Test
+ public void testEncodedClassIsShort() {
+ final DataType<Short> type = new OrderedInt16(Order.ASCENDING);
+
+ assertEquals(Short.class, type.encodedClass());
+ }
+
+ @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));
+ }
+ }
+ }
+
+ @Test
+ public void testEncodeNoSupportForNull() {
+ exception.expect(IllegalArgumentException.class);
+
+ final DataType<Short> type = new OrderedInt16(Order.ASCENDING);
+
+ type.encode(new SimplePositionedMutableByteRange(20), null);
+ }
+
+ @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));
+ }
+ }
+ }
+}
diff --git a/hbase-common/src/test/java/org/apache/hadoop/hbase/types/TestOrderedInt32.java b/hbase-common/src/test/java/org/apache/hadoop/hbase/types/TestOrderedInt32.java
new file mode 100644
index 0000000..bcfe33c
--- /dev/null
+++ b/hbase-common/src/test/java/org/apache/hadoop/hbase/types/TestOrderedInt32.java
@@ -0,0 +1,99 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.hadoop.hbase.types;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+
+import org.apache.hadoop.hbase.HBaseClassTestRule;
+import org.apache.hadoop.hbase.testclassification.MiscTests;
+import org.apache.hadoop.hbase.testclassification.SmallTests;
+import org.apache.hadoop.hbase.util.Order;
+import org.apache.hadoop.hbase.util.PositionedByteRange;
+import org.apache.hadoop.hbase.util.SimplePositionedMutableByteRange;
+import org.junit.ClassRule;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.experimental.categories.Category;
+import org.junit.rules.ExpectedException;
+
+@Category({MiscTests.class, SmallTests.class})
+public class TestOrderedInt32 {
+ private static final Integer[] VALUES = new Integer[] {
+ 1, 22, 333, 4444, 55555, 666666, 7777777, 88888888, 999999999
+ };
+
+ @ClassRule
+ public static final HBaseClassTestRule CLASS_RULE =
+ HBaseClassTestRule.forClass(TestOrderedInt32.class);
+
+ @Rule
+ public ExpectedException exception = ExpectedException.none();
+
+ @Test
+ public void testIsNullableIsFalse() {
+ final DataType<Integer> type = new OrderedInt32(Order.ASCENDING);
+
+ assertFalse(type.isNullable());
+ }
+
+ @Test
+ public void testEncodedClassIsInteger() {
+ final DataType<Integer> type = new OrderedInt32(Order.ASCENDING);
+
+ assertEquals(Integer.class, type.encodedClass());
+ }
+
+ @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));
+ }
+ }
+ }
+
+ @Test
+ public void testEncodeNoSupportForNull() {
+ exception.expect(IllegalArgumentException.class);
+
+ final DataType<Integer> type = new OrderedInt32(Order.ASCENDING);
+
+ type.encode(new SimplePositionedMutableByteRange(20), null);
+ }
+
+ @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));
+ }
+ }
+ }
+}
diff --git a/hbase-common/src/test/java/org/apache/hadoop/hbase/types/TestOrderedInt64.java b/hbase-common/src/test/java/org/apache/hadoop/hbase/types/TestOrderedInt64.java
new file mode 100644
index 0000000..de90baa
--- /dev/null
+++ b/hbase-common/src/test/java/org/apache/hadoop/hbase/types/TestOrderedInt64.java
@@ -0,0 +1,98 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.hadoop.hbase.types;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+
+import org.apache.hadoop.hbase.HBaseClassTestRule;
+import org.apache.hadoop.hbase.testclassification.MiscTests;
+import org.apache.hadoop.hbase.testclassification.SmallTests;
+import org.apache.hadoop.hbase.util.Order;
+import org.apache.hadoop.hbase.util.PositionedByteRange;
+import org.apache.hadoop.hbase.util.SimplePositionedMutableByteRange;
+import org.junit.ClassRule;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.experimental.categories.Category;
+import org.junit.rules.ExpectedException;
+
+@Category({MiscTests.class, SmallTests.class})
+public class TestOrderedInt64 {
+ private static final Long[] VALUES = new Long[] {
+ 1L, 22L, 333L, 4444L, 55555L, 666666L, 7777777L, 88888888L, 999999999L
+ };
+
+ @ClassRule
+ public static final HBaseClassTestRule CLASS_RULE =
+ HBaseClassTestRule.forClass(TestOrderedInt64.class);
+
+ @Rule
+ public ExpectedException exception = ExpectedException.none();
+
+ @Test
+ public void testIsNullableIsFalse() {
+ final DataType<Long> type = new OrderedInt64(Order.ASCENDING);
+
+ assertFalse(type.isNullable());
+ }
+
+ @Test
+ public void testEncodedClassIsLong() {
+ final DataType<Long> type = new OrderedInt64(Order.ASCENDING);
+
+ assertEquals(Long.class, type.encodedClass());
+ }
+
+ @Test
+ public void testEncodedLength() {
+ final PositionedByteRange buffer = new SimplePositionedMutableByteRange(20);
+ for (final DataType<Long> type : new OrderedInt64[] { new OrderedInt64(Order.ASCENDING),
+ new OrderedInt64(Order.DESCENDING) }) {
+ for (final Long val : VALUES) {
+ buffer.setPosition(0);
+ type.encode(buffer, val);
+ assertEquals("encodedLength does not match actual, " + val,
+ buffer.getPosition(), type.encodedLength(val));
+ }
+ }
+ }
+
+ @Test
+ public void testEncodeNoSupportForNull() {
+ exception.expect(IllegalArgumentException.class);
+
+ final DataType<Long> type = new OrderedInt64(Order.ASCENDING);
+
+ type.encode(new SimplePositionedMutableByteRange(20), null);
+ }
+
+ @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));
+ }
+ }
+ }
+}
diff --git a/hbase-common/src/test/java/org/apache/hadoop/hbase/types/TestOrderedInt8.java b/hbase-common/src/test/java/org/apache/hadoop/hbase/types/TestOrderedInt8.java
new file mode 100644
index 0000000..e31d213
--- /dev/null
+++ b/hbase-common/src/test/java/org/apache/hadoop/hbase/types/TestOrderedInt8.java
@@ -0,0 +1,98 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.hadoop.hbase.types;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+
+import org.apache.hadoop.hbase.HBaseClassTestRule;
+import org.apache.hadoop.hbase.testclassification.MiscTests;
+import org.apache.hadoop.hbase.testclassification.SmallTests;
+import org.apache.hadoop.hbase.util.Order;
+import org.apache.hadoop.hbase.util.PositionedByteRange;
+import org.apache.hadoop.hbase.util.SimplePositionedMutableByteRange;
+import org.junit.ClassRule;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.experimental.categories.Category;
+import org.junit.rules.ExpectedException;
+
+@Category({MiscTests.class, SmallTests.class})
+public class TestOrderedInt8 {
+ private static final Byte[] VALUES = new Byte[] {
+ 1, 22
+ };
+
+ @ClassRule
+ public static final HBaseClassTestRule CLASS_RULE =
+ HBaseClassTestRule.forClass(TestOrderedInt8.class);
+
+ @Rule
+ public ExpectedException exception = ExpectedException.none();
+
+ @Test
+ public void testIsNullableIsFalse() {
+ final DataType<Byte> type = new OrderedInt8(Order.ASCENDING);
+
+ assertFalse(type.isNullable());
+ }
+
+ @Test
+ public void testEncodedClassIsByte() {
+ final DataType<Byte> type = new OrderedInt8(Order.ASCENDING);
+
+ assertEquals(Byte.class, type.encodedClass());
+ }
+
+ @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));
+ }
+ }
+ }
+
+ @Test
+ public void testEncodeNoSupportForNull() {
+ exception.expect(IllegalArgumentException.class);
+
+ final DataType<Byte> type = new OrderedInt8(Order.ASCENDING);
+
+ type.encode(new SimplePositionedMutableByteRange(20), null);
+ }
+
+ @Test
+ public void testEncodedFloatLength() {
+ final PositionedByteRange buffer = new SimplePositionedMutableByteRange(20);
+ for (final OrderedInt8 type : new OrderedInt8[] { new OrderedInt8(Order.ASCENDING),
+ new OrderedInt8(Order.DESCENDING) }) {
+ for (final Byte val : VALUES) {
+ buffer.setPosition(0);
+ type.encodeByte(buffer, val);
+ assertEquals("encodedLength does not match actual, " + val,
+ buffer.getPosition(), type.encodedLength(val));
+ }
+ }
+ }
+}
diff --git a/hbase-common/src/test/java/org/apache/hadoop/hbase/types/TestOrderedNumeric.java b/hbase-common/src/test/java/org/apache/hadoop/hbase/types/TestOrderedNumeric.java
new file mode 100644
index 0000000..aae364b
--- /dev/null
+++ b/hbase-common/src/test/java/org/apache/hadoop/hbase/types/TestOrderedNumeric.java
@@ -0,0 +1,154 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.hadoop.hbase.types;
+
+import static org.junit.Assert.assertEquals;
+
+import java.math.BigDecimal;
+import java.math.BigInteger;
+import org.apache.hadoop.hbase.HBaseClassTestRule;
+import org.apache.hadoop.hbase.testclassification.MiscTests;
+import org.apache.hadoop.hbase.testclassification.SmallTests;
+import org.apache.hadoop.hbase.util.Order;
+import org.apache.hadoop.hbase.util.PositionedByteRange;
+import org.apache.hadoop.hbase.util.SimplePositionedMutableByteRange;
+import org.junit.ClassRule;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.experimental.categories.Category;
+import org.junit.rules.ExpectedException;
+
+@Category({MiscTests.class, SmallTests.class})
+public class TestOrderedNumeric {
+ private static final Long[] LONG_VALUES = new Long[] {
+ 1L, 22L, 333L, 4444L, 55555L, 666666L, 7777777L, 88888888L, 999999999L
+ };
+
+ private static final Double[] DOUBLE_VALUES = new Double[] {
+ Double.NaN, 1.1, 22.2, 333.3, 4444.4, 55555.5, 666666.6, 7777777.7, 88888888.8, 999999999.9
+ };
+
+ private static final BigDecimal[] BIG_DECIMAL_VALUES = new BigDecimal[] {
+ new BigDecimal(1), new BigDecimal(22), new BigDecimal(333), new BigDecimal(4444),
+ new BigDecimal(55555), new BigDecimal(666666), new BigDecimal(7777777),
+ new BigDecimal(88888888), new BigDecimal(999999999)
+ };
+
+ private static final BigInteger[] BIG_INTEGER_VALUES = new BigInteger[] {
+ new BigInteger("1"), new BigInteger("22"), new BigInteger("333"), new BigInteger("4444"),
+ new BigInteger("55555"), new BigInteger("666666"), new BigInteger("7777777"),
+ new BigInteger("88888888"), new BigInteger("999999999")
+ };
+
+ @ClassRule
+ public static final HBaseClassTestRule CLASS_RULE =
+ HBaseClassTestRule.forClass(TestOrderedNumeric.class);
+
+ @Rule
+ public ExpectedException exception = ExpectedException.none();
+
+ @Test
+ public void testEncodedClassIsNumber() {
+ final DataType<Number> type = new OrderedNumeric(Order.ASCENDING);
+
+ assertEquals(Number.class, type.encodedClass());
+ }
+
+ @Test
+ public void testEncodedLength() {
+ 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 : DOUBLE_VALUES) {
+ buffer.setPosition(0);
+ type.encode(buffer, val);
+ assertEquals("encodedLength does not match actual, " + val,
+ buffer.getPosition(), type.encodedLength(val));
+ }
+ }
+ }
+
+ @Test
+ public void testEncodedBigDecimalLength() {
+ 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_DECIMAL_VALUES) {
+ buffer.setPosition(0);
+ type.encode(buffer, val);
+ assertEquals("encodedLength does not match actual, " + val,
+ buffer.getPosition(), type.encodedLength(val));
+ }
+ }
+ }
+
+ @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));
+ }
+ }
+ }
+
+ @Test
+ public void testEncodedNullLength() {
+ final PositionedByteRange buffer = new SimplePositionedMutableByteRange(20);
+ final DataType<Number> type = new OrderedNumeric(Order.ASCENDING);
+
+ buffer.setPosition(0);
+ type.encode(buffer, null);
+ type.encode(new SimplePositionedMutableByteRange(20), null);
+
+ assertEquals("encodedLength does not match actual, " + null,
+ buffer.getPosition(), type.encodedLength(null));
+ }
+
+ @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));
+ }
+ }
+ }
+
+ @Test
+ public void testEncodedDoubleLength() {
+ final PositionedByteRange buffer = new SimplePositionedMutableByteRange(20);
+ for (final OrderedNumeric type : new OrderedNumeric[] { new OrderedNumeric(Order.ASCENDING),
+ new OrderedNumeric(Order.DESCENDING) }) {
+ for (final Double val : DOUBLE_VALUES) {
+ buffer.setPosition(0);
+ type.encodeDouble(buffer, val);
+ assertEquals("encodedLength does not match actual, " + val,
+ buffer.getPosition(), type.encodedLength(val));
+ }
+ }
+ }
+}
diff --git a/hbase-common/src/test/java/org/apache/hadoop/hbase/types/TestOrderedString.java b/hbase-common/src/test/java/org/apache/hadoop/hbase/types/TestOrderedString.java
index d616627..71c991b 100644
--- a/hbase-common/src/test/java/org/apache/hadoop/hbase/types/TestOrderedString.java
+++ b/hbase-common/src/test/java/org/apache/hadoop/hbase/types/TestOrderedString.java
@@ -22,6 +22,7 @@ import static org.junit.Assert.assertEquals;
import org.apache.hadoop.hbase.HBaseClassTestRule;
import org.apache.hadoop.hbase.testclassification.MiscTests;
import org.apache.hadoop.hbase.testclassification.SmallTests;
+import org.apache.hadoop.hbase.util.Order;
import org.apache.hadoop.hbase.util.PositionedByteRange;
import org.apache.hadoop.hbase.util.SimplePositionedMutableByteRange;
import org.junit.ClassRule;
@@ -30,26 +31,32 @@ import org.junit.experimental.categories.Category;
@Category({MiscTests.class, SmallTests.class})
public class TestOrderedString {
-
@ClassRule
public static final HBaseClassTestRule CLASS_RULE =
HBaseClassTestRule.forClass(TestOrderedString.class);
- static final String[] VALUES =
+ private static final String[] VALUES =
new String[] { null, "", "1", "22", "333", "4444", "55555", "666666",
- "7777777", "88888888", "999999999" };
+ "7777777", "88888888", "999999999" };
@Test
public void testEncodedLength() {
PositionedByteRange buff = new SimplePositionedMutableByteRange(20);
- for (DataType<String> type : new OrderedString[] { OrderedString.ASCENDING, OrderedString.DESCENDING }) {
- for (String val : VALUES) {
+ 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,
+ assertEquals("encodedLength does not match actual, " + val,
buff.getPosition(), type.encodedLength(val));
}
}
}
+
+ @Test
+ public void testEncodedClassIsFloat() {
+ final DataType<String> type = new OrderedString(Order.ASCENDING);
+
+ assertEquals(String.class, type.encodedClass());
+ }
}
diff --git a/hbase-common/src/test/java/org/apache/hadoop/hbase/types/TestRawBytes.java b/hbase-common/src/test/java/org/apache/hadoop/hbase/types/TestRawBytes.java
new file mode 100644
index 0000000..ca4e9d6e
--- /dev/null
+++ b/hbase-common/src/test/java/org/apache/hadoop/hbase/types/TestRawBytes.java
@@ -0,0 +1,101 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ * <p>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p>
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.hadoop.hbase.types;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
+import java.util.Arrays;
+import org.apache.hadoop.hbase.HBaseClassTestRule;
+import org.apache.hadoop.hbase.testclassification.MiscTests;
+import org.apache.hadoop.hbase.testclassification.SmallTests;
+import org.apache.hadoop.hbase.util.Bytes;
+import org.apache.hadoop.hbase.util.Order;
+import org.apache.hadoop.hbase.util.PositionedByteRange;
+import org.apache.hadoop.hbase.util.SimplePositionedMutableByteRange;
+import org.junit.ClassRule;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.experimental.categories.Category;
+import org.junit.rules.ExpectedException;
+
+@Category({MiscTests.class, SmallTests.class})
+public class TestRawBytes {
+ private static final byte[][] VALUES = new byte[][] {
+ Bytes.toBytes(""), Bytes.toBytes("1"), Bytes.toBytes("22"), Bytes.toBytes("333"),
+ Bytes.toBytes("4444"), Bytes.toBytes("55555"), Bytes.toBytes("666666"),
+ Bytes.toBytes("7777777"), Bytes.toBytes("88888888"), Bytes.toBytes("999999999"),
+ };
+
+ @ClassRule
+ public static final HBaseClassTestRule CLASS_RULE =
+ HBaseClassTestRule.forClass(TestRawBytes.class);
+
+ @Rule
+ public ExpectedException exception = ExpectedException.none();
+
+ @Test
+ public void testIsOrderPreservingIsTrue() {
+ final DataType<byte[]> type = new RawBytes(Order.ASCENDING);
+
+ assertTrue(type.isOrderPreserving());
+ }
+
+ @Test
+ public void testGetOrderCorrectOrder() {
+ final DataType<byte[]> type = new RawBytes(Order.ASCENDING);
+
+ assertEquals(Order.ASCENDING, type.getOrder());
+ }
+
+ @Test
+ public void testIsNullableIsFalse() {
+ final DataType<byte[]> type = new RawBytes(Order.ASCENDING);
+
+ assertFalse(type.isNullable());
+ }
+
+ @Test
+ public void testIsSkippableIsFalse() {
+ final DataType<byte[]> type = new RawBytes(Order.ASCENDING);
+
+ assertFalse(type.isSkippable());
+ }
+
+ @Test
+ public void testEncodedClassIsByteArray() {
+ final DataType<byte[]> type = new RawBytes(Order.ASCENDING);
+
+ assertEquals(byte[].class, type.encodedClass());
+ }
+
+ @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));
+ }
+ }
+ }
+}
diff --git a/hbase-common/src/test/java/org/apache/hadoop/hbase/types/TestRawString.java b/hbase-common/src/test/java/org/apache/hadoop/hbase/types/TestRawString.java
index b1bfe75..d3e0409 100644
--- a/hbase-common/src/test/java/org/apache/hadoop/hbase/types/TestRawString.java
+++ b/hbase-common/src/test/java/org/apache/hadoop/hbase/types/TestRawString.java
@@ -19,6 +19,8 @@ package org.apache.hadoop.hbase.types;
import static org.junit.Assert.assertArrayEquals;
import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
import org.apache.hadoop.hbase.HBaseClassTestRule;
import org.apache.hadoop.hbase.testclassification.MiscTests;
@@ -33,24 +35,59 @@ import org.junit.experimental.categories.Category;
@Category({MiscTests.class, SmallTests.class})
public class TestRawString {
-
@ClassRule
public static final HBaseClassTestRule CLASS_RULE =
HBaseClassTestRule.forClass(TestRawString.class);
- static final String[] VALUES = new String[] {
+ private static final String[] VALUES = new String[] {
"", "1", "22", "333", "4444", "55555", "666666", "7777777", "88888888", "999999999",
};
@Test
+ public void testIsOrderPreservingIsTrue() {
+ final DataType<String> type = new RawString(Order.ASCENDING);
+
+ assertTrue(type.isOrderPreserving());
+ }
+
+ @Test
+ public void testGetOrderIsCorrectOrder() {
+ final DataType<String> type = new RawString(Order.ASCENDING);
+
+ assertEquals(Order.ASCENDING, type.getOrder());
+ }
+
+ @Test
+ public void testIsNullableIsFalse() {
+ final DataType<String> type = new RawString(Order.ASCENDING);
+
+ assertFalse(type.isNullable());
+ }
+
+ @Test
+ public void testIsSkippableIsFalse() {
+ final DataType<String> type = new RawString(Order.ASCENDING);
+
+ assertFalse(type.isSkippable());
+ }
+
+ @Test
+ public void testEncodedClassIsString() {
+ final DataType<String> type = new RawString(Order.ASCENDING);
+
+ assertEquals(String.class, type.encodedClass());
+ }
+
+ @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 SimplePositionedMutableByteRange(Bytes.toBytes(val).length);
+ 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));
- byte[] expected = Bytes.toBytes(val);
+ final byte[] expected = Bytes.toBytes(val);
ord.apply(expected);
assertArrayEquals(expected, buff.getBytes());
buff.setPosition(0);
diff --git a/hbase-common/src/test/java/org/apache/hadoop/hbase/types/TestStruct.java b/hbase-common/src/test/java/org/apache/hadoop/hbase/types/TestStruct.java
index d1a0fa6..428d130 100644
--- a/hbase-common/src/test/java/org/apache/hadoop/hbase/types/TestStruct.java
+++ b/hbase-common/src/test/java/org/apache/hadoop/hbase/types/TestStruct.java
@@ -361,7 +361,7 @@ public class TestStruct {
new RawBytesTerminated(Order.DESCENDING, "/");
private static RawStringTerminated stringField =
new RawStringTerminated(Order.DESCENDING, new byte[] { 0x00 });
- private static RawBytes byteField3 = RawBytes.DESCENDING;
+ private static RawBytes byteField3 = new RawBytes(Order.DESCENDING);
/**
* The {@link Struct} equivalent of this type.
diff --git a/hbase-common/src/test/java/org/apache/hadoop/hbase/types/TestStructNullExtension.java b/hbase-common/src/test/java/org/apache/hadoop/hbase/types/TestStructNullExtension.java
index a1a6205..565dd7c 100644
--- a/hbase-common/src/test/java/org/apache/hadoop/hbase/types/TestStructNullExtension.java
+++ b/hbase-common/src/test/java/org/apache/hadoop/hbase/types/TestStructNullExtension.java
@@ -26,6 +26,7 @@ import java.util.Arrays;
import org.apache.hadoop.hbase.HBaseClassTestRule;
import org.apache.hadoop.hbase.testclassification.MiscTests;
import org.apache.hadoop.hbase.testclassification.SmallTests;
+import org.apache.hadoop.hbase.util.Order;
import org.apache.hadoop.hbase.util.PositionedByteRange;
import org.apache.hadoop.hbase.util.SimplePositionedMutableByteRange;
import org.junit.ClassRule;
@@ -57,14 +58,14 @@ public class TestStructNullExtension {
@Test
public void testNullableNullExtension() {
// the following field members are used because they're all nullable
- StructBuilder builder = new StructBuilder()
- .add(OrderedNumeric.ASCENDING)
- .add(OrderedString.ASCENDING);
+ final StructBuilder builder = new StructBuilder()
+ .add(new OrderedNumeric(Order.ASCENDING))
+ .add(new OrderedString(Order.ASCENDING));
Struct shorter = builder.toStruct();
- Struct longer = builder
+ final Struct longer = builder
// intentionally include a wrapped instance to test wrapper behavior.
- .add(new TerminatedWrapper<>(OrderedString.ASCENDING, "/"))
- .add(OrderedNumeric.ASCENDING)
+ .add(new TerminatedWrapper<>(new OrderedString(Order.ASCENDING), "/"))
+ .add(new OrderedNumeric(Order.ASCENDING))
.toStruct();
PositionedByteRange buf1 = new SimplePositionedMutableByteRange(7);
diff --git a/hbase-common/src/test/java/org/apache/hadoop/hbase/types/TestTerminatedWrapper.java b/hbase-common/src/test/java/org/apache/hadoop/hbase/types/TestTerminatedWrapper.java
index 02b36ab..09a1752 100644
--- a/hbase-common/src/test/java/org/apache/hadoop/hbase/types/TestTerminatedWrapper.java
+++ b/hbase-common/src/test/java/org/apache/hadoop/hbase/types/TestTerminatedWrapper.java
@@ -53,7 +53,7 @@ public class TestTerminatedWrapper {
@Test(expected = IllegalArgumentException.class)
public void testEmptyDelimiter() {
- new TerminatedWrapper<>(new RawBytes(), "");
+ new TerminatedWrapper<>(new RawBytes(Order.ASCENDING), "");
}
@Test(expected = IllegalArgumentException.class)
@@ -64,21 +64,21 @@ public class TestTerminatedWrapper {
@Test(expected = IllegalArgumentException.class)
public void testEncodedValueContainsTerm() {
- DataType<byte[]> type = new TerminatedWrapper<>(new RawBytes(), "foo");
- PositionedByteRange buff = new SimplePositionedMutableByteRange(16);
+ final DataType<byte[]> type = new TerminatedWrapper<>(new RawBytes(Order.ASCENDING), "foo");
+ final PositionedByteRange buff = new SimplePositionedMutableByteRange(16);
type.encode(buff, Bytes.toBytes("hello foobar!"));
}
@Test
public void testReadWriteSkippable() {
- PositionedByteRange buff = new SimplePositionedMutableByteRange(14);
- for (OrderedString t : new OrderedString[] {
- OrderedString.ASCENDING, OrderedString.DESCENDING
+ final PositionedByteRange buff = new SimplePositionedMutableByteRange(14);
+ for (final OrderedString t : new OrderedString[] {
+ new OrderedString(Order.ASCENDING), new OrderedString(Order.DESCENDING)
}) {
- for (byte[] term : TERMINATORS) {
- for (String val : VALUES_STRINGS) {
+ for (final byte[] term : TERMINATORS) {
+ for (final String val : VALUES_STRINGS) {
buff.setPosition(0);
- DataType<String> type = new TerminatedWrapper<>(t, term);
+ 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));
@@ -107,15 +107,15 @@ public class TestTerminatedWrapper {
@Test
public void testSkipSkippable() {
- PositionedByteRange buff = new SimplePositionedMutableByteRange(14);
- for (OrderedString t : new OrderedString[] {
- OrderedString.ASCENDING, OrderedString.DESCENDING
+ final PositionedByteRange buff = new SimplePositionedMutableByteRange(14);
+ for (final OrderedString t : new OrderedString[] {
+ new OrderedString(Order.ASCENDING), new OrderedString(Order.DESCENDING)
}) {
- for (byte[] term : TERMINATORS) {
- for (String val : VALUES_STRINGS) {
+ for (final byte[] term : TERMINATORS) {
+ for (final String val : VALUES_STRINGS) {
buff.setPosition(0);
- DataType<String> type = new TerminatedWrapper<>(t, term);
- int expected = val.length() + 2 + term.length;
+ 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));
@@ -144,8 +144,9 @@ public class TestTerminatedWrapper {
@Test(expected = IllegalArgumentException.class)
public void testInvalidSkip() {
- PositionedByteRange buff = new SimplePositionedMutableByteRange(Bytes.toBytes("foo"));
- DataType<byte[]> type = new TerminatedWrapper<>(new RawBytes(), new byte[] { 0x00 });
+ final PositionedByteRange buff = new SimplePositionedMutableByteRange(Bytes.toBytes("foo"));
+ final DataType<byte[]> type = new TerminatedWrapper<>(new RawBytes(Order.ASCENDING),
+ new byte[] { 0x00 });
type.skip(buff);
}
}