org.apache.hadoop.hive.serde2.lazy
Class LazySimpleSerDe

java.lang.Object
  extended by org.apache.hadoop.hive.serde2.lazy.LazySimpleSerDe
All Implemented Interfaces:
Deserializer, SerDe, Serializer
Direct Known Subclasses:
DelimitedJSONSerDe

public class LazySimpleSerDe
extends Object
implements SerDe

LazySimpleSerDe can be used to read the same data format as MetadataTypedColumnsetSerDe and TCTLSeparatedProtocol. However, LazySimpleSerDe creates Objects in a lazy way, to provide better performance. Also LazySimpleSerDe outputs typed columns instead of treating all columns as String like MetadataTypedColumnsetSerDe.


Nested Class Summary
static class LazySimpleSerDe.SerDeParameters
          SerDeParameters.
 
Field Summary
static byte[] DefaultSeparators
           
static org.apache.commons.logging.Log LOG
           
 
Constructor Summary
LazySimpleSerDe()
           
 
Method Summary
 Object deserialize(org.apache.hadoop.io.Writable field)
          Deserialize a row from the Writable to a LazyObject.
static byte getByte(String altValue, byte defaultVal)
          Return the byte value of the number string.
 ObjectInspector getObjectInspector()
          Returns the ObjectInspector for the row.
 SerDeStats getSerDeStats()
          Returns the statistics after (de)serialization)
 Class<? extends org.apache.hadoop.io.Writable> getSerializedClass()
          Returns the Writable Class after serialization.
 void initialize(org.apache.hadoop.conf.Configuration job, Properties tbl)
          Initialize the SerDe given the parameters.
static LazySimpleSerDe.SerDeParameters initSerdeParams(org.apache.hadoop.conf.Configuration job, Properties tbl, String serdeName)
           
static void serialize(ByteStream.Output out, Object obj, ObjectInspector objInspector, byte[] separators, int level, org.apache.hadoop.io.Text nullSequence, boolean escaped, byte escapeChar, boolean[] needsEscape)
          Serialize the row into the StringBuilder.
 org.apache.hadoop.io.Writable serialize(Object obj, ObjectInspector objInspector)
          Serialize a row of data.
protected  void serializeField(ByteStream.Output out, Object obj, ObjectInspector objInspector, LazySimpleSerDe.SerDeParameters serdeParams)
           
 String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

LOG

public static final org.apache.commons.logging.Log LOG

DefaultSeparators

public static final byte[] DefaultSeparators
Constructor Detail

LazySimpleSerDe

public LazySimpleSerDe()
                throws SerDeException
Throws:
SerDeException
Method Detail

toString

public String toString()
Overrides:
toString in class Object

getByte

public static byte getByte(String altValue,
                           byte defaultVal)
Return the byte value of the number string.

Parameters:
altValue - The string containing a number.
defaultVal - If the altValue does not represent a number, return the defaultVal.

initialize

public void initialize(org.apache.hadoop.conf.Configuration job,
                       Properties tbl)
                throws SerDeException
Initialize the SerDe given the parameters. serialization.format: separator char or byte code (only supports byte-value up to 127) columns: ","-separated column names columns.types: ",", ":", or ";"-separated column types

Specified by:
initialize in interface Deserializer
Specified by:
initialize in interface Serializer
Parameters:
job - System properties
tbl - table properties
Throws:
SerDeException
See Also:
Deserializer.initialize(Configuration, Properties)

initSerdeParams

public static LazySimpleSerDe.SerDeParameters initSerdeParams(org.apache.hadoop.conf.Configuration job,
                                                              Properties tbl,
                                                              String serdeName)
                                                       throws SerDeException
Throws:
SerDeException

deserialize

public Object deserialize(org.apache.hadoop.io.Writable field)
                   throws SerDeException
Deserialize a row from the Writable to a LazyObject.

Specified by:
deserialize in interface Deserializer
Parameters:
field - the Writable that contains the data
Returns:
The deserialized row Object.
Throws:
SerDeException
See Also:
Deserializer.deserialize(Writable)

getObjectInspector

public ObjectInspector getObjectInspector()
                                   throws SerDeException
Returns the ObjectInspector for the row.

Specified by:
getObjectInspector in interface Deserializer
Throws:
SerDeException

getSerializedClass

public Class<? extends org.apache.hadoop.io.Writable> getSerializedClass()
Returns the Writable Class after serialization.

Specified by:
getSerializedClass in interface Serializer
See Also:
Serializer.getSerializedClass()

serialize

public org.apache.hadoop.io.Writable serialize(Object obj,
                                               ObjectInspector objInspector)
                                        throws SerDeException
Serialize a row of data.

Specified by:
serialize in interface Serializer
Parameters:
obj - The row object
objInspector - The ObjectInspector for the row object
Returns:
The serialized Writable object
Throws:
IOException
SerDeException
See Also:
Serializer.serialize(Object, ObjectInspector)

serializeField

protected void serializeField(ByteStream.Output out,
                              Object obj,
                              ObjectInspector objInspector,
                              LazySimpleSerDe.SerDeParameters serdeParams)
                       throws SerDeException
Throws:
SerDeException

serialize

public static void serialize(ByteStream.Output out,
                             Object obj,
                             ObjectInspector objInspector,
                             byte[] separators,
                             int level,
                             org.apache.hadoop.io.Text nullSequence,
                             boolean escaped,
                             byte escapeChar,
                             boolean[] needsEscape)
                      throws IOException
Serialize the row into the StringBuilder.

Parameters:
out - The StringBuilder to store the serialized data.
obj - The object for the current field.
objInspector - The ObjectInspector for the current Object.
separators - The separators array.
level - The current level of separator.
nullSequence - The byte sequence representing the NULL value.
escaped - Whether we need to escape the data when writing out
escapeChar - Which char to use as the escape char, e.g. '\\'
needsEscape - Which chars needs to be escaped. This array should have size of 128. Negative byte values (or byte values >= 128) are never escaped.
Throws:
IOException

getSerDeStats

public SerDeStats getSerDeStats()
Returns the statistics after (de)serialization)

Specified by:
getSerDeStats in interface Deserializer
Specified by:
getSerDeStats in interface Serializer


Copyright © 2011 The Apache Software Foundation