org.apache.hadoop.hive.serde2.objectinspector
Class ObjectInspectorUtils

java.lang.Object
  extended by org.apache.hadoop.hive.serde2.objectinspector.ObjectInspectorUtils

public final class ObjectInspectorUtils
extends Object

ObjectInspectorFactory is the primary way to create new ObjectInspector instances. SerDe classes should call the static functions in this library to create an ObjectInspector to return to the caller of SerDe2.getObjectInspector().


Nested Class Summary
static class ObjectInspectorUtils.ObjectInspectorCopyOption
          This enum controls how we copy primitive objects.
 
Field Summary
protected static org.apache.commons.logging.Log LOG
           
 
Method Summary
static int compare(Object[] o1, ObjectInspector[] oi1, Object[] o2, ObjectInspector[] oi2)
          Compare two arrays of objects with their respective arrays of ObjectInspectors.
static int compare(Object o1, ObjectInspector oi1, Object o2, ObjectInspector oi2)
          Compare two objects with their respective ObjectInspectors.
static boolean compareSupported(ObjectInspector oi)
          Whether comparison is supported for this type.
static boolean compareTypes(ObjectInspector o1, ObjectInspector o2)
          Compares two types identified by the given object inspectors.
static Object copyToStandardObject(Object o, ObjectInspector oi)
          Returns a deep copy of the Object o that can be scanned by a StandardObjectInspector returned by getStandardObjectInspector(oi).
static Object copyToStandardObject(Object o, ObjectInspector oi, ObjectInspectorUtils.ObjectInspectorCopyOption objectInspectorOption)
           
static Field[] getDeclaredNonStaticFields(Class<?> c)
          Get all the declared non-static fields of Class c.
static String getFieldNames(StructObjectInspector soi)
          Get the list of field names as csv from a StructObjectInspector.
static String getFieldTypes(StructObjectInspector soi)
          Get the list of field type as csv from a StructObjectInspector.
static String getObjectInspectorName(ObjectInspector oi)
          Get the class names of the ObjectInspector hierarchy.
static ObjectInspector getStandardObjectInspector(ObjectInspector oi)
          Get the corresponding standard ObjectInspector for an ObjectInspector.
static ObjectInspector getStandardObjectInspector(ObjectInspector oi, ObjectInspectorUtils.ObjectInspectorCopyOption objectInspectorOption)
           
static StructField getStandardStructFieldRef(String fieldName, List<? extends StructField> fields)
           
static String getStandardStructTypeName(StructObjectInspector soi)
           
static String getTypeNameFromJavaClass(Type t)
          Get the type name of the Java class.
static int hashCode(Object o, ObjectInspector objIns)
           
static void partialCopyToStandardObject(List<Object> result, Object row, int startCol, int numCols, StructObjectInspector soi, ObjectInspectorUtils.ObjectInspectorCopyOption objectInspectorOption)
          Copy specified fields in the input row to the output array of standard objects.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

LOG

protected static final org.apache.commons.logging.Log LOG
Method Detail

getStandardObjectInspector

public static ObjectInspector getStandardObjectInspector(ObjectInspector oi)
Get the corresponding standard ObjectInspector for an ObjectInspector. The returned ObjectInspector can be used to inspect the standard object.


getStandardObjectInspector

public static ObjectInspector getStandardObjectInspector(ObjectInspector oi,
                                                         ObjectInspectorUtils.ObjectInspectorCopyOption objectInspectorOption)

partialCopyToStandardObject

public static void partialCopyToStandardObject(List<Object> result,
                                               Object row,
                                               int startCol,
                                               int numCols,
                                               StructObjectInspector soi,
                                               ObjectInspectorUtils.ObjectInspectorCopyOption objectInspectorOption)
Copy specified fields in the input row to the output array of standard objects.

Parameters:
result - output list of standard objects.
row - input row.
startCol - starting column number from the input row.
numCols - number of columns to copy.
soi - Object inspector for the to-be-copied columns.

copyToStandardObject

public static Object copyToStandardObject(Object o,
                                          ObjectInspector oi)
Returns a deep copy of the Object o that can be scanned by a StandardObjectInspector returned by getStandardObjectInspector(oi).


copyToStandardObject

public static Object copyToStandardObject(Object o,
                                          ObjectInspector oi,
                                          ObjectInspectorUtils.ObjectInspectorCopyOption objectInspectorOption)

getStandardStructTypeName

public static String getStandardStructTypeName(StructObjectInspector soi)

getStandardStructFieldRef

public static StructField getStandardStructFieldRef(String fieldName,
                                                    List<? extends StructField> fields)

getDeclaredNonStaticFields

public static Field[] getDeclaredNonStaticFields(Class<?> c)
Get all the declared non-static fields of Class c.


getObjectInspectorName

public static String getObjectInspectorName(ObjectInspector oi)
Get the class names of the ObjectInspector hierarchy. Mainly used for debugging.


hashCode

public static int hashCode(Object o,
                           ObjectInspector objIns)

compare

public static int compare(Object[] o1,
                          ObjectInspector[] oi1,
                          Object[] o2,
                          ObjectInspector[] oi2)
Compare two arrays of objects with their respective arrays of ObjectInspectors.


compareSupported

public static boolean compareSupported(ObjectInspector oi)
Whether comparison is supported for this type. Currently all types that references any map are not comparable.


compare

public static int compare(Object o1,
                          ObjectInspector oi1,
                          Object o2,
                          ObjectInspector oi2)
Compare two objects with their respective ObjectInspectors.


getFieldNames

public static String getFieldNames(StructObjectInspector soi)
Get the list of field names as csv from a StructObjectInspector.


getFieldTypes

public static String getFieldTypes(StructObjectInspector soi)
Get the list of field type as csv from a StructObjectInspector.


getTypeNameFromJavaClass

public static String getTypeNameFromJavaClass(Type t)
Get the type name of the Java class.


compareTypes

public static boolean compareTypes(ObjectInspector o1,
                                   ObjectInspector o2)
Compares two types identified by the given object inspectors. This method compares the types as follows:
  1. If the given inspectors do not belong to same category, the result is negative.
  2. If the given inspectors are for PRIMITIVE type, the result is the comparison of their type names.
  3. If the given inspectors are for LIST type, then the result is recursive call to compare the type of list elements.
  4. If the given inspectors are MAP type, then the result is a recursive call to compare the map key and value types.
  5. If the given inspectors are STRUCT type, then the result is negative if they do not have the same number of fields. If they do have the same number of fields, the result is a recursive call to compare each of the field types.
  6. If none of the above, the result is negative.

Parameters:
o1 -
o2 -
Returns:
true if the given object inspectors represent the same types.


Copyright © 2010 The Apache Software Foundation