Interface DataType<T>
- All Known Implementing Classes:
FixedLengthWrapper
,OrderedBlob
,OrderedBlobVar
,OrderedBytesBase
,OrderedFloat32
,OrderedFloat64
,OrderedInt16
,OrderedInt32
,OrderedInt64
,OrderedInt8
,OrderedNumeric
,OrderedString
,PBCell
,PBType
,RawByte
,RawBytes
,RawBytesFixedLength
,RawBytesTerminated
,RawDouble
,RawFloat
,RawInteger
,RawLong
,RawShort
,RawString
,RawStringFixedLength
,RawStringTerminated
,Struct
,TerminatedWrapper
,Union2
,Union3
,Union4
DataType
is the base class for all HBase data types. Data type implementations are
designed to be serialized to and deserialized from byte[]. Serialized representations can retain
the natural sort ordering of the source object, when a suitable encoding is supported by the
underlying implementation. This is a desirable feature for use in rowkeys and column qualifiers.
DataType
s are different from Hadoop
ImmutableBytesWritable
s in two significant ways. First,
DataType
describes how to serialize a value, it does not encapsulate a serialized value.
Second, DataType
implementations provide hints to consumers about relationships between
the POJOs they represent and richness of the encoded representation.
Data type instances are designed to be stateless, thread-safe, and reused. Implementations should
provide static final
instances corresponding to each variation on configurable
parameters. This is to encourage and simplify instance reuse. For instance, order-preserving
types should provide static ASCENDING and DESCENDING instances. It is also encouraged for
implementations operating on Java primitive types to provide primitive implementations of the
encode
and decode
methods. This advice is a performance consideration to clients
reading and writing values in tight loops.
-
Method Summary
Modifier and TypeMethodDescriptionRead an instance ofT
from the buffersrc
.int
encode
(PositionedByteRange dst, T val) Write instanceval
into bufferdst
.Inform consumers over what type thisDataType
operates.int
encodedLength
(T val) Inform consumers how long the encodedbyte[]
will be.getOrder()
Retrieve the sortOrder
imposed by this data type, or null when natural ordering is not preserved.boolean
Indicates whether this instance supports encoding null values.boolean
Indicates whether this instance writes encodedbyte[]
's which preserve the natural sort order of the unencoded value.boolean
Indicates whether this instance is able to skip over it's encoded value.int
skip
(PositionedByteRange src) Skipsrc
's position forward over one encoded value.
-
Method Details
-
isOrderPreserving
boolean isOrderPreserving()Indicates whether this instance writes encodedbyte[]
's which preserve the natural sort order of the unencoded value.- Returns:
true
when natural order is preserved,false
otherwise.
-
getOrder
Retrieve the sortOrder
imposed by this data type, or null when natural ordering is not preserved. Value is either ascending or descending. Default is assumed to beOrder.ASCENDING
. -
isNullable
boolean isNullable()Indicates whether this instance supports encoding null values. This depends on the implementation details of the encoding format. AllDataType
s that support null should treat null as comparing less than any non-null value for default sort ordering purposes.- Returns:
true
when null is supported,false
otherwise.
-
isSkippable
boolean isSkippable()Indicates whether this instance is able to skip over it's encoded value.DataType
s that are not skippable can only be used as the right-most field of aStruct
. -
encodedLength
Inform consumers how long the encodedbyte[]
will be.- Parameters:
val
- The value to check.- Returns:
- the number of bytes required to encode
val
.a
-
encodedClass
Class<T> encodedClass()Inform consumers over what type thisDataType
operates. Useful when working with bareDataType
instances. -
skip
Skipsrc
's position forward over one encoded value.- Parameters:
src
- the buffer containing the encoded value.- Returns:
- number of bytes skipped.
-
decode
Read an instance ofT
from the buffersrc
.- Parameters:
src
- the buffer containing the encoded value.
-
encode
Write instanceval
into bufferdst
.- Parameters:
dst
- the buffer containing the encoded value.val
- the value to encode ontodst
.- Returns:
- number of bytes written.
-