org.apache.hadoop.hive.serde2.thrift
Class TBinarySortableProtocol

java.lang.Object
  extended by org.apache.thrift.protocol.TProtocol
      extended by org.apache.hadoop.hive.serde2.thrift.TBinarySortableProtocol
All Implemented Interfaces:
ConfigurableTProtocol, WriteNullsProtocol, WriteTextProtocol

public class TBinarySortableProtocol
extends org.apache.thrift.protocol.TProtocol
implements ConfigurableTProtocol, WriteNullsProtocol, WriteTextProtocol

An implementation of the Thrift Protocol for binary sortable records. The data format: NULL: a single byte \0 NON-NULL Primitives: ALWAYS prepend a single byte \1, and then: Boolean: FALSE = \1, TRUE = \2 Byte: flip the sign-bit to make sure negative comes before positive Short: flip the sign-bit to make sure negative comes before positive Int: flip the sign-bit to make sure negative comes before positive Long: flip the sign-bit to make sure negative comes before positive Double: flip the sign-bit for positive double, and all bits for negative double values String: NULL-terminated UTF-8 string, with NULL escaped to \1 \1, and \1 escaped to \1 \2 NON-NULL Complex Types: Struct: first the single byte \1, and then one field by one field. List: size stored as Int (see above), then one element by one element. Map: size stored as Int (see above), then one key by one value, and then the next pair and so on. Binary: size stored as Int (see above), then the binary data in its original form Note that the relative order of list/map/binary will be based on the size first (and elements one by one if the sizes are equal). This protocol takes an additional parameter SERIALIZATION_SORT_ORDER which is a string containing only "+" and "-". The length of the string should equal to the number of fields in the top-level struct for serialization. "+" means the field should be sorted ascendingly, and "-" means descendingly. The sub fields in the same top-level field will have the same sort order. This is not thrift compliant in that it doesn't write out field ids so things cannot actually be versioned.


Nested Class Summary
static class TBinarySortableProtocol.Factory
          Factory for TBinarySortableProtocol objects.
 
Field Summary
protected  byte[] escapedNull
          The escaped byte sequence for the null byte.
protected  byte[] escapedOne
          The escaped byte sequence for the "\1" byte.
protected  byte[] nonNullByte
           
protected  byte[] nullByte
           
 
Fields inherited from class org.apache.thrift.protocol.TProtocol
trans_
 
Constructor Summary
TBinarySortableProtocol(org.apache.thrift.transport.TTransport trans)
           
 
Method Summary
 void initialize(org.apache.hadoop.conf.Configuration conf, Properties tbl)
          Initialize the TProtocol.
 boolean lastPrimitiveWasNull()
          Was the last primitive read really a NULL.
 byte[] readBinary()
           
 boolean readBool()
           
 byte readByte()
           
 double readDouble()
           
 org.apache.thrift.protocol.TField readFieldBegin()
           
 void readFieldEnd()
           
 short readI16()
           
 int readI32()
           
 long readI64()
           
 boolean readIsNull()
           
 org.apache.thrift.protocol.TList readListBegin()
          This method always return the same instance of TList to avoid creating new instances.
 void readListEnd()
           
 org.apache.thrift.protocol.TMap readMapBegin()
          This method always return the same instance of TMap to avoid creating new instances.
 void readMapEnd()
           
 org.apache.thrift.protocol.TMessage readMessageBegin()
           
 void readMessageEnd()
           
 org.apache.thrift.protocol.TSet readSetBegin()
          This method always return the same instance of TSet to avoid creating new instances.
 void readSetEnd()
           
 String readString()
           
 org.apache.thrift.protocol.TStruct readStructBegin()
           
 void readStructEnd()
           
 void writeBinary(byte[] bin)
           
 void writeBool(boolean b)
           
 void writeByte(byte b)
           
 void writeDouble(double dub)
           
 void writeFieldBegin(org.apache.thrift.protocol.TField field)
           
 void writeFieldEnd()
           
 void writeFieldStop()
           
 void writeI16(short i16)
           
 void writeI32(int i32)
           
 void writeI64(long i64)
           
 void writeListBegin(org.apache.thrift.protocol.TList list)
           
 void writeListEnd()
           
 void writeMapBegin(org.apache.thrift.protocol.TMap map)
           
 void writeMapEnd()
           
 void writeMessageBegin(org.apache.thrift.protocol.TMessage message)
           
 void writeMessageEnd()
           
 void writeNull()
          Write a null.
 void writeSetBegin(org.apache.thrift.protocol.TSet set)
           
 void writeSetEnd()
           
 void writeString(String str)
           
 void writeStructBegin(org.apache.thrift.protocol.TStruct struct)
           
 void writeStructEnd()
           
 void writeText(org.apache.hadoop.io.Text text)
          Write Text.
 
