hadoop-hive-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From zs...@apache.org
Subject svn commit: r901625 [3/6] - in /hadoop/hive/trunk: ./ serde/src/java/org/apache/hadoop/hive/serde2/ serde/src/java/org/apache/hadoop/hive/serde2/binarysortable/ serde/src/java/org/apache/hadoop/hive/serde2/columnar/ serde/src/java/org/apache/hadoop/hiv...
Date Thu, 21 Jan 2010 09:52:48 GMT
Modified: hadoop/hive/trunk/serde/src/java/org/apache/hadoop/hive/serde2/thrift/WriteTextProtocol.java
URL: http://svn.apache.org/viewvc/hadoop/hive/trunk/serde/src/java/org/apache/hadoop/hive/serde2/thrift/WriteTextProtocol.java?rev=901625&r1=901624&r2=901625&view=diff
==============================================================================
--- hadoop/hive/trunk/serde/src/java/org/apache/hadoop/hive/serde2/thrift/WriteTextProtocol.java (original)
+++ hadoop/hive/trunk/serde/src/java/org/apache/hadoop/hive/serde2/thrift/WriteTextProtocol.java Thu Jan 21 09:52:44 2010
@@ -19,13 +19,12 @@
 package org.apache.hadoop.hive.serde2.thrift;
 
 import org.apache.hadoop.io.Text;
-
 import org.apache.thrift.TException;
 
 /**
  * An interface for TProtocols that can write out data in hadoop Text objects
- * (UTF-8 encoded String).  This helps a lot with performance because we don't
- * need to do unnecessary UTF-8 decoding and encoding loops.    
+ * (UTF-8 encoded String). This helps a lot with performance because we don't
+ * need to do unnecessary UTF-8 decoding and encoding loops.
  */
 public interface WriteTextProtocol {
 

Modified: hadoop/hive/trunk/serde/src/java/org/apache/hadoop/hive/serde2/typeinfo/ListTypeInfo.java
URL: http://svn.apache.org/viewvc/hadoop/hive/trunk/serde/src/java/org/apache/hadoop/hive/serde2/typeinfo/ListTypeInfo.java?rev=901625&r1=901624&r2=901625&view=diff
==============================================================================
--- hadoop/hive/trunk/serde/src/java/org/apache/hadoop/hive/serde2/typeinfo/ListTypeInfo.java (original)
+++ hadoop/hive/trunk/serde/src/java/org/apache/hadoop/hive/serde2/typeinfo/ListTypeInfo.java Thu Jan 21 09:52:44 2010
@@ -19,50 +19,61 @@
 package org.apache.hadoop.hive.serde2.typeinfo;
 
 import java.io.Serializable;
+
 import org.apache.hadoop.hive.serde2.objectinspector.ObjectInspector.Category;
 
-/** A List Type has homogeneous elements.  All elements of the List has
- *  the same TypeInfo which is returned by getListElementTypeInfo.
- *  
- *  Always use the TypeInfoFactory to create new TypeInfo objects, instead
- *  of directly creating an instance of this class. 
+/**
+ * A List Type has homogeneous elements. All elements of the List has the same
+ * TypeInfo which is returned by getListElementTypeInfo.
+ * 
+ * Always use the TypeInfoFactory to create new TypeInfo objects, instead of
+ * directly creating an instance of this class.
  */
 public class ListTypeInfo extends TypeInfo implements Serializable {
 
   private static final long serialVersionUID = 1L;
   TypeInfo listElementTypeInfo;
-  
-  /** For java serialization use only.
+
+  /**
+   * For java serialization use only.
    */
-  public ListTypeInfo() {}
-  
+  public ListTypeInfo() {
+  }
+
+  @Override
   public String getTypeName() {
-    return org.apache.hadoop.hive.serde.Constants.LIST_TYPE_NAME 
-    + "<" + listElementTypeInfo.getTypeName() + ">";
+    return org.apache.hadoop.hive.serde.Constants.LIST_TYPE_NAME + "<"
+        + listElementTypeInfo.getTypeName() + ">";
   }
-  
-  /** For java serialization use only.
+
+  /**
+   * For java serialization use only.
    */
   public void setListElementTypeInfo(TypeInfo listElementTypeInfo) {
     this.listElementTypeInfo = listElementTypeInfo;
   }
-  
-  /** For TypeInfoFactory use only.
+
+  /**
+   * For TypeInfoFactory use only.
    */
   ListTypeInfo(TypeInfo elementTypeInfo) {
-    this.listElementTypeInfo = elementTypeInfo;
+    listElementTypeInfo = elementTypeInfo;
   }
 
+  @Override
   public Category getCategory() {
     return Category.LIST;
-  }  
+  }
 
   public TypeInfo getListElementTypeInfo() {
     return listElementTypeInfo;
   }
 
+  @Override
   public boolean equals(Object other) {
-    if (this == other) return true;
+    if (this == other) {
+      return true;
+    }
     if (!(other instanceof ListTypeInfo)) {
       return false;
     }
@@ -70,9 +81,10 @@
     return o.getCategory().equals(getCategory())
         && o.getListElementTypeInfo().equals(getListElementTypeInfo());
   }
-  
+
+  @Override
   public int hashCode() {
     return listElementTypeInfo.hashCode();
   }
-  
+
 }

Modified: hadoop/hive/trunk/serde/src/java/org/apache/hadoop/hive/serde2/typeinfo/MapTypeInfo.java
URL: http://svn.apache.org/viewvc/hadoop/hive/trunk/serde/src/java/org/apache/hadoop/hive/serde2/typeinfo/MapTypeInfo.java?rev=901625&r1=901624&r2=901625&view=diff
==============================================================================
--- hadoop/hive/trunk/serde/src/java/org/apache/hadoop/hive/serde2/typeinfo/MapTypeInfo.java (original)
+++ hadoop/hive/trunk/serde/src/java/org/apache/hadoop/hive/serde2/typeinfo/MapTypeInfo.java Thu Jan 21 09:52:44 2010
@@ -22,52 +22,59 @@
 
 import org.apache.hadoop.hive.serde2.objectinspector.ObjectInspector.Category;
 
-/** A Map Type has homogeneous keys and homogeneous values.
- *  All keys of the Map have the same TypeInfo, which is returned by
- *  getMapKeyTypeInfo(); and all values of the Map has the same TypeInfo,
- *  which is returned by getMapValueTypeInfo().
- *  
- *  Always use the TypeInfoFactory to create new TypeInfo objects, instead
- *  of directly creating an instance of this class. 
+/**
+ * A Map Type has homogeneous keys and homogeneous values. All keys of the Map
+ * have the same TypeInfo, which is returned by getMapKeyTypeInfo(); and all
+ * values of the Map has the same TypeInfo, which is returned by
+ * getMapValueTypeInfo().
+ * 
+ * Always use the TypeInfoFactory to create new TypeInfo objects, instead of
+ * directly creating an instance of this class.
  */
-public class MapTypeInfo extends TypeInfo implements Serializable{
+public class MapTypeInfo extends TypeInfo implements Serializable {
 
   private static final long serialVersionUID = 1L;
-  
+
   TypeInfo mapKeyTypeInfo;
   TypeInfo mapValueTypeInfo;
-  
-  /** For java serialization use only.
+
+  /**
+   * For java serialization use only.
    */
-  public MapTypeInfo() {}
-  
+  public MapTypeInfo() {
+  }
+
+  @Override
   public String getTypeName() {
-    return org.apache.hadoop.hive.serde.Constants.MAP_TYPE_NAME 
-    + "<" + mapKeyTypeInfo.getTypeName() + "," 
-    + mapValueTypeInfo.getTypeName() + ">";
+    return org.apache.hadoop.hive.serde.Constants.MAP_TYPE_NAME + "<"
+        + mapKeyTypeInfo.getTypeName() + "," + mapValueTypeInfo.getTypeName()
+        + ">";
   }
-  
-  /** For java serialization use only.
+
+  /**
+   * For java serialization use only.
    */
   public void setMapKeyTypeInfo(TypeInfo mapKeyTypeInfo) {
     this.mapKeyTypeInfo = mapKeyTypeInfo;
   }
 
-  /** For java serialization use only.
+  /**
+   * For java serialization use only.
    */
   public void setMapValueTypeInfo(TypeInfo mapValueTypeInfo) {
     this.mapValueTypeInfo = mapValueTypeInfo;
   }
-  
+
   // For TypeInfoFactory use only
   MapTypeInfo(TypeInfo keyTypeInfo, TypeInfo valueTypeInfo) {
-    this.mapKeyTypeInfo = keyTypeInfo;
-    this.mapValueTypeInfo = valueTypeInfo;
+    mapKeyTypeInfo = keyTypeInfo;
+    mapValueTypeInfo = valueTypeInfo;
   }
 
+  @Override
   public Category getCategory() {
     return Category.MAP;
-  }  
+  }
 
   public TypeInfo getMapKeyTypeInfo() {
     return mapKeyTypeInfo;
@@ -77,8 +84,11 @@
     return mapValueTypeInfo;
   }
 
+  @Override
   public boolean equals(Object other) {
-    if (this == other) return true;
+    if (this == other) {
+      return true;
+    }
     if (!(other instanceof MapTypeInfo)) {
       return false;
     }
@@ -87,10 +97,10 @@
         && o.getMapKeyTypeInfo().equals(getMapKeyTypeInfo())
         && o.getMapValueTypeInfo().equals(getMapValueTypeInfo());
   }
-  
+
+  @Override
   public int hashCode() {
     return mapKeyTypeInfo.hashCode() ^ mapValueTypeInfo.hashCode();
   }
-  
-  
+
 }

Modified: hadoop/hive/trunk/serde/src/java/org/apache/hadoop/hive/serde2/typeinfo/PrimitiveTypeInfo.java
URL: http://svn.apache.org/viewvc/hadoop/hive/trunk/serde/src/java/org/apache/hadoop/hive/serde2/typeinfo/PrimitiveTypeInfo.java?rev=901625&r1=901624&r2=901625&view=diff
==============================================================================
--- hadoop/hive/trunk/serde/src/java/org/apache/hadoop/hive/serde2/typeinfo/PrimitiveTypeInfo.java (original)
+++ hadoop/hive/trunk/serde/src/java/org/apache/hadoop/hive/serde2/typeinfo/PrimitiveTypeInfo.java Thu Jan 21 09:52:44 2010
@@ -19,38 +19,41 @@
 package org.apache.hadoop.hive.serde2.typeinfo;
 
 import java.io.Serializable;
