org.apache.hadoop.hbase.types
Interface DataType<T>

All Known Implementing Classes:
FixedLengthWrapper, OrderedBlob, OrderedBlobVar, OrderedBytesBase, OrderedFloat32, OrderedFloat64, OrderedInt16, OrderedInt32, OrderedInt64, OrderedInt8, OrderedNumeric, OrderedString, PBType, RawByte, RawBytes, RawBytesFixedLength, RawBytesTerminated, RawDouble, RawFloat, RawInteger, RawLong, RawShort, RawString, RawStringFixedLength, RawStringTerminated, Struct, TerminatedWrapper, Union2, Union3, Union4

@InterfaceAudience.Public
@InterfaceStability.Evolving
public interface DataType<T>

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.

DataTypes are different from Hadoop Writables 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
 T decode(PositionedByteRange src)
          Read an instance of T from the buffer src.
 int encode(PositionedByteRange dst, T val)
          Write instance val into buffer dst.
 Class<T> encodedClass()
          Inform consumers over what type this DataType operates.
 int encodedLength(T val)
          Inform consumers how long the encoded byte[] will be.
 Order getOrder()
          Retrieve the sort Order imposed by this data type, or null when natural ordering is not preserved.
 boolean isNullable()
          Indicates whether this instance supports encoding null values.
 boolean isOrderPreserving()
          Indicates whether this instance writes encoded byte[]'s which preserve the natural sort order of the unencoded value.
 boolean isSkippable()
          Indicates whether this instance is able to skip over it's encoded value.
 int skip(PositionedByteRange src)
          Skip src's position forward over one encoded value.
 

Method Detail

isOrderPreserving

boolean isOrderPreserving()
Indicates whether this instance writes encoded byte[]'s which preserve the natural sort order of the unencoded value.

Returns:
true when natural order is preserved, false otherwise.

getOrder

Order getOrder()
Retrieve the sort Order imposed by this data type, or null when natural ordering is not preserved. Value is either ascending or descending. Default is assumed to be Order.ASCENDING.


isNullable

boolean isNullable()
Indicates whether this instance supports encoding null values. This depends on the implementation details of the encoding format. All DataTypes 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. DataTypes that are not skippable can only be used as the right-most field of a Struct.


encodedLength

int encodedLength(T val)
Inform consumers how long the encoded byte[] 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 this DataType operates. Useful when working with bare DataType instances.


skip

int skip(PositionedByteRange src)
Skip src's position forward over one encoded value.

Parameters:
src - the buffer containing the encoded value.
Returns:
number of bytes skipped.

decode

T decode(PositionedByteRange src)
Read an instance of T from the buffer src.

Parameters:
src - the buffer containing the encoded value.

encode

int encode(PositionedByteRange dst,
           T val)
Write instance val into buffer dst.

Parameters:
dst - the buffer containing the encoded value.
val - the value to encode onto dst.
Returns:
number of bytes written.


Copyright © 2007–2015 The Apache Software Foundation. All rights reserved.