Methods inherited from class org.apache.thrift.protocol.TProtocol
getTransport
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

nullByte

protected final byte[] nullByte

nonNullByte

protected final byte[] nonNullByte

escapedNull

protected final byte[] escapedNull
The escaped byte sequence for the null byte. This cannot be changed alone without changing the readString() code.


escapedOne

protected final byte[] escapedOne
The escaped byte sequence for the "\1" byte. This cannot be changed alone without changing the readString() code.

Constructor Detail

TBinarySortableProtocol

public TBinarySortableProtocol(org.apache.thrift.transport.TTransport trans)
Method Detail

initialize

public void initialize(org.apache.hadoop.conf.Configuration conf,
                       Properties tbl)
                throws org.apache.thrift.TException
Description copied from interface: ConfigurableTProtocol
Initialize the TProtocol.

Specified by:
initialize in interface ConfigurableTProtocol
Parameters:
conf - System properties
tbl - table properties
Throws:
org.apache.thrift.TException

writeMessageBegin

public void writeMessageBegin(org.apache.thrift.protocol.TMessage message)
                       throws org.apache.thrift.TException
Specified by:
writeMessageBegin in class org.apache.thrift.protocol.TProtocol
Throws:
org.apache.thrift.TException

writeMessageEnd

public void writeMessageEnd()
                     throws org.apache.thrift.TException
Specified by:
writeMessageEnd in class org.apache.thrift.protocol.TProtocol
Throws:
org.apache.thrift.TException

writeStructBegin

public void writeStructBegin(org.apache.thrift.protocol.TStruct struct)
                      throws org.apache.thrift.TException
Specified by:
writeStructBegin in class org.apache.thrift.protocol.TProtocol
Throws:
org.apache.thrift.TException

writeStructEnd

public void writeStructEnd()
                    throws org.apache.thrift.TException
Specified by:
writeStructEnd in class org.apache.thrift.protocol.TProtocol
Throws:
org.apache.thrift.TException

writeFieldBegin

public void writeFieldBegin(org.apache.thrift.protocol.TField field)
                     throws org.apache.thrift.TException
Specified by:
writeFieldBegin in class org.apache.thrift.protocol.TProtocol
Throws:
org.apache.thrift.TException

writeFieldEnd

public void writeFieldEnd()
                   throws org.apache.thrift.TException
Specified by:
writeFieldEnd in class org.apache.thrift.protocol.TProtocol
Throws:
org.apache.thrift.TException

writeFieldStop

public void writeFieldStop()
Specified by:
writeFieldStop in class org.apache.thrift.protocol.TProtocol

writeMapBegin

public void writeMapBegin(org.apache.thrift.protocol.TMap map)
                   throws org.apache.thrift.TException
Specified by:
writeMapBegin in class org.apache.thrift.protocol.TProtocol
Throws:
org.apache.thrift.TException

writeMapEnd

public void writeMapEnd()
                 throws org.apache.thrift.TException
Specified by:
writeMapEnd in class org.apache.thrift.protocol.TProtocol
Throws:
org.apache.thrift.TException

writeListBegin

public void writeListBegin(org.apache.thrift.protocol.TList list)
                    throws org.apache.thrift.TException
Specified by:
writeListBegin in class org.apache.thrift.protocol.TProtocol
Throws:
org.apache.thrift.TException