-import org.apache.hadoop.hive.serde2.objectinspector.ObjectInspectorUtils;
+
 import org.apache.hadoop.hive.serde2.objectinspector.ObjectInspector.Category;
 import org.apache.hadoop.hive.serde2.objectinspector.PrimitiveObjectInspector.PrimitiveCategory;
 import org.apache.hadoop.hive.serde2.objectinspector.primitive.PrimitiveObjectInspectorUtils;
 
-
-/** There are limited number of Primitive Types.
- *  All Primitive Types are defined by TypeInfoFactory.isPrimitiveClass().
- *  
- *  Always use the TypeInfoFactory to create new TypeInfo objects, instead
- *  of directly creating an instance of this class. 
+/**
+ * There are limited number of Primitive Types. All Primitive Types are defined
+ * by TypeInfoFactory.isPrimitiveClass().
+ * 
+ * Always use the TypeInfoFactory to create new TypeInfo objects, instead of
+ * directly creating an instance of this class.
  */
 public class PrimitiveTypeInfo extends TypeInfo implements Serializable {
 
   private static final long serialVersionUID = 1L;
-  
+
   String typeName;
-  
-  /** For java serialization use only.
+
+  /**
+   * For java serialization use only.
    */
-  public PrimitiveTypeInfo() {}
+  public PrimitiveTypeInfo() {
+  }
 
-  /** For TypeInfoFactory use only.
+  /**
+   * For TypeInfoFactory use only.
    */
   PrimitiveTypeInfo(String typeName) {
     this.typeName = typeName;
   }
-  
+
   /**
    * Returns the category of this TypeInfo.
    */
-  @Override  
+  @Override
   public Category getCategory() {
     return Category.PRIMITIVE;
   }
@@ -58,39 +61,40 @@
   public PrimitiveCategory getPrimitiveCategory() {
     return PrimitiveObjectInspectorUtils.getTypeEntryFromTypeName(typeName).primitiveCategory;
   }
-  
+
   public Class<?> getPrimitiveWritableClass() {
     return PrimitiveObjectInspectorUtils.getTypeEntryFromTypeName(typeName).primitiveWritableClass;
   }
-  
+
   public Class<?> getPrimitiveJavaClass() {
     return PrimitiveObjectInspectorUtils.getTypeEntryFromTypeName(typeName).primitiveJavaClass;
   }
-  
-  
+
   // The following 2 methods are for java serialization use only.
   public void setTypeName(String typeName) {
     this.typeName = typeName;
   }
 
+  @Override
   public String getTypeName() {
     return typeName;
   }
 
   /**
-   * Compare if 2 TypeInfos are the same.
-   * We use TypeInfoFactory to cache TypeInfos, so we only 
-   * need to compare the Object pointer.
+   * Compare if 2 TypeInfos are the same. We use TypeInfoFactory to cache
+   * TypeInfos, so we only need to compare the Object pointer.
    */
+  @Override
   public boolean equals(Object other) {
     return this == other;
   }
-  
+
   /**
    * Generate the hashCode for this TypeInfo.
    */
+  @Override
   public int hashCode() {
     return typeName.hashCode();
   }
-  
+
 }

Modified: hadoop/hive/trunk/serde/src/java/org/apache/hadoop/hive/serde2/typeinfo/StructTypeInfo.java
URL: http://svn.apache.org/viewvc/hadoop/hive/trunk/serde/src/java/org/apache/hadoop/hive/serde2/typeinfo/StructTypeInfo.java?rev=901625&r1=901624&r2=901625&view=diff
==============================================================================
--- hadoop/hive/trunk/serde/src/java/org/apache/hadoop/hive/serde2/typeinfo/StructTypeInfo.java (original)
+++ hadoop/hive/trunk/serde/src/java/org/apache/hadoop/hive/serde2/typeinfo/StructTypeInfo.java Thu Jan 21 09:52:44 2010
@@ -25,30 +25,35 @@
 import org.apache.hadoop.hive.serde.Constants;
 import org.apache.hadoop.hive.serde2.objectinspector.ObjectInspector.Category;
 
-/** StructTypeInfo represents the TypeInfo of a struct.
- *  A struct contains one or more fields each of which has a unique name
- *  and its own TypeInfo.  Different fields can have the same or different
- *  TypeInfo. 
- *  
- *  Always use the TypeInfoFactory to create new TypeInfo objects, instead
- *  of directly creating an instance of this class. 
+/**
+ * StructTypeInfo represents the TypeInfo of a struct. A struct contains one or
+ * more fields each of which has a unique name and its own TypeInfo. Different
+ * fields can have the same or different TypeInfo.
+ * 
+ * Always use the TypeInfoFactory to create new TypeInfo objects, instead of
+ * directly creating an instance of this class.
  */
