org.apache.hadoop.hbase.types
Class Struct

java.lang.Object
  extended by org.apache.hadoop.hbase.types.Struct
All Implemented Interfaces:
DataType<Object[]>

@InterfaceAudience.Public
@InterfaceStability.Evolving
public class Struct
extends Object
implements DataType<Object[]>

Struct is a simple DataType for implementing "compound rowkey" and "compound qualifier" schema design strategies.

Encoding

Struct member values are encoded onto the target byte[] in the order in which they are declared. A Struct may be used as a member of another Struct. Structs are not nullable but their component fields may be.

Sort Order

Struct instances sort according to the composite order of their fields, that is, left-to-right and depth-first. This can also be thought of as lexicographic comparison of concatenated members.

StructIterator is provided as a convenience for consuming the sequence of values. Users may find it more appropriate to provide their own custom DataType for encoding application objects rather than using this Object[] implementation. Examples are provided in test.

See Also:
StructIterator, DataType.isNullable()

Field Summary
protected  DataType[] fields
           
protected  boolean isOrderPreserving
           
protected  boolean isSkippable
           
 
Constructor Summary
Struct(DataType[] memberTypes)
          Create a new Struct instance defined as the sequence of HDataTypes in memberTypes.
 
Method Summary
 Object[] decode(PositionedByteRange src)
          Read an instance of T from the buffer src.
 Object decode(PositionedByteRange src, int index)
          Read the field at index.
 int encode(PositionedByteRange dst, Object[] val)
          Write instance val into buffer dst.
 Class<Object[]> encodedClass()
          Inform consumers over what type this DataType operates.
 int encodedLength(Object[] 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.
 StructIterator iterator(PositionedByteRange src)
          Retrieve an Iterator over the values encoded in src.
 int skip(PositionedByteRange src)
          Skip src's position forward over one encoded value.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

fields

protected final DataType[] fields

isOrderPreserving

protected final boolean isOrderPreserving

isSkippable

protected final boolean isSkippable
Constructor Detail

Struct

public Struct(DataType[] memberTypes)
Create a new Struct instance defined as the sequence of HDataTypes in memberTypes.

A Struct is orderPreserving when all of its fields are orderPreserving. A Struct is skippable when all of its fields are skippable.

Method Detail

isOrderPreserving

public boolean isOrderPreserving()
Description copied from interface: DataType
Indicates whether this instance writes encoded byte[]'s which preserve the natural sort order of the unencoded value.

Specified by:
isOrderPreserving in interface DataType<Object[]>
Returns:
true when natural order is preserved, false otherwise.

getOrder

public Order getOrder()
Description copied from interface: DataType
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.

Specified by:
getOrder in interface DataType<Object[]>

isNullable

public boolean isNullable()
Description copied from interface: DataType
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.

Specified by:
isNullable in interface DataType<Object[]>
Returns:
true when null is supported, false otherwise.

isSkippable

public boolean isSkippable()
Description copied from interface: DataType
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.

Specified by:
isSkippable in interface DataType<Object[]>

encodedLength

public int encodedLength(Object[] val)
Description copied from interface: DataType
Inform consumers how long the encoded byte[] will be.

Specified by:
encodedLength in interface DataType<Object[]>
Parameters:
val - The value to check.
Returns:
the number of bytes required to encode val.a

encodedClass

public Class<Object[]> encodedClass()
Description copied from interface: DataType
Inform consumers over what type this DataType operates. Useful when working with bare DataType instances.

Specified by:
encodedClass in interface DataType<Object[]>

iterator

public StructIterator iterator(PositionedByteRange src)
Retrieve an Iterator over the values encoded in src. src's position is consumed by consuming this iterator.


skip

public int skip(PositionedByteRange src)
Description copied from interface: DataType
Skip src's position forward over one encoded value.

Specified by:
skip in interface DataType<Object[]>
Parameters:
src - the buffer containing the encoded value.
Returns:
number of bytes skipped.

decode

public Object[] decode(PositionedByteRange src)
Description copied from interface: DataType
Read an instance of T from the buffer src.

Specified by:
decode in interface DataType<Object[]>
Parameters:
src - the buffer containing the encoded value.

decode

public Object decode(PositionedByteRange src,
                     int index)
Read the field at index. src's position is not affected.


encode

public int encode(PositionedByteRange dst,
                  Object[] val)
Description copied from interface: DataType
Write instance val into buffer dst.

Specified by:
encode in interface DataType<Object[]>
Parameters:
dst - the buffer containing the encoded value.
val - the value to encode onto dst.
Returns:
number of bytes written.


Copyright © 2013 The Apache Software Foundation. All Rights Reserved.