writeListEnd

public void writeListEnd()
                  throws org.apache.thrift.TException
Specified by:
writeListEnd in class org.apache.thrift.protocol.TProtocol
Throws:
org.apache.thrift.TException

writeSetBegin

public void writeSetBegin(org.apache.thrift.protocol.TSet set)
                   throws org.apache.thrift.TException
Specified by:
writeSetBegin in class org.apache.thrift.protocol.TProtocol
Throws:
org.apache.thrift.TException

writeSetEnd

public void writeSetEnd()
                 throws org.apache.thrift.TException
Specified by:
writeSetEnd in class org.apache.thrift.protocol.TProtocol
Throws:
org.apache.thrift.TException

writeBool

public void writeBool(boolean b)
               throws org.apache.thrift.TException
Specified by:
writeBool in class org.apache.thrift.protocol.TProtocol
Throws:
org.apache.thrift.TException

writeByte

public void writeByte(byte b)
               throws org.apache.thrift.TException
Specified by:
writeByte in class org.apache.thrift.protocol.TProtocol
Throws:
org.apache.thrift.TException

writeI16

public void writeI16(short i16)
              throws org.apache.thrift.TException
Specified by:
writeI16 in class org.apache.thrift.protocol.TProtocol
Throws:
org.apache.thrift.TException

writeI32

public void writeI32(int i32)
              throws org.apache.thrift.TException
Specified by:
writeI32 in class org.apache.thrift.protocol.TProtocol
Throws:
org.apache.thrift.TException

writeI64

public void writeI64(long i64)
              throws org.apache.thrift.TException
Specified by:
writeI64 in class org.apache.thrift.protocol.TProtocol
Throws:
org.apache.thrift.TException

writeDouble

public void writeDouble(double dub)
                 throws org.apache.thrift.TException
Specified by:
writeDouble in class org.apache.thrift.protocol.TProtocol
Throws:
org.apache.thrift.TException

writeString

public void writeString(String str)
                 throws org.apache.thrift.TException
Specified by:
writeString in class org.apache.thrift.protocol.TProtocol
Throws:
org.apache.thrift.TException

writeBinary

public void writeBinary(byte[] bin)
                 throws org.apache.thrift.TException
Specified by:
writeBinary in class org.apache.thrift.protocol.TProtocol
Throws:
org.apache.thrift.TException

readMessageBegin

public org.apache.thrift.protocol.TMessage readMessageBegin()
                                                     throws org.apache.thrift.TException
Specified by:
readMessageBegin in class org.apache.thrift.protocol.TProtocol
Throws:
org.apache.thrift.TException

readMessageEnd

public void readMessageEnd()
                    throws org.apache.thrift.TException
Specified by:
readMessageEnd in class org.apache.thrift.protocol.TProtocol
Throws:
org.apache.thrift.TException

readStructBegin

public org.apache.thrift.protocol.TStruct readStructBegin()
                                                   throws org.apache.thrift.TException
Specified by:
readStructBegin in class org.apache.thrift.protocol.TProtocol
Throws:
org.apache.thrift.TException

readStructEnd

public void readStructEnd()
                   throws org.apache.thrift.TException
Specified by:
readStructEnd in class org.apache.thrift.protocol.TProtocol
Throws:
org.apache.thrift.TException

readFieldBegin

public org.apache.thrift.protocol.TField readFieldBegin()
                                                 throws org.apache.thrift.TException
Specified by:
readFieldBegin in class org.apache.thrift.protocol.TProtocol
Throws:
org.apache.thrift.TException

readFieldEnd

public void readFieldEnd()
                  throws org.apache.thrift.TException
Specified by:
readFieldEnd in class org.apache.thrift.protocol.TProtocol
Throws:
org.apache.thrift.TException

readMapBegin

public org.apache.thrift.protocol.TMap readMapBegin()
                                             throws org.apache.thrift.TException
This method always return the same instance of TMap to avoid creating new instances. It is the responsibility of the caller to read the value before calling this method again.