-public class StructTypeInfo extends TypeInfo implements Serializable{
+public class StructTypeInfo extends TypeInfo implements Serializable {
 
   private static final long serialVersionUID = 1L;
-  
+
   ArrayList<String> allStructFieldNames;
   ArrayList<TypeInfo> allStructFieldTypeInfos;
-  
-  /** For java serialization use only.
+
+  /**
+   * For java serialization use only.
    */
-  public StructTypeInfo() {}
+  public StructTypeInfo() {
+  }
 
+  @Override
   public String getTypeName() {
     StringBuilder sb = new StringBuilder();
     sb.append(Constants.STRUCT_TYPE_NAME + "<");
-    for(int i=0; i<allStructFieldNames.size(); i++) {
-      if (i>0) sb.append(",");
+    for (int i = 0; i < allStructFieldNames.size(); i++) {
+      if (i > 0) {
+        sb.append(",");
+      }
       sb.append(allStructFieldNames.get(i));
       sb.append(":");
       sb.append(allStructFieldTypeInfos.get(i).getTypeName());
@@ -56,21 +61,24 @@
     sb.append(">");
     return sb.toString();
   }
-  
-  /** For java serialization use only.
+
+  /**
+   * For java serialization use only.
    */
   public void setAllStructFieldNames(ArrayList<String> allStructFieldNames) {
     this.allStructFieldNames = allStructFieldNames;
   }
 
-  /** For java serialization use only.
+  /**
+   * For java serialization use only.
    */
   public void setAllStructFieldTypeInfos(
       ArrayList<TypeInfo> allStructFieldTypeInfos) {
     this.allStructFieldTypeInfos = allStructFieldTypeInfos;
   }
-  
-  /** For TypeInfoFactory use only.
+
+  /**
+   * For TypeInfoFactory use only.
    */
   StructTypeInfo(List<String> names, List<TypeInfo> typeInfos) {
     allStructFieldNames = new ArrayList<String>();
@@ -79,33 +87,36 @@
     allStructFieldTypeInfos.addAll(typeInfos);
   }
 
+  @Override
   public Category getCategory() {
     return Category.STRUCT;
   }
-  
+
   public ArrayList<String> getAllStructFieldNames() {
     return allStructFieldNames;
   }
-  
+
   public ArrayList<TypeInfo> getAllStructFieldTypeInfos() {
     return allStructFieldTypeInfos;
   }
-  
+
   public TypeInfo getStructFieldTypeInfo(String field) {
     String fieldLowerCase = field.toLowerCase();
-    for(int i=0; i<allStructFieldNames.size(); i++) {
+    for (int i = 0; i < allStructFieldNames.size(); i++) {
       if (fieldLowerCase.equals(allStructFieldNames.get(i))) {
         return allStructFieldTypeInfos.get(i);
       }
     }
-    throw new RuntimeException("cannot find field " + field + "(lowercase form: " 
-        + fieldLowerCase + ") in " + allStructFieldNames);
+    throw new RuntimeException("cannot find field " + field
+        + "(lowercase form: " + fieldLowerCase + ") in " + allStructFieldNames);
     // return null;
   }
-  
+
   @Override
   public boolean equals(Object other) {
-    if (this == other) return true;
+    if (this == other) {
+      return true;
+    }
     if (!(other instanceof StructTypeInfo)) {
       return false;
     }
@@ -114,9 +125,10 @@
         && o.getAllStructFieldNames().equals(getAllStructFieldNames())
         && o.getAllStructFieldTypeInfos().equals(getAllStructFieldTypeInfos());
   }
-  
+
+  @Override
   public int hashCode() {
     return allStructFieldNames.hashCode() ^ allStructFieldTypeInfos.hashCode();
   }
-  
+
 }

Modified: hadoop/hive/trunk/serde/src/java/org/apache/hadoop/hive/serde2/typeinfo/TypeInfo.java
URL: http://svn.apache.org/viewvc/hadoop/hive/trunk/serde/src/java/org/apache/hadoop/hive/serde2/typeinfo/TypeInfo.java?rev=901625&r1=901624&r2=901625&view=diff
==============================================================================
--- hadoop/hive/trunk/serde/src/java/org/apache/hadoop/hive/serde2/typeinfo/TypeInfo.java (original)
+++ hadoop/hive/trunk/serde/src/java/org/apache/hadoop/hive/serde2/typeinfo/TypeInfo.java Thu Jan 21 09:52:44 2010
@@ -19,46 +19,51 @@
 package org.apache.hadoop.hive.serde2.typeinfo;
 
 import java.io.Serializable;
+
 import org.apache.hadoop.hive.serde2.objectinspector.ObjectInspector.Category;
 
 /**
- * Stores information about a type.
- * Always use the TypeInfoFactory to create new TypeInfo objects.
+ * Stores information about a type. Always use the TypeInfoFactory to create new
+ * TypeInfo objects.
  * 
- * We support 4 categories of types:
- * 1. Primitive objects (String, Number, etc)
- * 2. List objects (a list of objects of a single type)
- * 3. Map objects (a map from objects of one type to objects of another type)
- * 4. Struct objects (a list of fields with names and their own types)
+ * We support 4 categories of types: 1. Primitive objects (String, Number, etc)
+ * 2. List objects (a list of objects of a single type) 3. Map objects (a map
+ * from objects of one type to objects of another type) 4. Struct objects (a
+ * list of fields with names and their own types)
  */
 public abstract class TypeInfo implements Serializable {
 
-  protected TypeInfo() {}
+  protected TypeInfo() {
+  }
 
   /**
-   * The Category of this TypeInfo.
-   * Possible values are Primitive, List, Map and Struct, which corresponds
-   * to the 4 sub-classes of TypeInfo. 
+   * The Category of this TypeInfo. Possible values are Primitive, List, Map and
+   * Struct, which corresponds to the 4 sub-classes of TypeInfo.
    */
   public abstract Category getCategory();
-  
+
   /**
    * A String representation of the TypeInfo.
    */
   public abstract String getTypeName();
-  
+
+  @Override
   public String toString() {
     return getTypeName();
   }
 
+  @Override
   public boolean equals(Object o) {
-   if (!(o instanceof TypeInfo))
-     return false;
-   TypeInfo dest = (TypeInfo)o;
-   if (getCategory() != dest.getCategory())
-     return false;
-   if (getTypeName() != dest.getTypeName())
-     return false;
-   return true;
+    if (!(o instanceof TypeInfo)) {
+      return false;
+    }
+    TypeInfo dest = (TypeInfo) o;
+    if (getCategory() != dest.getCategory()) {
+      return false;
+    }
+    if (getTypeName() != dest.getTypeName()) {
+      return false;
+    }
+    return true;
   }
 }

Modified: hadoop/hive/trunk/serde/src/java/org/apache/hadoop/hive/serde2/typeinfo/TypeInfoFactory.java
URL: http://svn.apache.org/viewvc/hadoop/hive/trunk/serde/src/java/org/apache/hadoop/hive/serde2/typeinfo/TypeInfoFactory.java?rev=901625&r1=901624&r2=901625&view=diff
==============================================================================
--- hadoop/hive/trunk/serde/src/java/org/apache/hadoop/hive/serde2/typeinfo/TypeInfoFactory.java (original)
+++ hadoop/hive/trunk/serde/src/java/org/apache/hadoop/hive/serde2/typeinfo/TypeInfoFactory.java Thu Jan 21 09:52:44 2010
@@ -21,31 +21,28 @@
 import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.List;
-import java.util.Stack;
 
 import org.apache.hadoop.hive.serde.Constants;
-import org.apache.hadoop.hive.serde2.objectinspector.ObjectInspectorUtils;
 import org.apache.hadoop.hive.serde2.objectinspector.primitive.PrimitiveObjectInspectorUtils;
-import org.apache.hadoop.io.IntWritable;
-
-
 
 /**
  * TypeInfoFactory can be used to create the TypeInfo object for any types.
  * 
- * TypeInfo objects are all read-only so we can reuse them easily. TypeInfoFactory 
- * has internal cache to make sure we don't create 2 TypeInfo objects that represents the
- * same type.
+ * TypeInfo objects are all read-only so we can reuse them easily.
+ * TypeInfoFactory has internal cache to make sure we don't create 2 TypeInfo
+ * objects that represents the same type.
  */
 public class TypeInfoFactory {
 
   static HashMap<String, TypeInfo> cachedPrimitiveTypeInfo = new HashMap<String, TypeInfo>();
+
   public static TypeInfo getPrimitiveTypeInfo(String typeName) {
-    if (null == PrimitiveObjectInspectorUtils.getTypeEntryFromTypeName(typeName)) {
+    if (null == PrimitiveObjectInspectorUtils
+        .getTypeEntryFromTypeName(typeName)) {
       throw new RuntimeException("Cannot getPrimitiveTypeInfo for " + typeName);
     }
     TypeInfo result = cachedPrimitiveTypeInfo.get(typeName);
-    if (result == null) { 
+    if (result == null) {
       result = new PrimitiveTypeInfo(typeName);
       cachedPrimitiveTypeInfo.put(typeName, result);
     }
@@ -63,36 +60,43 @@
   public static final TypeInfo shortTypeInfo = getPrimitiveTypeInfo(Constants.SMALLINT_TYPE_NAME);
 
   public static final TypeInfo unknownTypeInfo = getPrimitiveTypeInfo("unknown");
-  
-  public static TypeInfo getPrimitiveTypeInfoFromPrimitiveWritable(Class<?> clazz) {
-    String typeName = PrimitiveObjectInspectorUtils.getTypeNameFromPrimitiveWritable(clazz);
+
+  public static TypeInfo getPrimitiveTypeInfoFromPrimitiveWritable(
+      Class<?> clazz) {
+    String typeName = PrimitiveObjectInspectorUtils
+        .getTypeNameFromPrimitiveWritable(clazz);
     if (typeName == null) {
-      throw new RuntimeException("Internal error: Cannot get typeName for " + clazz);
+      throw new RuntimeException("Internal error: Cannot get typeName for "
+          + clazz);
     }
     return getPrimitiveTypeInfo(typeName);
   }
 
   public static TypeInfo getPrimitiveTypeInfoFromJavaPrimitive(Class<?> clazz) {
-    return getPrimitiveTypeInfo(PrimitiveObjectInspectorUtils.getTypeNameFromPrimitiveJava(clazz));
+    return getPrimitiveTypeInfo(PrimitiveObjectInspectorUtils
+        .getTypeNameFromPrimitiveJava(clazz));
   }
-  
+
   static HashMap<ArrayList<List<?>>, TypeInfo> cachedStructTypeInfo = new HashMap<ArrayList<List<?>>, TypeInfo>();
-  public static TypeInfo getStructTypeInfo(List<String> names, List<TypeInfo> typeInfos) {
+
+  public static TypeInfo getStructTypeInfo(List<String> names,
+      List<TypeInfo> typeInfos) {
     ArrayList<List<?>> signature = new ArrayList<List<?>>(2);
     signature.add(names);
     signature.add(typeInfos);
     TypeInfo result = cachedStructTypeInfo.get(signature);
-    if (result == null) { 
+    if (result == null) {
       result = new StructTypeInfo(names, typeInfos);
       cachedStructTypeInfo.put(signature, result);
     }
     return result;
   }
-  
+
   static HashMap<TypeInfo, TypeInfo> cachedListTypeInfo = new HashMap<TypeInfo, TypeInfo>();
+
   public static TypeInfo getListTypeInfo(TypeInfo elementTypeInfo) {
     TypeInfo result = cachedListTypeInfo.get(elementTypeInfo);
-    if (result == null) { 
+    if (result == null) {
       result = new ListTypeInfo(elementTypeInfo);
       cachedListTypeInfo.put(elementTypeInfo, result);
     }
@@ -100,12 +104,14 @@
   }
 
   static HashMap<ArrayList<TypeInfo>, TypeInfo> cachedMapTypeInfo = new HashMap<ArrayList<TypeInfo>, TypeInfo>();
-  public static TypeInfo getMapTypeInfo(TypeInfo keyTypeInfo, TypeInfo valueTypeInfo) {
+
+  public static TypeInfo getMapTypeInfo(TypeInfo keyTypeInfo,
+      TypeInfo valueTypeInfo) {
     ArrayList<TypeInfo> signature = new ArrayList<TypeInfo>(2);
     signature.add(keyTypeInfo);
     signature.add(valueTypeInfo);
     TypeInfo result = cachedMapTypeInfo.get(signature);
-    if (result == null) { 
+    if (result == null) {
       result = new MapTypeInfo(keyTypeInfo, valueTypeInfo);
       cachedMapTypeInfo.put(signature, result);
     }

Modified: hadoop/hive/trunk/serde/src/java/org/apache/hadoop/hive/serde2/typeinfo/TypeInfoUtils.java
URL: http://svn.apache.org/viewvc/hadoop/hive/trunk/serde/src/java/org/apache/hadoop/hive/serde2/typeinfo/TypeInfoUtils.java?rev=901625&r1=901624&r2=901625&view=diff
==============================================================================
--- hadoop/hive/trunk/serde/src/java/org/apache/hadoop/hive/serde2/typeinfo/TypeInfoUtils.java (original)
+++ hadoop/hive/trunk/serde/src/java/org/apache/hadoop/hive/serde2/typeinfo/TypeInfoUtils.java Thu Jan 21 09:52:44 2010
@@ -25,111 +25,121 @@
 import org.apache.hadoop.hive.serde2.objectinspector.primitive.PrimitiveObjectInspectorUtils.PrimitiveTypeEntry;
 
 public class TypeInfoUtils {
-  
+
   /**
-   * Return the extended TypeInfo from a Java type.
-   * By extended TypeInfo, we allow unknownType for java.lang.Object.
-   * @param t  The Java type.
-   * @param m  The method, only used for generating error messages.
+   * Return the extended TypeInfo from a Java type. By extended TypeInfo, we
+   * allow unknownType for java.lang.Object.
+   * 
+   * @param t
+   *          The Java type.
+   * @param m
+   *          The method, only used for generating error messages.
    */
   private static TypeInfo getExtendedTypeInfoFromJavaType(Type t, Method m) {
 
     if (t == Object.class) {
-      return TypeInfoFactory.unknownTypeInfo; 
+      return TypeInfoFactory.unknownTypeInfo;
     }
-    
+
     if (t instanceof ParameterizedType) {
-      ParameterizedType pt = (ParameterizedType)t;
+      ParameterizedType pt = (ParameterizedType) t;
       // List?
-      if (List.class == (Class<?>)pt.getRawType()
-          || ArrayList.class == (Class<?>)pt.getRawType()) {
-        return TypeInfoFactory.getListTypeInfo(
-            getExtendedTypeInfoFromJavaType(pt.getActualTypeArguments()[0], m)); 
+      if (List.class == (Class<?>) pt.getRawType()
+          || ArrayList.class == (Class<?>) pt.getRawType()) {
+        return TypeInfoFactory.getListTypeInfo(getExtendedTypeInfoFromJavaType(
+            pt.getActualTypeArguments()[0], m));
       }
       // Map?
-      if (Map.class == (Class<?>)pt.getRawType()
-          || HashMap.class == (Class<?>)pt.getRawType()) {
-        return TypeInfoFactory.getMapTypeInfo( 
-            getExtendedTypeInfoFromJavaType(pt.getActualTypeArguments()[0], m),
+      if (Map.class == (Class<?>) pt.getRawType()
+          || HashMap.class == (Class<?>) pt.getRawType()) {
+        return TypeInfoFactory.getMapTypeInfo(getExtendedTypeInfoFromJavaType(
+            pt.getActualTypeArguments()[0], m),
             getExtendedTypeInfoFromJavaType(pt.getActualTypeArguments()[1], m));
       }
-      // Otherwise convert t to RawType so we will fall into the following if block.
+      // Otherwise convert t to RawType so we will fall into the following if
+      // block.
       t = pt.getRawType();
     }
-    
+
     // Must be a class.
     if (!(t instanceof Class)) {
-      throw new RuntimeException("Hive does not understand type " + t + " from " + m); 
+      throw new RuntimeException("Hive does not understand type " + t
+          + " from " + m);
     }
-    Class<?> c = (Class<?>)t;
-    
+    Class<?> c = (Class<?>) t;
+
     // Java Primitive Type?
     if (PrimitiveObjectInspectorUtils.isPrimitiveJavaType(c)) {
-      return TypeInfoUtils.getTypeInfoFromObjectInspector(
-          PrimitiveObjectInspectorFactory.getPrimitiveJavaObjectInspector(
-          PrimitiveObjectInspectorUtils.getTypeEntryFromPrimitiveJavaType(c).primitiveCategory));
+      return TypeInfoUtils
+          .getTypeInfoFromObjectInspector(PrimitiveObjectInspectorFactory
+              .getPrimitiveJavaObjectInspector(PrimitiveObjectInspectorUtils
+                  .getTypeEntryFromPrimitiveJavaType(c).primitiveCategory));
     }
 
     // Java Primitive Class?
     if (PrimitiveObjectInspectorUtils.isPrimitiveJavaClass(c)) {
-      return TypeInfoUtils.getTypeInfoFromObjectInspector(
-          PrimitiveObjectInspectorFactory.getPrimitiveJavaObjectInspector(
-          PrimitiveObjectInspectorUtils.getTypeEntryFromPrimitiveJavaClass(c).primitiveCategory));
+      return TypeInfoUtils
+          .getTypeInfoFromObjectInspector(PrimitiveObjectInspectorFactory
+              .getPrimitiveJavaObjectInspector(PrimitiveObjectInspectorUtils
+                  .getTypeEntryFromPrimitiveJavaClass(c).primitiveCategory));
     }
-    
+
     // Primitive Writable class?
     if (PrimitiveObjectInspectorUtils.isPrimitiveWritableClass(c)) {
-      return TypeInfoUtils.getTypeInfoFromObjectInspector(
-          PrimitiveObjectInspectorFactory.getPrimitiveWritableObjectInspector(
-          PrimitiveObjectInspectorUtils.getTypeEntryFromPrimitiveWritableClass(c).primitiveCategory));
+      return TypeInfoUtils
+          .getTypeInfoFromObjectInspector(PrimitiveObjectInspectorFactory
+              .getPrimitiveWritableObjectInspector(PrimitiveObjectInspectorUtils
+                  .getTypeEntryFromPrimitiveWritableClass(c).primitiveCategory));
     }
-    
+
     // Must be a struct
     Field[] fields = ObjectInspectorUtils.getDeclaredNonStaticFields(c);
     ArrayList<String> fieldNames = new ArrayList<String>(fields.length);
     ArrayList<TypeInfo> fieldTypeInfos = new ArrayList<TypeInfo>(fields.length);
-    for(int i=0; i<fields.length; i++) {
-      fieldNames.add(fields[i].getName());
-      fieldTypeInfos.add(getExtendedTypeInfoFromJavaType(fields[i].getGenericType(), m));
+    for (Field field : fields) {
+      fieldNames.add(field.getName());
+      fieldTypeInfos.add(getExtendedTypeInfoFromJavaType(
+          field.getGenericType(), m));
     }
     return TypeInfoFactory.getStructTypeInfo(fieldNames, fieldTypeInfos);
   }
-  
+
   /**
-   * Returns the array element type, if the Type is an array (Object[]),
-   * or GenericArrayType (Map<String,String>[]). Otherwise return null.
+   * Returns the array element type, if the Type is an array (Object[]), or
+   * GenericArrayType (Map<String,String>[]). Otherwise return null.
    */
   public static Type getArrayElementType(Type t) {
-    if (t instanceof Class
-        && ((Class<?>)t).isArray()) {
-      Class<?> arrayClass = (Class<?>)t;
+    if (t instanceof Class && ((Class<?>) t).isArray()) {
+      Class<?> arrayClass = (Class<?>) t;
       return arrayClass.getComponentType();
     } else if (t instanceof GenericArrayType) {
-      GenericArrayType arrayType = (GenericArrayType)t;
+      GenericArrayType arrayType = (GenericArrayType) t;
       return arrayType.getGenericComponentType();
     }
     return null;
   }
-  
+
   /**
    * Get the parameter TypeInfo for a method.
-   * @param size In case the last parameter of Method is an array, we will try to return a 
-   *             List<TypeInfo> with the specified size by repeating the element of the array
-   *             at the end.
-   *             In case the size is smaller than the minimum possible number of arguments 
-   *             for the method, null will be returned. 
+   * 
+   * @param size
+   *          In case the last parameter of Method is an array, we will try to
+   *          return a List<TypeInfo> with the specified size by repeating the
+   *          element of the array at the end. In case the size is smaller than
+   *          the minimum possible number of arguments for the method, null will
+   *          be returned.
    */
   public static List<TypeInfo> getParameterTypeInfos(Method m, int size) {
     Type[] methodParameterTypes = m.getGenericParameterTypes();
-    
+
     // Whether the method takes variable-length arguments
-    // Whether the method takes an array like Object[], 
+    // Whether the method takes an array like Object[],
     // or String[] etc in the last argument.
-    Type lastParaElementType = TypeInfoUtils.getArrayElementType(
-        methodParameterTypes.length == 0 ? null :
-        methodParameterTypes[methodParameterTypes.length-1]);
+    Type lastParaElementType = TypeInfoUtils
+        .getArrayElementType(methodParameterTypes.length == 0 ? null
+            : methodParameterTypes[methodParameterTypes.length - 1]);
     boolean isVariableLengthArgument = (lastParaElementType != null);
-    
+
     List<TypeInfo> typeInfos = null;
     if (!isVariableLengthArgument) {
       // Normal case, no variable-length arguments
@@ -137,8 +147,8 @@
         return null;
       }
       typeInfos = new ArrayList<TypeInfo>(methodParameterTypes.length);
-      for (int i = 0; i < methodParameterTypes.length; i++) {
-        typeInfos.add(getExtendedTypeInfoFromJavaType(methodParameterTypes[i], m));
+      for (Type methodParameterType : methodParameterTypes) {
+        typeInfos.add(getExtendedTypeInfoFromJavaType(methodParameterType, m));
       }
     } else {
       // Variable-length arguments
@@ -147,7 +157,8 @@
       }
       typeInfos = new ArrayList<TypeInfo>(size);
       for (int i = 0; i < methodParameterTypes.length - 1; i++) {
-        typeInfos.add(getExtendedTypeInfoFromJavaType(methodParameterTypes[i], m));
+        typeInfos.add(getExtendedTypeInfoFromJavaType(methodParameterTypes[i],
+            m));
       }
       for (int i = methodParameterTypes.length - 1; i < size; i++) {
         typeInfos.add(getExtendedTypeInfoFromJavaType(lastParaElementType, m));
@@ -155,46 +166,49 @@
     }
     return typeInfos;
   }
+
   /**
-   * Parse a recursive TypeInfo list String.
-   * For example, the following inputs are valid inputs: 
-   *  "int,string,map<string,int>,list<map<int,list<string>>>,list<struct<a:int,b:string>>"
+   * Parse a recursive TypeInfo list String. For example, the following inputs
+   * are valid inputs:"int,string,map<string,int>,list<map<int,list<string>>>,list<struct<a:int,b:string>>"
    * The separators between TypeInfos can be ",", ":", or ";".
    * 
-   * In order to use this class:
-   * TypeInfoParser parser = new TypeInfoParser("int,string");
-   * ArrayList<TypeInfo> typeInfos = parser.parseTypeInfos();
+   * In order to use this class: TypeInfoParser parser = new
+   * TypeInfoParser("int,string"); ArrayList<TypeInfo> typeInfos =
+   * parser.parseTypeInfos();
    */
   private static class TypeInfoParser {
-    
+
     private static class Token {
       public int position;
       public String text;
       public boolean isType;
+
+      @Override
       public String toString() {
         return "" + position + ":" + text;
       }
     };
-    
+
     private static boolean isTypeChar(char c) {
       return Character.isLetterOrDigit(c) || c == '_' || c == '.';
     }
-    
+
     /**
-     * Tokenize the typeInfoString.
-     * The rule is simple: all consecutive alphadigits and '_', '.' are in one
-     * token, and all other characters are one character per token.
+     * Tokenize the typeInfoString. The rule is simple: all consecutive
+     * alphadigits and '_', '.' are in one token, and all other characters are
+     * one character per token.
      * 
-     * tokenize("map<int,string>") should return ["map","<","int",",","string",">"]
+     * tokenize("map<int,string>") should return
+     * ["map","<","int",",","string",">"]
      */
     private static ArrayList<Token> tokenize(String typeInfoString) {
       ArrayList<Token> tokens = new ArrayList<Token>(0);
       int begin = 0;
       int end = 1;
       while (end <= typeInfoString.length()) {
-        // last character ends a token? 
-        if (end == typeInfoString.length() 
-            || !isTypeChar(typeInfoString.charAt(end-1))
+        // last character ends a token?
+        if (end == typeInfoString.length()
+            || !isTypeChar(typeInfoString.charAt(end - 1))
             || !isTypeChar(typeInfoString.charAt(end))) {
           Token t = new Token();
           t.position = begin;
@@ -202,22 +216,22 @@
           t.isType = isTypeChar(typeInfoString.charAt(begin));
           tokens.add(t);
           begin = end;
-        }          
-        end ++;
+        }
+        end++;
       }
       return tokens;
     }
-  
+
     public TypeInfoParser(String typeInfoString) {
       this.typeInfoString = typeInfoString;
-      this.typeInfoTokens = tokenize(typeInfoString);
+      typeInfoTokens = tokenize(typeInfoString);
     }
-  
-    private String typeInfoString;
-    private ArrayList<Token> typeInfoTokens;
+
+    private final String typeInfoString;
+    private final ArrayList<Token> typeInfoTokens;
     private ArrayList<TypeInfo> typeInfos;
     private int iToken;
-    
+
     public ArrayList<TypeInfo> parseTypeInfos() throws IllegalArgumentException {
       typeInfos = new ArrayList<TypeInfo>();
       iToken = 0;
@@ -225,61 +239,70 @@
         typeInfos.add(parseType());
         if (iToken < typeInfoTokens.size()) {
           Token separator = typeInfoTokens.get(iToken);
-          if (",".equals(separator.text) || ";".equals(separator.text) || ":".equals(separator.text)) {
-            iToken ++;
+          if (",".equals(separator.text) || ";".equals(separator.text)
+              || ":".equals(separator.text)) {
+            iToken++;
           } else {
-            throw new IllegalArgumentException("Error: ',', ':', or ';' expected at position " 
-                + separator.position + " from '" + typeInfoString + "' " + typeInfoTokens );
+            throw new IllegalArgumentException(
+                "Error: ',', ':', or ';' expected at position "
+                    + separator.position + " from '" + typeInfoString + "' "
+                    + typeInfoTokens);
           }
         }
       }
       return typeInfos;
     }
-  
+
     private Token expect(String item) {
       return expect(item, null);
     }
-    
+
     private Token expect(String item, String alternative) {
       if (iToken >= typeInfoTokens.size()) {
-        throw new IllegalArgumentException("Error: " + item + " expected at the end of '"  
-            + typeInfoString + "'" );
+        throw new IllegalArgumentException("Error: " + item
+            + " expected at the end of '" + typeInfoString + "'");
       }
       Token t = typeInfoTokens.get(iToken);
       if (item.equals("type")) {
         if (!Constants.LIST_TYPE_NAME.equals(t.text)
             && !Constants.MAP_TYPE_NAME.equals(t.text)
             && !Constants.STRUCT_TYPE_NAME.equals(t.text)
-            && null == PrimitiveObjectInspectorUtils.getTypeEntryFromTypeName(t.text)
+            && null == PrimitiveObjectInspectorUtils
+                .getTypeEntryFromTypeName(t.text)
             && !t.text.equals(alternative)) {
-          throw new IllegalArgumentException("Error: " + item + " expected at the position "
-              + t.position + " of '" + typeInfoString + "' but '" + t.text + "' is found." );
+          throw new IllegalArgumentException("Error: " + item
+              + " expected at the position " + t.position + " of '"
+              + typeInfoString + "' but '" + t.text + "' is found.");
         }
       } else if (item.equals("name")) {
         if (!t.isType && !t.text.equals(alternative)) {
-          throw new IllegalArgumentException("Error: " + item + " expected at the position "
-              + t.position + " of '" + typeInfoString + "' but '" + t.text + "' is found." );
+          throw new IllegalArgumentException("Error: " + item
+              + " expected at the position " + t.position + " of '"
+              + typeInfoString + "' but '" + t.text + "' is found.");
         }
       } else {
         if (!item.equals(t.text) && !t.text.equals(alternative)) {
-          throw new IllegalArgumentException("Error: " + item + " expected at the position "
-              + t.position + " of '" + typeInfoString + "' but '" + t.text + "' is found." );
+          throw new IllegalArgumentException("Error: " + item
+              + " expected at the position " + t.position + " of '"
+              + typeInfoString + "' but '" + t.text + "' is found.");
         }
       }
-      iToken ++;
+      iToken++;
       return t;
     }
-    
+
     private TypeInfo parseType() {
-      
+
       Token t = expect("type");
-  
+
       // Is this a primitive type?
-      PrimitiveTypeEntry primitiveType = PrimitiveObjectInspectorUtils.getTypeEntryFromTypeName(t.text);
-      if (primitiveType != null && !primitiveType.primitiveCategory.equals(PrimitiveCategory.UNKNOWN)) {
+      PrimitiveTypeEntry primitiveType = PrimitiveObjectInspectorUtils
+          .getTypeEntryFromTypeName(t.text);
+      if (primitiveType != null
+          && !primitiveType.primitiveCategory.equals(PrimitiveCategory.UNKNOWN)) {
         return TypeInfoFactory.getPrimitiveTypeInfo(primitiveType.typeName);
       }
-      
+
       // Is this a list type?
       if (Constants.LIST_TYPE_NAME.equals(t.text)) {
         expect("<");
@@ -287,7 +310,7 @@
         expect(">");
         return TypeInfoFactory.getListTypeInfo(listElementType);
       }
-  
+
       // Is this a map type?
       if (Constants.MAP_TYPE_NAME.equals(t.text)) {
         expect("<");
@@ -297,7 +320,7 @@
         expect(">");
         return TypeInfoFactory.getMapTypeInfo(mapKeyType, mapValueType);
       }
-  
+
       // Is this a struct type?
       if (Constants.STRUCT_TYPE_NAME.equals(t.text)) {
         ArrayList<String> fieldNames = new ArrayList<String>();
@@ -319,164 +342,190 @@
           expect(":");
           fieldTypeInfos.add(parseType());
         } while (true);
-        
+
         return TypeInfoFactory.getStructTypeInfo(fieldNames, fieldTypeInfos);
       }
-  
-      throw new RuntimeException("Internal error parsing position " + t.position + " of '"
-          + typeInfoString + "'");
+
+      throw new RuntimeException("Internal error parsing position "
+          + t.position + " of '" + typeInfoString + "'");
     }
-    
+
   }
 
   static HashMap<TypeInfo, ObjectInspector> cachedStandardObjectInspector = new HashMap<TypeInfo, ObjectInspector>();
+
   /**
-   * Returns the standard object inspector that can be used to translate an object of that typeInfo
-   * to a standard object type.  
+   * Returns the standard object inspector that can be used to translate an
+   * object of that typeInfo to a standard object type.
    */
-  public static ObjectInspector getStandardWritableObjectInspectorFromTypeInfo(TypeInfo typeInfo) {
+  public static ObjectInspector getStandardWritableObjectInspectorFromTypeInfo(
+      TypeInfo typeInfo) {
     ObjectInspector result = cachedStandardObjectInspector.get(typeInfo);
     if (result == null) {
-      switch(typeInfo.getCategory()) {
-        case PRIMITIVE: {
-          result = PrimitiveObjectInspectorFactory.getPrimitiveWritableObjectInspector(
-              ((PrimitiveTypeInfo)typeInfo).getPrimitiveCategory());
-          break;
-        }
-        case LIST: {
-          ObjectInspector elementObjectInspector = getStandardWritableObjectInspectorFromTypeInfo(
-              ((ListTypeInfo)typeInfo).getListElementTypeInfo());
-          result = ObjectInspectorFactory.getStandardListObjectInspector(elementObjectInspector);
-          break;
-        }
-        case MAP: {
-          MapTypeInfo mapTypeInfo = (MapTypeInfo)typeInfo;
-          ObjectInspector keyObjectInspector = getStandardWritableObjectInspectorFromTypeInfo(mapTypeInfo.getMapKeyTypeInfo());
-          ObjectInspector valueObjectInspector = getStandardWritableObjectInspectorFromTypeInfo(mapTypeInfo.getMapValueTypeInfo());
-          result = ObjectInspectorFactory.getStandardMapObjectInspector(keyObjectInspector, valueObjectInspector);
-          break;
-        }
-        case STRUCT: {
-          StructTypeInfo structTypeInfo = (StructTypeInfo)typeInfo;
-          List<String> fieldNames = structTypeInfo.getAllStructFieldNames();
-          List<TypeInfo> fieldTypeInfos = structTypeInfo.getAllStructFieldTypeInfos();
-          List<ObjectInspector> fieldObjectInspectors = new ArrayList<ObjectInspector>(fieldTypeInfos.size());
-          for(int i=0; i<fieldTypeInfos.size(); i++) {
-            fieldObjectInspectors.add(getStandardWritableObjectInspectorFromTypeInfo(fieldTypeInfos.get(i)));
-          }
-          result = ObjectInspectorFactory.getStandardStructObjectInspector(fieldNames, fieldObjectInspectors);
-          break;
-        }
-        default: {
-          result = null;
+      switch (typeInfo.getCategory()) {
+      case PRIMITIVE: {
+        result = PrimitiveObjectInspectorFactory
+            .getPrimitiveWritableObjectInspector(((PrimitiveTypeInfo) typeInfo)
+                .getPrimitiveCategory());
+        break;
+      }
+      case LIST: {
+        ObjectInspector elementObjectInspector = getStandardWritableObjectInspectorFromTypeInfo(((ListTypeInfo) typeInfo)
+            .getListElementTypeInfo());
+        result = ObjectInspectorFactory
+            .getStandardListObjectInspector(elementObjectInspector);
+        break;
+      }
+      case MAP: {
+        MapTypeInfo mapTypeInfo = (MapTypeInfo) typeInfo;
+        ObjectInspector keyObjectInspector = getStandardWritableObjectInspectorFromTypeInfo(mapTypeInfo
+            .getMapKeyTypeInfo());
+        ObjectInspector valueObjectInspector = getStandardWritableObjectInspectorFromTypeInfo(mapTypeInfo
+            .getMapValueTypeInfo());
+        result = ObjectInspectorFactory.getStandardMapObjectInspector(
+            keyObjectInspector, valueObjectInspector);
+        break;
+      }
+      case STRUCT: {
+        StructTypeInfo structTypeInfo = (StructTypeInfo) typeInfo;
+        List<String> fieldNames = structTypeInfo.getAllStructFieldNames();
+        List<TypeInfo> fieldTypeInfos = structTypeInfo
+            .getAllStructFieldTypeInfos();
+        List<ObjectInspector> fieldObjectInspectors = new ArrayList<ObjectInspector>(
+            fieldTypeInfos.size());
+        for (int i = 0; i < fieldTypeInfos.size(); i++) {
+          fieldObjectInspectors
+              .add(getStandardWritableObjectInspectorFromTypeInfo(fieldTypeInfos
+                  .get(i)));
         }
+        result = ObjectInspectorFactory.getStandardStructObjectInspector(
+            fieldNames, fieldObjectInspectors);
+        break;
+      }
+      default: {
+        result = null;
+      }
       }
       cachedStandardObjectInspector.put(typeInfo, result);
     }
     return result;
   }
 
-
-  
   static HashMap<TypeInfo, ObjectInspector> cachedStandardJavaObjectInspector = new HashMap<TypeInfo, ObjectInspector>();
+
   /**
-   * Returns the standard object inspector that can be used to translate an object of that typeInfo
-   * to a standard object type.  
+   * Returns the standard object inspector that can be used to translate an
+   * object of that typeInfo to a standard object type.
    */
-  public static ObjectInspector getStandardJavaObjectInspectorFromTypeInfo(TypeInfo typeInfo) {
+  public static ObjectInspector getStandardJavaObjectInspectorFromTypeInfo(
+      TypeInfo typeInfo) {
     ObjectInspector result = cachedStandardJavaObjectInspector.get(typeInfo);
     if (result == null) {
-      switch(typeInfo.getCategory()) {
-        case PRIMITIVE: {
-          // NOTE: we use JavaPrimitiveObjectInspector instead of StandardPrimitiveObjectInspector
-          result = PrimitiveObjectInspectorFactory.getPrimitiveJavaObjectInspector(
-              PrimitiveObjectInspectorUtils.getTypeEntryFromTypeName(typeInfo.getTypeName()).primitiveCategory);
-          break;
-        }
-        case LIST: {
-          ObjectInspector elementObjectInspector = getStandardJavaObjectInspectorFromTypeInfo(
-              ((ListTypeInfo)typeInfo).getListElementTypeInfo());
-          result = ObjectInspectorFactory.getStandardListObjectInspector(elementObjectInspector);
-          break;
-        }
-        case MAP: {
-          MapTypeInfo mapTypeInfo = (MapTypeInfo)typeInfo;
-          ObjectInspector keyObjectInspector = getStandardJavaObjectInspectorFromTypeInfo(mapTypeInfo.getMapKeyTypeInfo());
-          ObjectInspector valueObjectInspector = getStandardJavaObjectInspectorFromTypeInfo(mapTypeInfo.getMapValueTypeInfo());
-          result = ObjectInspectorFactory.getStandardMapObjectInspector(keyObjectInspector, valueObjectInspector);
-          break;
-        }
-        case STRUCT: {
-          StructTypeInfo strucTypeInfo = (StructTypeInfo)typeInfo;
-          List<String> fieldNames = strucTypeInfo.getAllStructFieldNames();
-          List<TypeInfo> fieldTypeInfos = strucTypeInfo.getAllStructFieldTypeInfos();
-          List<ObjectInspector> fieldObjectInspectors = new ArrayList<ObjectInspector>(fieldTypeInfos.size());
-          for(int i=0; i<fieldTypeInfos.size(); i++) {
-            fieldObjectInspectors.add(getStandardJavaObjectInspectorFromTypeInfo(fieldTypeInfos.get(i)));
-          }
-          result = ObjectInspectorFactory.getStandardStructObjectInspector(fieldNames, fieldObjectInspectors);
-          break;
-        }
-        default: {
-          result = null;
-        }
-      }
-      cachedStandardJavaObjectInspector.put(typeInfo, result);
-    }
-    return result;
-  }
-  
-  /**
-   * Get the TypeInfo object from the ObjectInspector object by recursively going into the
-   * ObjectInspector structure.
-   */
-  public static TypeInfo getTypeInfoFromObjectInspector(ObjectInspector oi) {
-//    OPTIMIZATION for later.
-//    if (oi instanceof TypeInfoBasedObjectInspector) {
-//      TypeInfoBasedObjectInspector typeInfoBasedObjectInspector = (ObjectInspector)oi;
-//      return typeInfoBasedObjectInspector.getTypeInfo();
-//    }
-    
-    // Recursively going into ObjectInspector structure
-    TypeInfo result = null;
-    switch (oi.getCategory()) {
+      switch (typeInfo.getCategory()) {
       case PRIMITIVE: {
-        PrimitiveObjectInspector poi =(PrimitiveObjectInspector)oi;
-        result = TypeInfoFactory.getPrimitiveTypeInfo(poi.getTypeName());
+        // NOTE: we use JavaPrimitiveObjectInspector instead of
+        // StandardPrimitiveObjectInspector
+        result = PrimitiveObjectInspectorFactory
+            .getPrimitiveJavaObjectInspector(PrimitiveObjectInspectorUtils
+                .getTypeEntryFromTypeName(typeInfo.getTypeName()).primitiveCategory);
         break;
       }
       case LIST: {
-        ListObjectInspector loi = (ListObjectInspector)oi;
-        result = TypeInfoFactory.getListTypeInfo(
-            getTypeInfoFromObjectInspector(loi.getListElementObjectInspector()));
+        ObjectInspector elementObjectInspector = getStandardJavaObjectInspectorFromTypeInfo(((ListTypeInfo) typeInfo)
+            .getListElementTypeInfo());
+        result = ObjectInspectorFactory
+            .getStandardListObjectInspector(elementObjectInspector);
         break;
       }
       case MAP: {
-        MapObjectInspector moi = (MapObjectInspector)oi;
-        result = TypeInfoFactory.getMapTypeInfo(
-            getTypeInfoFromObjectInspector(moi.getMapKeyObjectInspector()),
-            getTypeInfoFromObjectInspector(moi.getMapValueObjectInspector()));
+        MapTypeInfo mapTypeInfo = (MapTypeInfo) typeInfo;
+        ObjectInspector keyObjectInspector = getStandardJavaObjectInspectorFromTypeInfo(mapTypeInfo
+            .getMapKeyTypeInfo());
+        ObjectInspector valueObjectInspector = getStandardJavaObjectInspectorFromTypeInfo(mapTypeInfo
+            .getMapValueTypeInfo());
+        result = ObjectInspectorFactory.getStandardMapObjectInspector(
+            keyObjectInspector, valueObjectInspector);
         break;
       }
       case STRUCT: {
-        StructObjectInspector soi = (StructObjectInspector)oi;
-        List<? extends StructField> fields = soi.getAllStructFieldRefs();
-        List<String> fieldNames = new ArrayList<String>(fields.size());
-        List<TypeInfo> fieldTypeInfos = new ArrayList<TypeInfo>(fields.size());
-        for(StructField f : fields) {
-          fieldNames.add(f.getFieldName());
-          fieldTypeInfos.add(getTypeInfoFromObjectInspector(f.getFieldObjectInspector()));
+        StructTypeInfo strucTypeInfo = (StructTypeInfo) typeInfo;
+        List<String> fieldNames = strucTypeInfo.getAllStructFieldNames();
+        List<TypeInfo> fieldTypeInfos = strucTypeInfo
+            .getAllStructFieldTypeInfos();
+        List<ObjectInspector> fieldObjectInspectors = new ArrayList<ObjectInspector>(
+            fieldTypeInfos.size());
+        for (int i = 0; i < fieldTypeInfos.size(); i++) {
+          fieldObjectInspectors
+              .add(getStandardJavaObjectInspectorFromTypeInfo(fieldTypeInfos
+                  .get(i)));
         }
-        result = TypeInfoFactory.getStructTypeInfo(fieldNames, fieldTypeInfos);
+        result = ObjectInspectorFactory.getStandardStructObjectInspector(
+            fieldNames, fieldObjectInspectors);
         break;
       }
       default: {
-        throw new RuntimeException("Unknown ObjectInspector category!");
+        result = null;
+      }
+      }
+      cachedStandardJavaObjectInspector.put(typeInfo, result);
+    }
+    return result;
+  }
+
+  /**
+   * Get the TypeInfo object from the ObjectInspector object by recursively
+   * going into the ObjectInspector structure.
+   */
+  public static TypeInfo getTypeInfoFromObjectInspector(ObjectInspector oi) {
+    // OPTIMIZATION for later.
+    // if (oi instanceof TypeInfoBasedObjectInspector) {
+    // TypeInfoBasedObjectInspector typeInfoBasedObjectInspector =
+    // (ObjectInspector)oi;
+    // return typeInfoBasedObjectInspector.getTypeInfo();
+    // }
+
+    // Recursively going into ObjectInspector structure
+    TypeInfo result = null;
+    switch (oi.getCategory()) {
+    case PRIMITIVE: {
+      PrimitiveObjectInspector poi = (PrimitiveObjectInspector) oi;
+      result = TypeInfoFactory.getPrimitiveTypeInfo(poi.getTypeName());
+      break;
+    }
+    case LIST: {
+      ListObjectInspector loi = (ListObjectInspector) oi;
+      result = TypeInfoFactory
+          .getListTypeInfo(getTypeInfoFromObjectInspector(loi
+              .getListElementObjectInspector()));
+      break;
+    }
+    case MAP: {
+      MapObjectInspector moi = (MapObjectInspector) oi;
+      result = TypeInfoFactory.getMapTypeInfo(
+          getTypeInfoFromObjectInspector(moi.getMapKeyObjectInspector()),
+          getTypeInfoFromObjectInspector(moi.getMapValueObjectInspector()));
+      break;
+    }
+    case STRUCT: {
+      StructObjectInspector soi = (StructObjectInspector) oi;
+      List<? extends StructField> fields = soi.getAllStructFieldRefs();
+      List<String> fieldNames = new ArrayList<String>(fields.size());
+      List<TypeInfo> fieldTypeInfos = new ArrayList<TypeInfo>(fields.size());
+      for (StructField f : fields) {
+        fieldNames.add(f.getFieldName());
+        fieldTypeInfos.add(getTypeInfoFromObjectInspector(f
+            .getFieldObjectInspector()));
       }
+      result = TypeInfoFactory.getStructTypeInfo(fieldNames, fieldTypeInfos);
+      break;
+    }
+    default: {
+      throw new RuntimeException("Unknown ObjectInspector category!");
+    }
     }
     return result;
   }
-    
+
   public static ArrayList<TypeInfo> getTypeInfosFromTypeString(String typeString) {
     TypeInfoParser parser = new TypeInfoParser(typeString);
     return parser.parseTypeInfos();

Modified: hadoop/hive/trunk/serde/src/test/org/apache/hadoop/hive/serde2/TestTCTLSeparatedProtocol.java
URL: http://svn.apache.org/viewvc/hadoop/hive/trunk/serde/src/test/org/apache/hadoop/hive/serde2/TestTCTLSeparatedProtocol.java?rev=901625&r1=901624&r2=901625&view=diff
==============================================================================
--- hadoop/hive/trunk/serde/src/test/org/apache/hadoop/hive/serde2/TestTCTLSeparatedProtocol.java (original)
+++ hadoop/hive/trunk/serde/src/test/org/apache/hadoop/hive/serde2/TestTCTLSeparatedProtocol.java Thu Jan 21 09:52:44 2010
@@ -18,7 +18,6 @@
 
 package org.apache.hadoop.hive.serde2;
 
-
 import java.util.Properties;
 
 import junit.framework.TestCase;
@@ -26,7 +25,6 @@
 import org.apache.hadoop.conf.Configuration;
 import org.apache.hadoop.hive.serde.Constants;
 import org.apache.hadoop.hive.serde2.thrift.TCTLSeparatedProtocol;
-
 import org.apache.thrift.protocol.TField;
 import org.apache.thrift.protocol.TList;
 import org.apache.thrift.protocol.TMap;
@@ -44,14 +42,13 @@
     String bar = "World!";
 
     String key = "22";
-    String  value = "TheValue";
+    String value = "TheValue";
     String key2 = "24";
-    String  value2 = "TheValueAgain";
-
-    byte columnSeparator [] = { 1 };
-    byte elementSeparator [] = { 2 };
-    byte kvSeparator [] = { 3 };
+    String value2 = "TheValueAgain";
 
+    byte columnSeparator[] = { 1 };
+    byte elementSeparator[] = { 2 };
+    byte kvSeparator[] = { 3 };
 
     trans.write(foo.getBytes(), 0, foo.getBytes().length);
     trans.write(columnSeparator, 0, 1);
@@ -61,19 +58,17 @@
     trans.write(bar.getBytes(), 0, bar.getBytes().length);
     trans.write(columnSeparator, 0, 1);
 
-    trans.write(key.getBytes(), 0, key.getBytes().length); 
+    trans.write(key.getBytes(), 0, key.getBytes().length);
     trans.write(kvSeparator, 0, 1);
     trans.write(value.getBytes(), 0, value.getBytes().length);
     trans.write(elementSeparator, 0, 1);
 
-    trans.write(key2.getBytes(), 0, key2.getBytes().length); 
+    trans.write(key2.getBytes(), 0, key2.getBytes().length);
     trans.write(kvSeparator, 0, 1);
     trans.write(value2.getBytes(), 0, value2.getBytes().length);
-    
 
     trans.flush();
 
-
     // use 3 as the row buffer size to force lots of re-buffering.
     TCTLSeparatedProtocol prot = new TCTLSeparatedProtocol(trans, 1024);
     prot.initialize(new Configuration(), new Properties());
@@ -113,7 +108,6 @@
     prot.readStructEnd();
   }
 
-
   public void testWrites() throws Exception {
     TMemoryBuffer trans = new TMemoryBuffer(1024);
     TCTLSeparatedProtocol prot = new TCTLSeparatedProtocol(trans, 1024);
@@ -152,15 +146,14 @@
     prot.writeListEnd();
     prot.writeFieldEnd();
 
-    
     prot.writeFieldBegin(new TField());
     prot.writeString("bye!");
     prot.writeFieldEnd();
 
     prot.writeStructEnd();
     trans.flush();
-    byte b[] = new byte[3*1024];
-    int len = trans.read(b,0,b.length);
+    byte b[] = new byte[3 * 1024];
+    int len = trans.read(b, 0, b.length);
     String test = new String(b, 0, len);
 
     String testRef = "100348.55234.22hello world!key1val1key2val2key3val3elem1elem2bye!";
@@ -175,7 +168,7 @@
 
     prot = new TCTLSeparatedProtocol(trans, 10);
     prot.initialize(new Configuration(), new Properties());
-    
+
     // 100 is the start
     prot.readStructBegin();
     prot.readFieldBegin();
@@ -265,11 +258,10 @@
     trans.flush();
 
     byte b[] = new byte[4096];
-    int len = trans.read(b,0,b.length);
-
+    int len = trans.read(b, 0, b.length);
 
     trans = new TMemoryBuffer(4096);
-    trans.write(b,0,len);
+    trans.write(b, 0, len);
     prot = new TCTLSeparatedProtocol(trans, 1024);
     prot.initialize(new Configuration(), schema);
 
@@ -278,11 +270,10 @@
     final String firstRead = prot.readString();
     prot.readFieldEnd();
 
-    testStr = testStr.replace("\"","");
+    testStr = testStr.replace("\"", "");
 
     assertEquals(testStr, firstRead);
 
-
     // the 2 element list
     prot.readFieldBegin();
     TList l = prot.readListBegin();
@@ -305,10 +296,10 @@
     prot.readStructEnd();
   }
 
-
   /**
-   * Tests a sample apache log format. This is actually better done in general with a more TRegexLike protocol, but for this
-   * case, TCTLSeparatedProtocol can do it. 
+   * Tests a sample apache log format. This is actually better done in general
+   * with a more TRegexLike protocol, but for this case, TCTLSeparatedProtocol
+   * can do it.
    */
   public void test1ApacheLogFormat() throws Exception {
     final String sample = "127.0.0.1 - frank [10/Oct/2000:13:55:36 -0700] \"GET /apache_pb.gif HTTP/1.0\" 200 2326";
@@ -320,7 +311,8 @@
     TCTLSeparatedProtocol prot = new TCTLSeparatedProtocol(trans, 4096);
     Properties schema = new Properties();
 
-    // this is a hacky way of doing the quotes since it will match any 2 of these, so
+    // this is a hacky way of doing the quotes since it will match any 2 of
+    // these, so
     // "[ hello this is something to split [" would be considered to be quoted.
     schema.setProperty(Constants.QUOTE_CHAR, "(\"|\\[|\\])");
 
@@ -337,42 +329,42 @@
 
     assertEquals("127.0.0.1", ip);
 
-    //  identd
+    // identd
     prot.readFieldBegin();
     final String identd = prot.readString();
     prot.readFieldEnd();
 
     assertNull(identd);
 
-    //  user
+    // user
     prot.readFieldBegin();
     final String user = prot.readString();
     prot.readFieldEnd();
 
-    assertEquals("frank",user);
+    assertEquals("frank", user);
 
-    //  finishTime
+    // finishTime
     prot.readFieldBegin();
     final String finishTime = prot.readString();
     prot.readFieldEnd();
 
-    assertEquals("10/Oct/2000:13:55:36 -0700",finishTime);
+    assertEquals("10/Oct/2000:13:55:36 -0700", finishTime);
 
-    //  requestLine
+    // requestLine
     prot.readFieldBegin();
     final String requestLine = prot.readString();
     prot.readFieldEnd();
 
-    assertEquals("GET /apache_pb.gif HTTP/1.0",requestLine);
+    assertEquals("GET /apache_pb.gif HTTP/1.0", requestLine);
 
-    //  returncode
+    // returncode
     prot.readFieldBegin();
     final int returnCode = prot.readI32();
     prot.readFieldEnd();
 
     assertEquals(200, returnCode);
 
-    //  return size
+    // return size
     prot.readFieldBegin();
     final int returnSize = prot.readI32();
     prot.readFieldEnd();
@@ -382,8 +374,6 @@
     prot.readStructEnd();
   }
 
-
-
   public void testNulls() throws Exception {
     TMemoryBuffer trans = new TMemoryBuffer(1024);
     TCTLSeparatedProtocol prot = new TCTLSeparatedProtocol(trans, 10);
@@ -420,9 +410,9 @@
 
     prot.writeStructEnd();
 
-    byte b[] = new byte[3*1024];
-    int len = trans.read(b,0,b.length);
-    String written = new String(b,0,len);
+    byte b[] = new byte[3 * 1024];
+    int len = trans.read(b, 0, b.length);
+    String written = new String(b, 0, len);
 
     String testRef = "\\N\\N100\\N\\N\\Nkey2\\N\\Nval3";
 
@@ -433,7 +423,7 @@
 
     prot = new TCTLSeparatedProtocol(trans, 3);
     prot.initialize(new Configuration(), new Properties());
-    
+
     prot.readStructBegin();
 
     prot.readFieldBegin();
@@ -445,7 +435,7 @@
     prot.readFieldBegin();
     ret = prot.readString();
     prot.readFieldEnd();
-    
+
     assertNull(ret);
 
     prot.readFieldBegin();
@@ -454,13 +444,12 @@
 
     assertTrue(ret1 == 100);
 
-
     prot.readFieldBegin();
     ret1 = prot.readI32();
     prot.readFieldEnd();
 
     prot.readFieldBegin();
-    TMap map =  prot.readMapBegin();
+    TMap map = prot.readMapBegin();
 
     assertTrue(map.size == 3);
 
@@ -472,7 +461,7 @@
 
     assertNull(prot.readString());
     assertTrue(prot.readString().equals("val3"));
-    
+
     prot.readMapEnd();
     prot.readFieldEnd();
 

Modified: hadoop/hive/trunk/serde/src/test/org/apache/hadoop/hive/serde2/binarysortable/MyTestClass.java
URL: http://svn.apache.org/viewvc/hadoop/hive/trunk/serde/src/test/org/apache/hadoop/hive/serde2/binarysortable/MyTestClass.java?rev=901625&r1=901624&r2=901625&view=diff
==============================================================================
--- hadoop/hive/trunk/serde/src/test/org/apache/hadoop/hive/serde2/binarysortable/MyTestClass.java (original)
+++ hadoop/hive/trunk/serde/src/test/org/apache/hadoop/hive/serde2/binarysortable/MyTestClass.java Thu Jan 21 09:52:44 2010
@@ -29,21 +29,20 @@
   String myString;
   MyTestInnerStruct myStruct;
   List<Integer> myList;
-  
-  public MyTestClass() {  
+
+  public MyTestClass() {
   }
-  
-  public MyTestClass(Byte b, Short s, Integer i, Long l, 
-      Float f, Double d, String st, MyTestInnerStruct is, 
-      List<Integer> li) {
-    this.myByte = b;
-    this.myShort = s;
-    this.myInt = i;
-    this.myLong = l;
-    this.myFloat = f;
-    this.myDouble = d;
-    this.myString = st;
-    this.myStruct = is;
-    this.myList = li;
+
+  public MyTestClass(Byte b, Short s, Integer i, Long l, Float f, Double d,
+      String st, MyTestInnerStruct is, List<Integer> li) {
+    myByte = b;
+    myShort = s;
+    myInt = i;
+    myLong = l;
+    myFloat = f;
+    myDouble = d;
+    myString = st;
+    myStruct = is;
+    myList = li;
   }
 }

Modified: hadoop/hive/trunk/serde/src/test/org/apache/hadoop/hive/serde2/binarysortable/MyTestInnerStruct.java
URL: http://svn.apache.org/viewvc/hadoop/hive/trunk/serde/src/test/org/apache/hadoop/hive/serde2/binarysortable/MyTestInnerStruct.java?rev=901625&r1=901624&r2=901625&view=diff
==============================================================================
--- hadoop/hive/trunk/serde/src/test/org/apache/hadoop/hive/serde2/binarysortable/MyTestInnerStruct.java (original)
+++ hadoop/hive/trunk/serde/src/test/org/apache/hadoop/hive/serde2/binarysortable/MyTestInnerStruct.java Thu Jan 21 09:52:44 2010
@@ -21,14 +21,13 @@
 
   Integer int1;
   Integer int2;
-  
+
   public MyTestInnerStruct() {
   }
-  
+
   public MyTestInnerStruct(Integer int1, Integer int2) {
     this.int1 = int1;
     this.int2 = int2;
   }
 
 }
-

Modified: hadoop/hive/trunk/serde/src/test/org/apache/hadoop/hive/serde2/binarysortable/TestBinarySortableSerDe.java
URL: http://svn.apache.org/viewvc/hadoop/hive/trunk/serde/src/test/org/apache/hadoop/hive/serde2/binarysortable/TestBinarySortableSerDe.java?rev=901625&r1=901624&r2=901625&view=diff
==============================================================================
--- hadoop/hive/trunk/serde/src/test/org/apache/hadoop/hive/serde2/binarysortable/TestBinarySortableSerDe.java (original)
+++ hadoop/hive/trunk/serde/src/test/org/apache/hadoop/hive/serde2/binarysortable/TestBinarySortableSerDe.java Thu Jan 21 09:52:44 2010
@@ -23,6 +23,8 @@
 import java.util.Properties;
 import java.util.Random;
 
+import junit.framework.TestCase;
+
 import org.apache.hadoop.conf.Configuration;
 import org.apache.hadoop.hive.serde.Constants;
 import org.apache.hadoop.hive.serde2.SerDe;
@@ -32,32 +34,30 @@
 import org.apache.hadoop.hive.serde2.objectinspector.ObjectInspectorUtils;
 import org.apache.hadoop.hive.serde2.objectinspector.StructObjectInspector;
 import org.apache.hadoop.hive.serde2.objectinspector.ObjectInspectorFactory.ObjectInspectorOptions;
-
-import junit.framework.TestCase;
 import org.apache.hadoop.io.BytesWritable;
 
-
 public class TestBinarySortableSerDe extends TestCase {
 
-  public static HashMap<String,String> makeHashMap(String... params) {
-    HashMap<String,String> r = new HashMap<String,String>(); 
-    for(int i=0; i<params.length; i+=2) {
-      r.put(params[i], params[i+1]);
+  public static HashMap<String, String> makeHashMap(String... params) {
+    HashMap<String, String> r = new HashMap<String, String>();
+    for (int i = 0; i < params.length; i += 2) {
+      r.put(params[i], params[i + 1]);
     }
     return r;
   }
 
   public static String hexString(BytesWritable bytes) {
     StringBuilder sb = new StringBuilder();
-    for (int i=0; i<bytes.getSize(); i++) {
+    for (int i = 0; i < bytes.getSize(); i++) {
       byte b = bytes.get()[i];
-      int v = (b<0 ? 256 + b : b);
+      int v = (b < 0 ? 256 + b : b);
       sb.append(String.format("x%02x", v));
     }
     return sb.toString();
   }
 
-  private SerDe getSerDe(String fieldNames, String fieldTypes, String order) throws Throwable {
+  private SerDe getSerDe(String fieldNames, String fieldTypes, String order)
+      throws Throwable {
     Properties schema = new Properties();
     schema.setProperty(Constants.LIST_COLUMNS, fieldNames);
     schema.setProperty(Constants.LIST_COLUMN_TYPES, fieldTypes);
@@ -67,109 +67,125 @@
     serde.initialize(new Configuration(), schema);
     return serde;
   }
-  
-  private void testBinarySortableSerDe(Object[] rows, 
-      ObjectInspector rowOI, SerDe serde, boolean ascending) throws Throwable{
-    
+
+  private void testBinarySortableSerDe(Object[] rows, ObjectInspector rowOI,
+      SerDe serde, boolean ascending) throws Throwable {
+
     ObjectInspector serdeOI = serde.getObjectInspector();
 
     // Try to serialize
     BytesWritable bytes[] = new BytesWritable[rows.length];
-    for (int i=0; i<rows.length; i++) {
-      BytesWritable s = (BytesWritable)serde.serialize(rows[i], rowOI);
+    for (int i = 0; i < rows.length; i++) {
+      BytesWritable s = (BytesWritable) serde.serialize(rows[i], rowOI);
       bytes[i] = new BytesWritable();
       bytes[i].set(s);
-      if (i>0) {
-        int compareResult = bytes[i-1].compareTo(bytes[i]);
-        if ( (compareResult<0 && !ascending) || (compareResult>0 && ascending) ) {
-          System.out.println("Test failed in " + (ascending ? "ascending" : "descending")
-              + " order with " + (i-1) + " and " + i);
-          System.out.println("serialized data [" + (i-1) + "] = " + hexString(bytes[i-1]));
-          System.out.println("serialized data [" + i + "] = " + hexString(bytes[i]));
-          System.out.println("deserialized data [" + (i-1) + " = " + 
-              SerDeUtils.getJSONString(rows[i-1], rowOI));
-          System.out.println("deserialized data [" + i + " = " + 
-              SerDeUtils.getJSONString(rows[i], rowOI));
-          fail("Sort order of serialized " + (i-1) + " and " + i + " are reversed!");            
+      if (i > 0) {
+        int compareResult = bytes[i - 1].compareTo(bytes[i]);
+        if ((compareResult < 0 && !ascending)
+            || (compareResult > 0 && ascending)) {
+          System.out.println("Test failed in "
+              + (ascending ? "ascending" : "descending") + " order with "
+              + (i - 1) + " and " + i);
+          System.out.println("serialized data [" + (i - 1) + "] = "
+              + hexString(bytes[i - 1]));
+          System.out.println("serialized data [" + i + "] = "
+              + hexString(bytes[i]));
+          System.out.println("deserialized data [" + (i - 1) + " = "
+              + SerDeUtils.getJSONString(rows[i - 1], rowOI));
+          System.out.println("deserialized data [" + i + " = "
+              + SerDeUtils.getJSONString(rows[i], rowOI));
+          fail("Sort order of serialized " + (i - 1) + " and " + i
+              + " are reversed!");
         }
       }
     }
 
     // Try to deserialize
     Object[] deserialized = new Object[rows.length];
-    for (int i=0; i<rows.length; i++) {
+    for (int i = 0; i < rows.length; i++) {
       deserialized[i] = serde.deserialize(bytes[i]);
-      if (0 != ObjectInspectorUtils.compare(rows[i], rowOI, deserialized[i], serdeOI)) {
-        System.out.println("structs[" + i + "] = " + SerDeUtils.getJSONString(rows[i], rowOI));
-        System.out.println("deserialized[" + i + "] = " + SerDeUtils.getJSONString(deserialized[i], serdeOI));
+      if (0 != ObjectInspectorUtils.compare(rows[i], rowOI, deserialized[i],
+          serdeOI)) {
+        System.out.println("structs[" + i + "] = "
+            + SerDeUtils.getJSONString(rows[i], rowOI));
+        System.out.println("deserialized[" + i + "] = "
+            + SerDeUtils.getJSONString(deserialized[i], serdeOI));
         System.out.println("serialized[" + i + "] = " + hexString(bytes[i]));
         assertEquals(rows[i], deserialized[i]);
       }
     }
   }
-  
+
   private void sort(Object[] structs, ObjectInspector oi) {
-    for (int i=0; i<structs.length; i++) for (int j=i+1; j<structs.length; j++)
-      if (ObjectInspectorUtils.compare(structs[i], oi, structs[j], oi)>0) {
-        Object t = structs[i];
-        structs[i] = structs[j];
-        structs[j] = t;
+    for (int i = 0; i < structs.length; i++) {
+      for (int j = i + 1; j < structs.length; j++) {
+        if (ObjectInspectorUtils.compare(structs[i], oi, structs[j], oi) > 0) {
+          Object t = structs[i];
+          structs[i] = structs[j];
+          structs[j] = t;
+        }
       }
-  }  
+    }
+  }
 
   public static String getRandString(Random r) {
     int length = r.nextInt(10);
     StringBuilder sb = new StringBuilder();
-    for(int i=0; i<length; i++) {
-      sb.append((char)(r.nextInt(128)));
+    for (int i = 0; i < length; i++) {
+      sb.append((char) (r.nextInt(128)));
     }
     return sb.toString();
   }
-  
+
   public static List<Integer> getRandIntegerArray(Random r) {
     int length = r.nextInt(10);
     ArrayList<Integer> result = new ArrayList<Integer>(length);
-    for(int i=0; i<length; i++) {
-      result.add((int)r.nextInt(128));
+    for (int i = 0; i < length; i++) {
+      result.add(r.nextInt(128));
     }
     return result;
   }
-  
+
   public void testBinarySortableSerDe() throws Throwable {
     try {
 
       System.out.println("Beginning Test testBinarySortableSerDe:");
-      
+
       int num = 1000;
       Random r = new Random(1234);
       MyTestClass rows[] = new MyTestClass[num];
-      
-      for (int i=0; i<num; i++) {
+
+      for (int i = 0; i < num; i++) {
         int randField = r.nextInt(10);
         MyTestClass t = new MyTestClass();
-        t.myByte = randField > 0 ? null : Byte.valueOf((byte)r.nextInt());
-        t.myShort = randField > 1 ? null : Short.valueOf((short)r.nextInt());
+        t.myByte = randField > 0 ? null : Byte.valueOf((byte) r.nextInt());
+        t.myShort = randField > 1 ? null : Short.valueOf((short) r.nextInt());
         t.myInt = randField > 2 ? null : Integer.valueOf(r.nextInt());
         t.myLong = randField > 3 ? null : Long.valueOf(r.nextLong());
-        t.myFloat = randField > 4 ? null : Float.valueOf(r.nextFloat() * 10 - 5);
-        t.myDouble = randField > 5 ? null : Double.valueOf(r.nextDouble() * 10 - 5);
+        t.myFloat = randField > 4 ? null : Float
+            .valueOf(r.nextFloat() * 10 - 5);
+        t.myDouble = randField > 5 ? null : Double
+            .valueOf(r.nextDouble() * 10 - 5);
         t.myString = randField > 6 ? null : getRandString(r);
-        t.myStruct = randField > 7 ? null : new MyTestInnerStruct(r.nextInt(5)-2, r.nextInt(5)-2);
-        t.myList = randField > 8 ? null: getRandIntegerArray(r);
+        t.myStruct = randField > 7 ? null : new MyTestInnerStruct(
+            r.nextInt(5) - 2, r.nextInt(5) - 2);
+        t.myList = randField > 8 ? null : getRandIntegerArray(r);
         rows[i] = t;
       }
 
-      StructObjectInspector rowOI = (StructObjectInspector)ObjectInspectorFactory
-      .getReflectionObjectInspector(MyTestClass.class,
-           ObjectInspectorOptions.JAVA);
+      StructObjectInspector rowOI = (StructObjectInspector) ObjectInspectorFactory
+          .getReflectionObjectInspector(MyTestClass.class,
+              ObjectInspectorOptions.JAVA);
       sort(rows, rowOI);
-      
+
       String fieldNames = ObjectInspectorUtils.getFieldNames(rowOI);
       String fieldTypes = ObjectInspectorUtils.getFieldTypes(rowOI);
-      
-      testBinarySortableSerDe(rows, rowOI, getSerDe(fieldNames, fieldTypes, "++++++++++"), true);
-      testBinarySortableSerDe(rows, rowOI, getSerDe(fieldNames, fieldTypes, "----------"), false);
-      
+
+      testBinarySortableSerDe(rows, rowOI, getSerDe(fieldNames, fieldTypes,
+          "++++++++++"), true);
+      testBinarySortableSerDe(rows, rowOI, getSerDe(fieldNames, fieldTypes,
+          "----------"), false);
+
       System.out.println("Test testTBinarySortableProtocol passed!");
     } catch (Throwable e) {
       e.printStackTrace();
@@ -177,6 +193,4 @@
     }
   }
 
-
-
 }



Mime
View raw message