Specified by:
readMapBegin in class org.apache.thrift.protocol.TProtocol
Throws:
org.apache.thrift.TException

readMapEnd

public void readMapEnd()
                throws org.apache.thrift.TException
Specified by:
readMapEnd in class org.apache.thrift.protocol.TProtocol
Throws:
org.apache.thrift.TException

readListBegin

public org.apache.thrift.protocol.TList readListBegin()
                                               throws org.apache.thrift.TException
This method always return the same instance of TList to avoid creating new instances. It is the responsibility of the caller to read the value before calling this method again.

Specified by:
readListBegin in class org.apache.thrift.protocol.TProtocol
Throws:
org.apache.thrift.TException

readListEnd

public void readListEnd()
                 throws org.apache.thrift.TException
Specified by:
readListEnd in class org.apache.thrift.protocol.TProtocol
Throws:
org.apache.thrift.TException

readSetBegin

public org.apache.thrift.protocol.TSet readSetBegin()
                                             throws org.apache.thrift.TException
This method always return the same instance of TSet to avoid creating new instances. It is the responsibility of the caller to read the value before calling this method again.

Specified by:
readSetBegin in class org.apache.thrift.protocol.TProtocol
Throws:
org.apache.thrift.TException

readSetEnd

public void readSetEnd()
                throws org.apache.thrift.TException
Specified by:
readSetEnd in class org.apache.thrift.protocol.TProtocol
Throws:
org.apache.thrift.TException

readBool

public boolean readBool()
                 throws org.apache.thrift.TException
Specified by:
readBool in class org.apache.thrift.protocol.TProtocol
Throws:
org.apache.thrift.TException

readIsNull

public final boolean readIsNull()
                         throws org.apache.thrift.TException
Throws:
org.apache.thrift.TException

readByte

public byte readByte()
              throws org.apache.thrift.TException
Specified by:
readByte in class org.apache.thrift.protocol.TProtocol
Throws:
org.apache.thrift.TException

readI16

public short readI16()
              throws org.apache.thrift.TException
Specified by:
readI16 in class org.apache.thrift.protocol.TProtocol
Throws:
org.apache.thrift.TException

readI32

public int readI32()
            throws org.apache.thrift.TException
Specified by:
readI32 in class org.apache.thrift.protocol.TProtocol
Throws:
org.apache.thrift.TException

readI64

public long readI64()
             throws org.apache.thrift.TException
Specified by:
readI64 in class org.apache.thrift.protocol.TProtocol
Throws:
org.apache.thrift.TException

readDouble

public double readDouble()
                  throws org.apache.thrift.TException
Specified by:
readDouble in class org.apache.thrift.protocol.TProtocol
Throws:
org.apache.thrift.TException

readString

public String readString()
                  throws org.apache.thrift.TException
Specified by:
readString in class org.apache.thrift.protocol.TProtocol
Throws:
org.apache.thrift.TException

readBinary

public byte[] readBinary()
                  throws org.apache.thrift.TException
Specified by:
readBinary in class org.apache.thrift.protocol.TProtocol
Throws:
org.apache.thrift.TException

lastPrimitiveWasNull

public boolean lastPrimitiveWasNull()
                             throws org.apache.thrift.TException
Description copied from interface: WriteNullsProtocol
Was the last primitive read really a NULL. Need only be called when the value of the primitive was 0. ie the protocol should return 0 on nulls and the caller will then check if it was actually null For boolean this is false.

Specified by:
lastPrimitiveWasNull in interface WriteNullsProtocol
Throws:
org.apache.thrift.TException

writeNull

public void writeNull()
               throws org.apache.thrift.TException
Description copied from interface: WriteNullsProtocol
Write a null.

Specified by:
writeNull in interface WriteNullsProtocol
Throws:
org.apache.thrift.TException

writeText

public void writeText(org.apache.hadoop.io.Text text)
               throws org.apache.thrift.TException
Description copied from interface: WriteTextProtocol
Write Text.

Specified by:
writeText in interface WriteTextProtocol
Throws:
org.apache.thrift.TException


Copyright © 2010 The Apache Software Foundation