hive-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From na...@apache.org
Subject svn commit: r790435 [3/3] - in /hadoop/hive/trunk: ./ ql/src/java/org/apache/hadoop/hive/ql/exec/ ql/src/java/org/apache/hadoop/hive/ql/parse/ ql/src/java/org/apache/hadoop/hive/ql/plan/ ql/src/test/org/apache/hadoop/hive/ql/io/ ql/src/test/queries/cli...
Date Thu, 02 Jul 2009 02:03:16 GMT
Modified: hadoop/hive/trunk/serde/src/java/org/apache/hadoop/hive/serde2/objectinspector/ObjectInspectorFactory.java
URL: http://svn.apache.org/viewvc/hadoop/hive/trunk/serde/src/java/org/apache/hadoop/hive/serde2/objectinspector/ObjectInspectorFactory.java?rev=790435&r1=790434&r2=790435&view=diff
==============================================================================
--- hadoop/hive/trunk/serde/src/java/org/apache/hadoop/hive/serde2/objectinspector/ObjectInspectorFactory.java (original)
+++ hadoop/hive/trunk/serde/src/java/org/apache/hadoop/hive/serde2/objectinspector/ObjectInspectorFactory.java Thu Jul  2 02:03:14 2009
@@ -27,10 +27,8 @@
 import java.util.List;
 import java.util.Map;
 
-import org.apache.hadoop.hive.serde2.objectinspector.PrimitiveObjectInspector.PrimitiveCategory;
 import org.apache.hadoop.hive.serde2.objectinspector.primitive.PrimitiveObjectInspectorFactory;
 import org.apache.hadoop.hive.serde2.objectinspector.primitive.PrimitiveObjectInspectorUtils;
-import org.apache.hadoop.hive.serde2.objectinspector.primitive.WritableBooleanObjectInspector;
 import org.apache.hadoop.io.Text;
 
 
@@ -192,60 +190,6 @@
     return result;
   }
 
-  static HashMap<ArrayList<Object>, LazySimpleStructObjectInspector> cachedLazySimpleStructObjectInspector =
-    new HashMap<ArrayList<Object>, LazySimpleStructObjectInspector>(); 
-  public static LazySimpleStructObjectInspector getLazySimpleStructObjectInspector(List<String> structFieldNames, 
-      List<ObjectInspector> structFieldObjectInspectors, byte separator, Text nullSequence,
-      boolean lastColumnTakesRest) {
-    ArrayList<Object> signature = new ArrayList<Object>();
-    signature.add(structFieldNames);
-    signature.add(structFieldObjectInspectors);
-    signature.add(Byte.valueOf(separator));
-    signature.add(nullSequence.toString());
-    signature.add(Boolean.valueOf(lastColumnTakesRest));
-    LazySimpleStructObjectInspector result = cachedLazySimpleStructObjectInspector.get(signature);
-    if (result == null) {
-      result = new LazySimpleStructObjectInspector(structFieldNames, structFieldObjectInspectors, 
-          separator, nullSequence, lastColumnTakesRest);
-      cachedLazySimpleStructObjectInspector.put(signature, result);
-    }
-    return result;
-  }
-
-  static HashMap<ArrayList<Object>, LazyListObjectInspector> cachedLazySimpleListObjectInspector =
-    new HashMap<ArrayList<Object>, LazyListObjectInspector>(); 
-  public static LazyListObjectInspector getLazySimpleListObjectInspector( 
-      ObjectInspector listElementObjectInspector, byte separator, Text nullSequence) {
-    ArrayList<Object> signature = new ArrayList<Object>();
-    signature.add(listElementObjectInspector);
-    signature.add(Byte.valueOf(separator));
-    signature.add(nullSequence.toString());
-    LazyListObjectInspector result = cachedLazySimpleListObjectInspector.get(signature);
-    if (result == null) {
-      result = new LazyListObjectInspector(listElementObjectInspector, 
-          separator, nullSequence);
-      cachedLazySimpleListObjectInspector.put(signature, result);
-    }
-    return result;
-  }
-  
-  static HashMap<ArrayList<Object>, LazyMapObjectInspector> cachedLazySimpleMapObjectInspector =
-    new HashMap<ArrayList<Object>, LazyMapObjectInspector>(); 
-  public static LazyMapObjectInspector getLazySimpleMapObjectInspector( 
-      ObjectInspector mapKeyObjectInspector, ObjectInspector mapValueObjectInspector, 
-      byte itemSeparator, byte keyValueSeparator, Text nullSequence) {
-    ArrayList<Object> signature = new ArrayList<Object>();
-    signature.add(mapKeyObjectInspector);
-    signature.add(mapValueObjectInspector);
-    signature.add(nullSequence.toString());
-    LazyMapObjectInspector result = cachedLazySimpleMapObjectInspector.get(signature);
-    if (result == null) {
-      result = new LazyMapObjectInspector(mapKeyObjectInspector,
-          mapValueObjectInspector, itemSeparator, keyValueSeparator, nullSequence);
-      cachedLazySimpleMapObjectInspector.put(signature, result);
-    }
-    return result;
-  }
   
   static HashMap<List<StructObjectInspector>, UnionStructObjectInspector> cachedUnionStructObjectInspector =
     new HashMap<List<StructObjectInspector>, UnionStructObjectInspector>(); 

Modified: hadoop/hive/trunk/serde/src/java/org/apache/hadoop/hive/serde2/objectinspector/ObjectInspectorUtils.java
URL: http://svn.apache.org/viewvc/hadoop/hive/trunk/serde/src/java/org/apache/hadoop/hive/serde2/objectinspector/ObjectInspectorUtils.java?rev=790435&r1=790434&r2=790435&view=diff
==============================================================================
--- hadoop/hive/trunk/serde/src/java/org/apache/hadoop/hive/serde2/objectinspector/ObjectInspectorUtils.java (original)
+++ hadoop/hive/trunk/serde/src/java/org/apache/hadoop/hive/serde2/objectinspector/ObjectInspectorUtils.java Thu Jul  2 02:03:14 2009
@@ -83,13 +83,13 @@
   /**
    * This enum controls how we copy primitive objects.
    * 
-   * KEEP means keeping the original format of the primitive object. This is usually the most efficient. 
+   * DEFAULT means choosing the most efficient way between JAVA and WRITABLE. 
    * JAVA means converting all primitive objects to java primitive objects.
    * WRITABLE means converting all primitive objects to writable objects. 
    *
    */
   public enum ObjectInspectorCopyOption {
-    KEEP,
+    DEFAULT,
     JAVA,
     WRITABLE
   }
@@ -100,7 +100,7 @@
    * The returned ObjectInspector can be used to inspect the standard object.
    */
   public static ObjectInspector getStandardObjectInspector(ObjectInspector oi) {
-    return getStandardObjectInspector(oi, ObjectInspectorCopyOption.KEEP);
+    return getStandardObjectInspector(oi, ObjectInspectorCopyOption.DEFAULT);
   }
   
   public static ObjectInspector getStandardObjectInspector(ObjectInspector oi, ObjectInspectorCopyOption objectInspectorOption) {
@@ -109,8 +109,12 @@
       case PRIMITIVE: {
         PrimitiveObjectInspector poi = (PrimitiveObjectInspector)oi;
         switch (objectInspectorOption) {
-          case KEEP: {
-            result = poi;
+          case DEFAULT: {
+            if (poi.preferWritable()) {
+              result = PrimitiveObjectInspectorFactory.getPrimitiveWritableObjectInspector(poi.getPrimitiveCategory());
+            } else {
+              result = PrimitiveObjectInspectorFactory.getPrimitiveJavaObjectInspector(poi.getPrimitiveCategory());
+            }
             break;
           }
           case JAVA: {
@@ -161,7 +165,7 @@
    * StandardObjectInspector returned by getStandardObjectInspector(oi).
    */
   public static Object copyToStandardObject(Object o, ObjectInspector oi) {
-    return copyToStandardObject(o, oi, ObjectInspectorCopyOption.KEEP);
+    return copyToStandardObject(o, oi, ObjectInspectorCopyOption.DEFAULT);
   }
   
   public static Object copyToStandardObject(Object o, ObjectInspector oi, ObjectInspectorCopyOption objectInspectorOption) {
@@ -174,8 +178,12 @@
       case PRIMITIVE: {
         PrimitiveObjectInspector loi = (PrimitiveObjectInspector)oi;
         switch (objectInspectorOption) {
-          case KEEP: {
-            result = loi.copyObject(o);
+          case DEFAULT: {
+            if (loi.preferWritable()) {
+              result = loi.getPrimitiveWritableObject(loi.copyObject(o));
+            } else {
+              result = loi.getPrimitiveJavaObject(o);
+            }
             break;
           }
           case JAVA: {
@@ -351,5 +359,116 @@
         throw new RuntimeException("Hash code on complex types not supported yet.");
     }
   }
+
+  public static int compare(Object o1, ObjectInspector oi1, Object o2, ObjectInspector oi2) {
+    if (oi1.getCategory() != oi2.getCategory()) {
+      return oi1.getCategory().compareTo(oi2.getCategory());
+    }
+
+    if (o1 == null) {
+      return o2 == null ? 0 : -1;
+    } else if (o2 == null) {
+      return 1;
+    }
+    
+    switch (oi1.getCategory()) {
+      case PRIMITIVE: {
+        PrimitiveObjectInspector poi1 = ((PrimitiveObjectInspector)oi1);
+        PrimitiveObjectInspector poi2 = ((PrimitiveObjectInspector)oi2);
+        if (poi1.getPrimitiveCategory() != poi2.getPrimitiveCategory()) {
+          return poi1.getPrimitiveCategory().compareTo(poi2.getPrimitiveCategory());
+        }
+        switch (poi1.getPrimitiveCategory()) {
+          case VOID: return 0;
+          case BOOLEAN: {
+            int v1 = ((BooleanObjectInspector)poi1).get(o1) ? 1 : 0;
+            int v2 = ((BooleanObjectInspector)poi2).get(o2) ? 1 : 0;
+            return v1 - v2;
+          }
+          case BYTE: {
+            int v1 = ((ByteObjectInspector)poi1).get(o1);
+            int v2 = ((ByteObjectInspector)poi2).get(o2);
+            return v1 - v2;
+          }
+          case SHORT: {
+            int v1 = ((ShortObjectInspector)poi1).get(o1);
+            int v2 = ((ShortObjectInspector)poi2).get(o2);
+            return v1 - v2;
+          }
+          case INT: {
+            int v1 = ((IntObjectInspector)poi1).get(o1);
+            int v2 = ((IntObjectInspector)poi2).get(o2);
+            return v1 > v2 ? 1 : (v1 < v2 ? -1 : 0);
+          }
+          case LONG: {
+            long v1 = ((LongObjectInspector)poi1).get(o1);
+            long v2 = ((LongObjectInspector)poi2).get(o2);
+            return v1 > v2 ? 1 : (v1 < v2 ? -1 : 0);
+          }
+          case FLOAT: {
+            float v1 = ((FloatObjectInspector)poi1).get(o1);
+            float v2 = ((FloatObjectInspector)poi2).get(o2);
+            return v1 > v2 ? 1 : (v1 < v2 ? -1 : 0);
+          }
+          case DOUBLE: {
+            double v1 = ((DoubleObjectInspector)poi1).get(o1);
+            double v2 = ((DoubleObjectInspector)poi2).get(o2);
+            return v1 > v2 ? 1 : (v1 < v2 ? -1 : 0);
+          }
+          case STRING: {
+            if (poi1.preferWritable() || poi2.preferWritable()) {
+              Text t1 = (Text)poi1.getPrimitiveWritableObject(o1);
+              Text t2 = (Text)poi2.getPrimitiveWritableObject(o2);
+              return t1 == null
+                     ? (t2 == null ? 0 : -1)
+                     : (t2 == null ? 1 : t1.compareTo(t2));
+            } else {
+              String s1 = (String)poi1.getPrimitiveJavaObject(o1);
+              String s2 = (String)poi2.getPrimitiveJavaObject(o2);
+              return s1 == null
+                     ? (s2 == null ? 0 : -1)
+                     : (s2 == null ? 1 : s1.compareTo(s2));
+            }
+          }
+          default: {
+            throw new RuntimeException("Unknown type: " + poi1.getPrimitiveCategory());
+          }
+        }
+      }
+      case STRUCT: {
+        StructObjectInspector soi1 = (StructObjectInspector)oi1;
+        StructObjectInspector soi2 = (StructObjectInspector)oi2;
+        List<? extends StructField> fields1 = soi1.getAllStructFieldRefs();
+        List<? extends StructField> fields2 = soi2.getAllStructFieldRefs();
+        int minimum = Math.min(fields1.size(), fields2.size());
+        for (int i=0; i<minimum; i++) {
+          int r = compare(
+              soi1.getStructFieldData(o1, fields1.get(i)),
+              fields1.get(i).getFieldObjectInspector(),
+              soi2.getStructFieldData(o2, fields2.get(i)),
+              fields2.get(i).getFieldObjectInspector());
+          if (r != 0) return r;
+        }
+        return fields1.size() - fields2.size();
+      }
+      case LIST: {
+        ListObjectInspector loi1 = (ListObjectInspector)oi1;
+        ListObjectInspector loi2 = (ListObjectInspector)oi2;
+        int minimum = Math.min(loi1.getListLength(o1), loi1.getListLength(o2));
+        for (int i=0; i<minimum; i++) {
+          int r = compare(
+              loi1.getListElement(o1, i),
+              loi1.getListElementObjectInspector(),
+              loi2.getListElement(o2, i),
+              loi2.getListElementObjectInspector());
+          if (r != 0) return r;
+        }
+        return loi1.getListLength(o1) - loi1.getListLength(o2);
+      }
+      case MAP:
+      default:  
+        throw new RuntimeException("Hash code on map type not supported yet.");
+    }
+  }
   
 }

Modified: hadoop/hive/trunk/serde/src/java/org/apache/hadoop/hive/serde2/objectinspector/PrimitiveObjectInspector.java
URL: http://svn.apache.org/viewvc/hadoop/hive/trunk/serde/src/java/org/apache/hadoop/hive/serde2/objectinspector/PrimitiveObjectInspector.java?rev=790435&r1=790434&r2=790435&view=diff
==============================================================================
--- hadoop/hive/trunk/serde/src/java/org/apache/hadoop/hive/serde2/objectinspector/PrimitiveObjectInspector.java (original)
+++ hadoop/hive/trunk/serde/src/java/org/apache/hadoop/hive/serde2/objectinspector/PrimitiveObjectInspector.java Thu Jul  2 02:03:14 2009
@@ -69,5 +69,5 @@
    * This can be useful for determining the most efficient way to getting
    * data out of the Object. 
    */
-  public boolean isWritable();
+  public boolean preferWritable();
 }

Modified: hadoop/hive/trunk/serde/src/java/org/apache/hadoop/hive/serde2/objectinspector/primitive/AbstractPrimitiveJavaObjectInspector.java
URL: http://svn.apache.org/viewvc/hadoop/hive/trunk/serde/src/java/org/apache/hadoop/hive/serde2/objectinspector/primitive/AbstractPrimitiveJavaObjectInspector.java?rev=790435&r1=790434&r2=790435&view=diff
==============================================================================
--- hadoop/hive/trunk/serde/src/java/org/apache/hadoop/hive/serde2/objectinspector/primitive/AbstractPrimitiveJavaObjectInspector.java (original)
+++ hadoop/hive/trunk/serde/src/java/org/apache/hadoop/hive/serde2/objectinspector/primitive/AbstractPrimitiveJavaObjectInspector.java Thu Jul  2 02:03:14 2009
@@ -39,7 +39,7 @@
   }
   
   @Override
-  public boolean isWritable() {
+  public boolean preferWritable() {
     return false;
   }
 }

Modified: hadoop/hive/trunk/serde/src/java/org/apache/hadoop/hive/serde2/objectinspector/primitive/AbstractPrimitiveWritableObjectInspector.java
URL: http://svn.apache.org/viewvc/hadoop/hive/trunk/serde/src/java/org/apache/hadoop/hive/serde2/objectinspector/primitive/AbstractPrimitiveWritableObjectInspector.java?rev=790435&r1=790434&r2=790435&view=diff
==============================================================================
--- hadoop/hive/trunk/serde/src/java/org/apache/hadoop/hive/serde2/objectinspector/primitive/AbstractPrimitiveWritableObjectInspector.java (original)
+++ hadoop/hive/trunk/serde/src/java/org/apache/hadoop/hive/serde2/objectinspector/primitive/AbstractPrimitiveWritableObjectInspector.java Thu Jul  2 02:03:14 2009
@@ -34,7 +34,7 @@
   }
 
   @Override
-  public boolean isWritable() {
+  public boolean preferWritable() {
     return true;
   }
   

Modified: hadoop/hive/trunk/serde/src/java/org/apache/hadoop/hive/serde2/objectinspector/primitive/JavaStringObjectInspector.java
URL: http://svn.apache.org/viewvc/hadoop/hive/trunk/serde/src/java/org/apache/hadoop/hive/serde2/objectinspector/primitive/JavaStringObjectInspector.java?rev=790435&r1=790434&r2=790435&view=diff
==============================================================================
--- hadoop/hive/trunk/serde/src/java/org/apache/hadoop/hive/serde2/objectinspector/primitive/JavaStringObjectInspector.java (original)
+++ hadoop/hive/trunk/serde/src/java/org/apache/hadoop/hive/serde2/objectinspector/primitive/JavaStringObjectInspector.java Thu Jul  2 02:03:14 2009
@@ -39,5 +39,4 @@
   public String getPrimitiveJavaObject(Object o) {
     return (String)o;
   }
-
 }

Modified: hadoop/hive/trunk/serde/src/java/org/apache/hadoop/hive/serde2/objectinspector/primitive/PrimitiveObjectInspectorUtils.java
URL: http://svn.apache.org/viewvc/hadoop/hive/trunk/serde/src/java/org/apache/hadoop/hive/serde2/objectinspector/primitive/PrimitiveObjectInspectorUtils.java?rev=790435&r1=790434&r2=790435&view=diff
==============================================================================
--- hadoop/hive/trunk/serde/src/java/org/apache/hadoop/hive/serde2/objectinspector/primitive/PrimitiveObjectInspectorUtils.java (original)
+++ hadoop/hive/trunk/serde/src/java/org/apache/hadoop/hive/serde2/objectinspector/primitive/PrimitiveObjectInspectorUtils.java Thu Jul  2 02:03:14 2009
@@ -382,7 +382,7 @@
       }
       case STRING: {
         StringObjectInspector soi = (StringObjectInspector)oi;
-        if (soi.isWritable()) {
+        if (soi.preferWritable()) {
           Text t = soi.getPrimitiveWritableObject(o);
           result = LazyInteger.parseInt(t.getBytes(), 0, t.getLength());
         } else {

Modified: hadoop/hive/trunk/serde/src/java/org/apache/hadoop/hive/serde2/objectinspector/primitive/WritableStringObjectInspector.java
URL: http://svn.apache.org/viewvc/hadoop/hive/trunk/serde/src/java/org/apache/hadoop/hive/serde2/objectinspector/primitive/WritableStringObjectInspector.java?rev=790435&r1=790434&r2=790435&view=diff
==============================================================================
--- hadoop/hive/trunk/serde/src/java/org/apache/hadoop/hive/serde2/objectinspector/primitive/WritableStringObjectInspector.java (original)
+++ hadoop/hive/trunk/serde/src/java/org/apache/hadoop/hive/serde2/objectinspector/primitive/WritableStringObjectInspector.java Thu Jul  2 02:03:14 2009
@@ -32,7 +32,7 @@
 
   @Override
   public Object copyObject(Object o) {
-    return new Text((Text)o);
+    return o == null ? null : new Text((Text)o);
   }
 
   @Override

Modified: hadoop/hive/trunk/serde/src/test/org/apache/hadoop/hive/serde2/lazy/TestLazyArrayMapStruct.java
URL: http://svn.apache.org/viewvc/hadoop/hive/trunk/serde/src/test/org/apache/hadoop/hive/serde2/lazy/TestLazyArrayMapStruct.java?rev=790435&r1=790434&r2=790435&view=diff
==============================================================================
--- hadoop/hive/trunk/serde/src/test/org/apache/hadoop/hive/serde2/lazy/TestLazyArrayMapStruct.java (original)
+++ hadoop/hive/trunk/serde/src/test/org/apache/hadoop/hive/serde2/lazy/TestLazyArrayMapStruct.java Thu Jul  2 02:03:14 2009
@@ -21,12 +21,14 @@
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.List;
+import java.util.Map;
 
 import org.apache.hadoop.hive.serde2.SerDeUtils;
 import org.apache.hadoop.hive.serde2.io.ByteWritable;
+import org.apache.hadoop.hive.serde2.lazy.objectinspector.LazyObjectInspectorFactory;
 import org.apache.hadoop.hive.serde2.objectinspector.ObjectInspector;
+import org.apache.hadoop.hive.serde2.objectinspector.primitive.PrimitiveObjectInspectorFactory;
 import org.apache.hadoop.hive.serde2.typeinfo.TypeInfo;
-import org.apache.hadoop.hive.serde2.typeinfo.TypeInfoFactory;
 import org.apache.hadoop.hive.serde2.typeinfo.TypeInfoUtils;
 import org.apache.hadoop.io.IntWritable;
 import org.apache.hadoop.io.Text;
@@ -43,33 +45,44 @@
     try {
       // Array of Byte
       Text nullSequence = new Text("\\N");
-      LazyArray b = (LazyArray)LazyFactory.createLazyObject(TypeInfoUtils.getTypeInfoFromTypeString("array<tinyint>"));
+      ObjectInspector oi = LazyFactory.createLazyObjectInspector(
+          TypeInfoUtils.getTypeInfosFromTypeString("array<tinyint>").get(0), 
+          new byte[]{(byte)1}, 0, nullSequence, false, (byte)0);
+      LazyArray b = (LazyArray)LazyFactory.createLazyObject(oi);
       byte[] data = new byte[]{'-', '1', 1, '\\', 'N', 1, '8'};
       TestLazyPrimitive.initLazyObject(b, data, 0, data.length);
       
-      assertNull(b.getListElementObject(-1, (byte)1, nullSequence));
-      assertEquals(new ByteWritable((byte)-1), b.getListElementObject(0, (byte)1, nullSequence));
-      assertNull(b.getListElementObject(1, (byte)1, nullSequence));
-      assertEquals(new ByteWritable((byte)8), b.getListElementObject(2, (byte)1, nullSequence));
-      assertNull(b.getListElementObject(3, (byte)1, nullSequence));
-      assertEquals(
-          Arrays.asList(new ByteWritable[]{new ByteWritable((byte)-1), null, new ByteWritable((byte)8)}),
-          b.getList((byte)1, nullSequence));
+      assertNull(b.getListElementObject(-1));
+      assertEquals(new ByteWritable((byte)-1), ((LazyByte)b.getListElementObject(0)).getWritableObject());
+      assertEquals(new ByteWritable((byte)-1), ((LazyByte)b.getList().get(0)).getWritableObject());
+      assertNull(b.getListElementObject(1));
+      assertNull(b.getList().get(1));
+      assertEquals(new ByteWritable((byte)8), ((LazyByte)b.getListElementObject(2)).getWritableObject());
+      assertEquals(new ByteWritable((byte)8), ((LazyByte)b.getList().get(2)).getWritableObject());
+      assertNull(b.getListElementObject(3));
+      assertEquals(3, b.getList().size());
       
       // Array of String
-      b = (LazyArray)LazyFactory.createLazyObject(TypeInfoUtils.getTypeInfoFromTypeString("array<string>"));
+      oi = LazyFactory.createLazyObjectInspector(
+          TypeInfoUtils.getTypeInfosFromTypeString("array<string>").get(0), 
+          new byte[]{(byte)'\t'}, 0, nullSequence, false, (byte)0);
+      b = (LazyArray)LazyFactory.createLazyObject(oi);
       data = new byte[]{'a', 'b', '\t', 'c', '\t', '\\', 'N', '\t', '\t', 'd'};
       // Note: the first and last element of the byte[] are NOT used
       TestLazyPrimitive.initLazyObject(b, data, 1, data.length - 2);
-      assertNull(b.getListElementObject(-1, (byte)'\t', nullSequence));
-      assertEquals(new Text("b"), b.getListElementObject(0, (byte)'\t', nullSequence));
-      assertEquals(new Text("c"), b.getListElementObject(1, (byte)'\t', nullSequence));
-      assertNull(b.getListElementObject(2, (byte)'\t', nullSequence));
-      assertEquals(new Text(""), b.getListElementObject(3, (byte)'\t', nullSequence));
-      assertEquals(new Text(""), b.getListElementObject(4, (byte)'\t', nullSequence));
-      assertNull(b.getListElementObject(5, (byte)'\t', nullSequence));
-      assertEquals(Arrays.asList(new Text[]{new Text("b"), new Text("c"), null, new Text(""), new Text("")}),
-          b.getList((byte)'\t', nullSequence));
+      assertNull(b.getListElementObject(-1));
+      assertEquals(new Text("b"), ((LazyString)b.getListElementObject(0)).getWritableObject());
+      assertEquals(new Text("b"), ((LazyString)b.getList().get(0)).getWritableObject());
+      assertEquals(new Text("c"), ((LazyString)b.getListElementObject(1)).getWritableObject());
+      assertEquals(new Text("c"), ((LazyString)b.getList().get(1)).getWritableObject());
+      assertNull(((LazyString)b.getListElementObject(2)));
+      assertNull(((LazyString)b.getList().get(2)));
+      assertEquals(new Text(""), ((LazyString)b.getListElementObject(3)).getWritableObject());
+      assertEquals(new Text(""), ((LazyString)b.getList().get(3)).getWritableObject());
+      assertEquals(new Text(""), ((LazyString)b.getListElementObject(4)).getWritableObject());
+      assertEquals(new Text(""), ((LazyString)b.getList().get(4)).getWritableObject());
+      assertNull(((LazyString)b.getListElementObject(5)));
+      assertEquals(5, b.getList().size());
       
     } catch (Throwable e) {
       e.printStackTrace();
@@ -85,43 +98,41 @@
       {
         // Map of Integer to String
         Text nullSequence = new Text("\\N");
-        LazyMap b = (LazyMap)LazyFactory.createLazyObject(TypeInfoUtils.getTypeInfoFromTypeString("map<int,string>"));
+        ObjectInspector oi = LazyFactory.createLazyObjectInspector(
+            TypeInfoUtils.getTypeInfosFromTypeString("map<int,string>").get(0), 
+            new byte[]{(byte)1, (byte)2}, 0, nullSequence, false, (byte)0);
+        LazyMap b = (LazyMap)LazyFactory.createLazyObject(oi);
         byte[] data = new byte[]{'2', 2, 'd', 'e', 'f', 1, '-', '1', 2, '\\', 'N', 1, '0', 2, '0', 1, '8', 2, 'a', 'b', 'c'};
         TestLazyPrimitive.initLazyObject(b, data, 0, data.length);
         
-        assertEquals(new Text("def"), b.getMapValueElement((byte)1, (byte)2, nullSequence, new IntWritable(2)));
-        assertNull(b.getMapValueElement((byte)1, (byte)2, nullSequence, Integer.valueOf(-1)));
-        assertEquals(new Text("0"), b.getMapValueElement((byte)1, (byte)2, nullSequence, new IntWritable(0)));
-        assertEquals(new Text("abc"), b.getMapValueElement((byte)1, (byte)2, nullSequence, new IntWritable(8)));
-        assertNull(b.getMapValueElement((byte)1, (byte)2, nullSequence, new IntWritable(12345)));
-        
-        HashMap<IntWritable, Text> r = new HashMap<IntWritable, Text>();
-        r.put(new IntWritable(2), new Text("def"));
-        r.put(new IntWritable(-1), null);
-        r.put(new IntWritable(0), new Text("0"));
-        r.put(new IntWritable(8), new Text("abc"));
-        assertEquals(r, b.getMap((byte)1, (byte)2, nullSequence));
+        assertEquals(new Text("def"), ((LazyString)b.getMapValueElement(new IntWritable(2))).getWritableObject());
+        assertNull(b.getMapValueElement(new IntWritable(-1)));
+        assertEquals(new Text("0"), ((LazyString)b.getMapValueElement(new IntWritable(0))).getWritableObject());
+        assertEquals(new Text("abc"), ((LazyString)b.getMapValueElement(new IntWritable(8))).getWritableObject());
+        assertNull(b.getMapValueElement(new IntWritable(12345)));
+        
+        assertEquals("{2:'def',-1:null,0:'0',8:'abc'}".replace('\'', '\"'),
+            SerDeUtils.getJSONString(b, oi));
       }
       
       {
         // Map of String to String
         Text nullSequence = new Text("\\N");
-        LazyMap b = (LazyMap)LazyFactory.createLazyObject(TypeInfoUtils.getTypeInfoFromTypeString("map<string,string>"));
+        ObjectInspector oi = LazyFactory.createLazyObjectInspector(
+            TypeInfoUtils.getTypeInfosFromTypeString("map<string,string>").get(0), 
+            new byte[]{(byte)'#', (byte)'\t'}, 0, nullSequence, false, (byte)0);
+        LazyMap b = (LazyMap)LazyFactory.createLazyObject(oi);
         byte[] data = new byte[]{'2', '\t', 'd', '\t', 'f', '#', '2', '\t', 'd', '#', '-', '1', '#', '0', '\t', '0', '#', '8', '\t', 'a', 'b', 'c'};
         TestLazyPrimitive.initLazyObject(b, data, 0, data.length);
         
-        assertEquals(new Text("d\tf"), b.getMapValueElement((byte)'#', (byte)'\t', nullSequence, new Text("2")));
-        assertNull(b.getMapValueElement((byte)'#', (byte)'\t', nullSequence, new Text("-1")));
-        assertEquals(new Text("0"), b.getMapValueElement((byte)'#', (byte)'\t', nullSequence, new Text("0")));
-        assertEquals(new Text("abc"), b.getMapValueElement((byte)'#', (byte)'\t', nullSequence, new Text("8")));
-        assertNull(b.getMapValueElement((byte)'#', (byte)'\t', nullSequence, new Text("-")));
-        
-        HashMap<Text,Text> r = new HashMap<Text, Text>();
-        r.put(new Text("2"), new Text("d\tf"));
-        r.put(new Text("-1"), null);
-        r.put(new Text("0"), new Text("0"));
-        r.put(new Text("8"), new Text("abc"));
-        assertEquals(r, b.getMap((byte)1, (byte)2, nullSequence));
+        assertEquals(new Text("d\tf"), ((LazyString)b.getMapValueElement(new Text("2"))).getWritableObject());
+        assertNull(b.getMapValueElement(new Text("-1")));
+        assertEquals(new Text("0"), ((LazyString)b.getMapValueElement(new Text("0"))).getWritableObject());
+        assertEquals(new Text("abc"), ((LazyString)b.getMapValueElement(new Text("8"))).getWritableObject());
+        assertNull(b.getMapValueElement(new Text("-")));
+        
+        assertEquals("{'2':'d\\tf','2':'d','-1':null,'0':'0','8':'abc'}".replace('\'', '\"'),
+            SerDeUtils.getJSONString(b, oi));
       }
       
     } catch (Throwable e) {
@@ -139,13 +150,11 @@
         ArrayList<TypeInfo> fieldTypeInfos = 
           TypeInfoUtils.getTypeInfosFromTypeString("int,array<string>,map<string,string>,string");
         List<String> fieldNames = Arrays.asList(new String[]{"a", "b", "c", "d"});
-        TypeInfo rowTypeInfo = TypeInfoFactory.getStructTypeInfo(fieldNames, fieldTypeInfos);
-        
         Text nullSequence = new Text("\\N");
         
-        LazyStruct o = (LazyStruct)LazyFactory.createLazyObject(rowTypeInfo);
-        ObjectInspector oi = LazyFactory.createLazyStructInspector(Arrays.asList(new String[]{"a","b","c","d"}),
-            fieldTypeInfos, new byte[] {' ', ':', '='}, nullSequence, false);
+        ObjectInspector oi = LazyFactory.createLazyStructInspector(fieldNames,
+            fieldTypeInfos, new byte[] {' ', ':', '='}, nullSequence, false, false, (byte)0);
+        LazyStruct o = (LazyStruct)LazyFactory.createLazyObject(oi);
         
         Text data;
         
@@ -176,7 +185,7 @@
 
         data = new Text(": : : :");
         TestLazyPrimitive.initLazyObject(o, data.getBytes(), 0, data.getLength());
-        assertEquals("{'a':null,'b':['',''],'c':{'':null},'d':':'}".replace("'", "\""),
+        assertEquals("{'a':null,'b':['',''],'c':{'':null,'':null},'d':':'}".replace("'", "\""),
             SerDeUtils.getJSONString(o, oi));
 
         data = new Text("= = = =");
@@ -186,7 +195,8 @@
         
         // test LastColumnTakesRest
         oi = LazyFactory.createLazyStructInspector(Arrays.asList(new String[]{"a","b","c","d"}),
-            fieldTypeInfos, new byte[] {' ', ':', '='}, nullSequence, true);
+            fieldTypeInfos, new byte[] {' ', ':', '='}, nullSequence, true, false, (byte)0);
+        o = (LazyStruct)LazyFactory.createLazyObject(oi);
         data = new Text("\\N a d=\\N:f=g:h has tail");
         TestLazyPrimitive.initLazyObject(o, data.getBytes(), 0, data.getLength());
         assertEquals("{'a':null,'b':['a'],'c':{'d':null,'f':'g','h':null},'d':'has tail'}".replace("'", "\""),

Modified: hadoop/hive/trunk/serde/src/test/org/apache/hadoop/hive/serde2/lazy/TestLazyPrimitive.java
URL: http://svn.apache.org/viewvc/hadoop/hive/trunk/serde/src/test/org/apache/hadoop/hive/serde2/lazy/TestLazyPrimitive.java?rev=790435&r1=790434&r2=790435&view=diff
==============================================================================
--- hadoop/hive/trunk/serde/src/test/org/apache/hadoop/hive/serde2/lazy/TestLazyPrimitive.java (original)
+++ hadoop/hive/trunk/serde/src/test/org/apache/hadoop/hive/serde2/lazy/TestLazyPrimitive.java Thu Jul  2 02:03:14 2009
@@ -22,6 +22,9 @@
 import org.apache.hadoop.hive.serde2.io.ByteWritable;
 import org.apache.hadoop.hive.serde2.io.DoubleWritable;
 import org.apache.hadoop.hive.serde2.io.ShortWritable;
+import org.apache.hadoop.hive.serde2.lazy.objectinspector.primitive.LazyPrimitiveObjectInspectorFactory;
+import org.apache.hadoop.hive.serde2.objectinspector.ObjectInspectorFactory;
+import org.apache.hadoop.hive.serde2.objectinspector.primitive.PrimitiveObjectInspectorFactory;
 import org.apache.hadoop.io.IntWritable;
 import org.apache.hadoop.io.LongWritable;
 import org.apache.hadoop.io.Text;
@@ -43,36 +46,36 @@
    */
   public void testLazyByte() throws Throwable {
     try {
-      LazyByte b = new LazyByte();
+      LazyByte b = new LazyByte(LazyPrimitiveObjectInspectorFactory.lazyByteObjectInspector);
       initLazyObject(b,new byte[]{'0'}, 0, 0);
-      assertNull(b.getObject());
+      assertNull(b.getWritableObject());
       initLazyObject(b,new byte[]{'0'}, 0, 1);
-      assertEquals(new ByteWritable((byte)0), b.getObject());
+      assertEquals(new ByteWritable((byte)0), b.getWritableObject());
       initLazyObject(b,new byte[]{'+', '0'}, 0, 2);
-      assertEquals(new ByteWritable((byte)0), b.getObject());
+      assertEquals(new ByteWritable((byte)0), b.getWritableObject());
       initLazyObject(b,new byte[]{'-', '0'}, 0, 2);
-      assertEquals(new ByteWritable((byte)0), b.getObject());
+      assertEquals(new ByteWritable((byte)0), b.getWritableObject());
       initLazyObject(b,new byte[]{'a', '1', 'b'}, 1, 1);
-      assertEquals(new ByteWritable((byte)1), b.getObject());
+      assertEquals(new ByteWritable((byte)1), b.getWritableObject());
       initLazyObject(b,new byte[]{'a', '-', '1'}, 1, 2);
-      assertEquals(new ByteWritable((byte)-1), b.getObject());
+      assertEquals(new ByteWritable((byte)-1), b.getWritableObject());
       initLazyObject(b,new byte[]{'a', '+', '1'}, 1, 2);
-      assertEquals(new ByteWritable((byte)1), b.getObject());
+      assertEquals(new ByteWritable((byte)1), b.getWritableObject());
       initLazyObject(b,new byte[]{'-', '1', '2', '8'}, 0, 4);
-      assertEquals(new ByteWritable((byte)-128), b.getObject());
+      assertEquals(new ByteWritable((byte)-128), b.getWritableObject());
       initLazyObject(b,new byte[]{'+', '1', '2', '7'}, 0, 4);
-      assertEquals(new ByteWritable((byte)127), b.getObject());
+      assertEquals(new ByteWritable((byte)127), b.getWritableObject());
       
       initLazyObject(b,new byte[]{'a', '1', 'b'}, 1, 2);
-      assertNull(b.getObject());
+      assertNull(b.getWritableObject());
       initLazyObject(b,new byte[]{'+', '1', '2', '8'}, 0, 4);
-      assertNull(b.getObject());
+      assertNull(b.getWritableObject());
       initLazyObject(b,new byte[]{'-', '1', '2', '9'}, 0, 4);
-      assertNull(b.getObject());
+      assertNull(b.getWritableObject());
       initLazyObject(b,new byte[]{'-', '1', '2', '3'}, 0, 1);
-      assertNull(b.getObject());
+      assertNull(b.getWritableObject());
       initLazyObject(b,new byte[]{'+', '1', '2', '3'}, 0, 1);
-      assertNull(b.getObject());
+      assertNull(b.getWritableObject());
      
     } catch (Throwable e) {
       e.printStackTrace();
@@ -85,40 +88,40 @@
    */
   public void testLazyShort() throws Throwable {
     try {
-      LazyShort b = new LazyShort();
+      LazyShort b = new LazyShort(LazyPrimitiveObjectInspectorFactory.lazyShortObjectInspector);
       initLazyObject(b,new byte[]{'0'}, 0, 0);
-      assertNull(b.getObject());
+      assertNull(b.getWritableObject());
       initLazyObject(b,new byte[]{'0'}, 0, 1);
-      assertEquals(new ShortWritable((short)0), b.getObject());
+      assertEquals(new ShortWritable((short)0), b.getWritableObject());
       initLazyObject(b,new byte[]{'+', '0'}, 0, 2);
-      assertEquals(new ShortWritable((short)0), b.getObject());
+      assertEquals(new ShortWritable((short)0), b.getWritableObject());
       initLazyObject(b,new byte[]{'-', '0'}, 0, 2);
-      assertEquals(new ShortWritable((short)0), b.getObject());
+      assertEquals(new ShortWritable((short)0), b.getWritableObject());
       initLazyObject(b,new byte[]{'a', '1', 'b'}, 1, 1);
-      assertEquals(new ShortWritable((short)1), b.getObject());
+      assertEquals(new ShortWritable((short)1), b.getWritableObject());
       initLazyObject(b,new byte[]{'a', '-', '1'}, 1, 2);
-      assertEquals(new ShortWritable((short)-1), b.getObject());
+      assertEquals(new ShortWritable((short)-1), b.getWritableObject());
       initLazyObject(b,new byte[]{'a', '+', '1'}, 1, 2);
-      assertEquals(new ShortWritable((short)1), b.getObject());
+      assertEquals(new ShortWritable((short)1), b.getWritableObject());
       initLazyObject(b,new byte[]{'-', '1', '2', '8'}, 0, 4);
-      assertEquals(new ShortWritable((short)-128), b.getObject());
+      assertEquals(new ShortWritable((short)-128), b.getWritableObject());
       initLazyObject(b,new byte[]{'+', '1', '2', '7'}, 0, 4);
-      assertEquals(new ShortWritable((short)127), b.getObject());
+      assertEquals(new ShortWritable((short)127), b.getWritableObject());
       initLazyObject(b,new byte[]{'-', '3', '2', '7', '6', '8'}, 0, 6);
-      assertEquals(new ShortWritable((short)-32768), b.getObject());
+      assertEquals(new ShortWritable((short)-32768), b.getWritableObject());
       initLazyObject(b,new byte[]{'+', '3', '2', '7', '6', '7'}, 0, 6);
-      assertEquals(new ShortWritable((short)32767), b.getObject());
+      assertEquals(new ShortWritable((short)32767), b.getWritableObject());
 
       initLazyObject(b,new byte[]{'a', '1', 'b'}, 1, 2);
-      assertNull(b.getObject());
+      assertNull(b.getWritableObject());
       initLazyObject(b,new byte[]{'-', '3', '2', '7', '6', '9'}, 0, 6);
-      assertNull(b.getObject());
+      assertNull(b.getWritableObject());
       initLazyObject(b,new byte[]{'+', '3', '2', '7', '6', '8'}, 0, 6);
-      assertNull(b.getObject());
+      assertNull(b.getWritableObject());
       initLazyObject(b,new byte[]{'-', '1', '2', '3'}, 0, 1);
-      assertNull(b.getObject());
+      assertNull(b.getWritableObject());
       initLazyObject(b,new byte[]{'+', '1', '2', '3'}, 0, 1);
-      assertNull(b.getObject());
+      assertNull(b.getWritableObject());
 
     } catch (Throwable e) {
       e.printStackTrace();
@@ -132,44 +135,44 @@
    */
   public void testLazyInteger() throws Throwable {
     try {
-      LazyInteger b = new LazyInteger();
+      LazyInteger b = new LazyInteger(LazyPrimitiveObjectInspectorFactory.lazyIntObjectInspector);
       initLazyObject(b,new byte[]{'0'}, 0, 0);
-      assertNull(b.getObject());
+      assertNull(b.getWritableObject());
       initLazyObject(b,new byte[]{'0'}, 0, 1);
-      assertEquals(new IntWritable((int)0), b.getObject());
+      assertEquals(new IntWritable((int)0), b.getWritableObject());
       initLazyObject(b,new byte[]{'+', '0'}, 0, 2);
-      assertEquals(new IntWritable((int)0), b.getObject());
+      assertEquals(new IntWritable((int)0), b.getWritableObject());
       initLazyObject(b,new byte[]{'-', '0'}, 0, 2);
-      assertEquals(new IntWritable((int)0), b.getObject());
+      assertEquals(new IntWritable((int)0), b.getWritableObject());
       initLazyObject(b,new byte[]{'a', '1', 'b'}, 1, 1);
-      assertEquals(new IntWritable((int)1), b.getObject());
+      assertEquals(new IntWritable((int)1), b.getWritableObject());
       initLazyObject(b,new byte[]{'a', '-', '1'}, 1, 2);
-      assertEquals(new IntWritable((int)-1), b.getObject());
+      assertEquals(new IntWritable((int)-1), b.getWritableObject());
       initLazyObject(b,new byte[]{'a', '+', '1'}, 1, 2);
-      assertEquals(new IntWritable((int)1), b.getObject());
+      assertEquals(new IntWritable((int)1), b.getWritableObject());
       initLazyObject(b,new byte[]{'-', '1', '2', '8'}, 0, 4);
-      assertEquals(new IntWritable((int)-128), b.getObject());
+      assertEquals(new IntWritable((int)-128), b.getWritableObject());
       initLazyObject(b,new byte[]{'+', '1', '2', '7'}, 0, 4);
-      assertEquals(new IntWritable((int)127), b.getObject());
+      assertEquals(new IntWritable((int)127), b.getWritableObject());
       initLazyObject(b,new byte[]{'-', '3', '2', '7', '6', '8'}, 0, 6);
-      assertEquals(new IntWritable((int)-32768), b.getObject());
+      assertEquals(new IntWritable((int)-32768), b.getWritableObject());
       initLazyObject(b,new byte[]{'+', '3', '2', '7', '6', '7'}, 0, 6);
-      assertEquals(new IntWritable((int)32767), b.getObject());
+      assertEquals(new IntWritable((int)32767), b.getWritableObject());
       initLazyObject(b,new byte[]{'-', '2', '1', '4', '7', '4', '8', '3', '6', '4', '8'}, 0, 11);
-      assertEquals(new IntWritable((int)-2147483648), b.getObject());
+      assertEquals(new IntWritable((int)-2147483648), b.getWritableObject());
       initLazyObject(b,new byte[]{'+', '2', '1', '4', '7', '4', '8', '3', '6', '4', '7'}, 0, 11);
-      assertEquals(new IntWritable((int)2147483647), b.getObject());
+      assertEquals(new IntWritable((int)2147483647), b.getWritableObject());
 
       initLazyObject(b,new byte[]{'a', '1', 'b'}, 1, 2);
-      assertNull(b.getObject());
+      assertNull(b.getWritableObject());
       initLazyObject(b,new byte[]{'-', '2', '1', '4', '7', '4', '8', '3', '6', '4', '9'}, 0, 11);
-      assertNull(b.getObject());
+      assertNull(b.getWritableObject());
       initLazyObject(b,new byte[]{'+', '2', '1', '4', '7', '4', '8', '3', '6', '4', '8'}, 0, 11);
-      assertNull(b.getObject());
+      assertNull(b.getWritableObject());
       initLazyObject(b,new byte[]{'-', '1', '2', '3'}, 0, 1);
-      assertNull(b.getObject());
+      assertNull(b.getWritableObject());
       initLazyObject(b,new byte[]{'+', '1', '2', '3'}, 0, 1);
-      assertNull(b.getObject());
+      assertNull(b.getWritableObject());
 
     } catch (Throwable e) {
       e.printStackTrace();
@@ -183,52 +186,52 @@
    */
   public void testLazyLong() throws Throwable {
     try {
-      LazyLong b = new LazyLong();
+      LazyLong b = new LazyLong(LazyPrimitiveObjectInspectorFactory.lazyLongObjectInspector);
       initLazyObject(b,new byte[]{'0'}, 0, 0);
-      assertNull(b.getObject());
+      assertNull(b.getWritableObject());
       initLazyObject(b,new byte[]{'0'}, 0, 1);
-      assertEquals(new LongWritable((long)0), b.getObject());
+      assertEquals(new LongWritable((long)0), b.getWritableObject());
       initLazyObject(b,new byte[]{'+', '0'}, 0, 2);
-      assertEquals(new LongWritable((long)0), b.getObject());
+      assertEquals(new LongWritable((long)0), b.getWritableObject());
       initLazyObject(b,new byte[]{'-', '0'}, 0, 2);
-      assertEquals(new LongWritable((long)0), b.getObject());
+      assertEquals(new LongWritable((long)0), b.getWritableObject());
       initLazyObject(b,new byte[]{'a', '1', 'b'}, 1, 1);
-      assertEquals(new LongWritable((long)1), b.getObject());
+      assertEquals(new LongWritable((long)1), b.getWritableObject());
       initLazyObject(b,new byte[]{'a', '-', '1'}, 1, 2);
-      assertEquals(new LongWritable((long)-1), b.getObject());
+      assertEquals(new LongWritable((long)-1), b.getWritableObject());
       initLazyObject(b,new byte[]{'a', '+', '1'}, 1, 2);
-      assertEquals(new LongWritable((long)1), b.getObject());
+      assertEquals(new LongWritable((long)1), b.getWritableObject());
       initLazyObject(b,new byte[]{'-', '1', '2', '8'}, 0, 4);
-      assertEquals(new LongWritable((long)-128), b.getObject());
+      assertEquals(new LongWritable((long)-128), b.getWritableObject());
       initLazyObject(b,new byte[]{'+', '1', '2', '7'}, 0, 4);
-      assertEquals(new LongWritable((long)127), b.getObject());
+      assertEquals(new LongWritable((long)127), b.getWritableObject());
       initLazyObject(b,new byte[]{'-', '3', '2', '7', '6', '8'}, 0, 6);
-      assertEquals(new LongWritable((long)-32768), b.getObject());
+      assertEquals(new LongWritable((long)-32768), b.getWritableObject());
       initLazyObject(b,new byte[]{'+', '3', '2', '7', '6', '7'}, 0, 6);
-      assertEquals(new LongWritable((long)32767), b.getObject());
+      assertEquals(new LongWritable((long)32767), b.getWritableObject());
       initLazyObject(b,new byte[]{'-', '2', '1', '4', '7', '4', '8', '3', '6', '4', '8'}, 0, 11);
-      assertEquals(new LongWritable((long)-2147483648), b.getObject());
+      assertEquals(new LongWritable((long)-2147483648), b.getWritableObject());
       initLazyObject(b,new byte[]{'+', '2', '1', '4', '7', '4', '8', '3', '6', '4', '7'}, 0, 11);
-      assertEquals(new LongWritable((long)2147483647), b.getObject());
+      assertEquals(new LongWritable((long)2147483647), b.getWritableObject());
       initLazyObject(b,new byte[]{'-', '9', '2', '2', '3', '3', '7', '2', '0', '3', '6', '8', '5',
           '4', '7', '7', '5', '8', '0', '8'}, 0, 20);
-      assertEquals(new LongWritable((long)-9223372036854775808L), b.getObject());
+      assertEquals(new LongWritable((long)-9223372036854775808L), b.getWritableObject());
       initLazyObject(b,new byte[]{'+', '9', '2', '2', '3', '3', '7', '2', '0', '3', '6', '8', '5',
           '4', '7', '7', '5', '8', '0', '7'}, 0, 20);
-      assertEquals(new LongWritable((long)9223372036854775807L), b.getObject());
+      assertEquals(new LongWritable((long)9223372036854775807L), b.getWritableObject());
 
       initLazyObject(b,new byte[]{'a', '1', 'b'}, 1, 2);
-      assertNull(b.getObject());
+      assertNull(b.getWritableObject());
       initLazyObject(b,new byte[]{'-', '9', '2', '2', '3', '3', '7', '2', '0', '3', '6', '8', '5',
           '4', '7', '7', '5', '8', '0', '9'}, 0, 20);
-      assertNull(b.getObject());
+      assertNull(b.getWritableObject());
       initLazyObject(b,new byte[]{'+', '9', '2', '2', '3', '3', '7', '2', '0', '3', '6', '8', '5',
           '4', '7', '7', '5', '8', '0', '8'}, 0, 20);
-      assertNull(b.getObject());
+      assertNull(b.getWritableObject());
       initLazyObject(b,new byte[]{'-', '1', '2', '3'}, 0, 1);
-      assertNull(b.getObject());
+      assertNull(b.getWritableObject());
       initLazyObject(b,new byte[]{'+', '1', '2', '3'}, 0, 1);
-      assertNull(b.getObject());
+      assertNull(b.getWritableObject());
 
     } catch (Throwable e) {
       e.printStackTrace();
@@ -241,81 +244,81 @@
    */
   public void testLazyDouble() throws Throwable {
     try {
-      LazyDouble b = new LazyDouble();
+      LazyDouble b = new LazyDouble(LazyPrimitiveObjectInspectorFactory.lazyDoubleObjectInspector);
       initLazyObject(b,new byte[]{'0'}, 0, 0);
-      assertNull(b.getObject());
+      assertNull(b.getWritableObject());
       initLazyObject(b,new byte[]{'0'}, 0, 1);
-      assertEquals(new DoubleWritable((double)0), b.getObject());
+      assertEquals(new DoubleWritable((double)0), b.getWritableObject());
       initLazyObject(b,new byte[]{'+', '0'}, 0, 2);
-      assertEquals(new DoubleWritable((double)0), b.getObject());
+      assertEquals(new DoubleWritable((double)0), b.getWritableObject());
       initLazyObject(b,new byte[]{'-', '0'}, 0, 2);
-      assertEquals(new DoubleWritable((double)-0.0), b.getObject());
+      assertEquals(new DoubleWritable((double)-0.0), b.getWritableObject());
       initLazyObject(b,new byte[]{'a', '1', 'b'}, 1, 1);
-      assertEquals(new DoubleWritable((double)1), b.getObject());
+      assertEquals(new DoubleWritable((double)1), b.getWritableObject());
       initLazyObject(b,new byte[]{'a', '-', '1'}, 1, 2);
-      assertEquals(new DoubleWritable((double)-1), b.getObject());
+      assertEquals(new DoubleWritable((double)-1), b.getWritableObject());
       initLazyObject(b,new byte[]{'a', '+', '1'}, 1, 2);
-      assertEquals(new DoubleWritable((double)1), b.getObject());
+      assertEquals(new DoubleWritable((double)1), b.getWritableObject());
       initLazyObject(b,new byte[]{'-', '1', '2', '8'}, 0, 4);
-      assertEquals(new DoubleWritable((double)-128), b.getObject());
+      assertEquals(new DoubleWritable((double)-128), b.getWritableObject());
       initLazyObject(b,new byte[]{'+', '1', '2', '7'}, 0, 4);
-      assertEquals(new DoubleWritable((double)127), b.getObject());
+      assertEquals(new DoubleWritable((double)127), b.getWritableObject());
       initLazyObject(b,new byte[]{'-', '3', '2', '7', '6', '8'}, 0, 6);
-      assertEquals(new DoubleWritable((double)-32768), b.getObject());
+      assertEquals(new DoubleWritable((double)-32768), b.getWritableObject());
       initLazyObject(b,new byte[]{'+', '3', '2', '7', '6', '7'}, 0, 6);
-      assertEquals(new DoubleWritable((double)32767), b.getObject());
+      assertEquals(new DoubleWritable((double)32767), b.getWritableObject());
       initLazyObject(b,new byte[]{'-', '2', '1', '4', '7', '4', '8', '3', '6', '4', '8'}, 0, 11);
-      assertEquals(new DoubleWritable((double)-2147483648), b.getObject());
+      assertEquals(new DoubleWritable((double)-2147483648), b.getWritableObject());
       initLazyObject(b,new byte[]{'+', '2', '1', '4', '7', '4', '8', '3', '6', '4', '7'}, 0, 11);
-      assertEquals(new DoubleWritable((double)2147483647), b.getObject());
+      assertEquals(new DoubleWritable((double)2147483647), b.getWritableObject());
       initLazyObject(b,new byte[]{'-', '9', '2', '2', '3', '3', '7', '2', '0', '3', '6', '8', '5',
           '4', '7', '7', '5', '8', '0', '8'}, 0, 20);
-      assertEquals(new DoubleWritable((double)-9223372036854775808L), b.getObject());
+      assertEquals(new DoubleWritable((double)-9223372036854775808L), b.getWritableObject());
       initLazyObject(b,new byte[]{'+', '9', '2', '2', '3', '3', '7', '2', '0', '3', '6', '8', '5',
           '4', '7', '7', '5', '8', '0', '7'}, 0, 20);
-      assertEquals(new DoubleWritable((long)9223372036854775807L), b.getObject());
+      assertEquals(new DoubleWritable((long)9223372036854775807L), b.getWritableObject());
 
       initLazyObject(b,new byte[]{'-', '3', '.', '7', '6', '8'}, 0, 6);
-      assertEquals(new DoubleWritable((double)-3.768), b.getObject());
+      assertEquals(new DoubleWritable((double)-3.768), b.getWritableObject());
       initLazyObject(b,new byte[]{'+', '3', '.', '7', '6', '7'}, 0, 6);
-      assertEquals(new DoubleWritable((double)3.767), b.getObject());
+      assertEquals(new DoubleWritable((double)3.767), b.getWritableObject());
       initLazyObject(b,new byte[]{'-', '2', '.', '4', '7', '4', '8', '3', '6', 'e', '8'}, 0, 11);
-      assertEquals(new DoubleWritable((double)-2.474836e8), b.getObject());
+      assertEquals(new DoubleWritable((double)-2.474836e8), b.getWritableObject());
       initLazyObject(b,new byte[]{'+', '2', '.', '4', '7', '4', '8', '3', 'E', '-', '7'}, 0, 11);
-      assertEquals(new DoubleWritable((double)2.47483E-7), b.getObject());
+      assertEquals(new DoubleWritable((double)2.47483E-7), b.getWritableObject());
       initLazyObject(b,new byte[]{'-', '.', '4', '7', '4', '8', '3', '6', 'e', '8'}, 0, 10);
-      assertEquals(new DoubleWritable((double)-.474836e8), b.getObject());
+      assertEquals(new DoubleWritable((double)-.474836e8), b.getWritableObject());
       initLazyObject(b,new byte[]{'+', '.', '4', '7', '4', '8', '3', 'E', '-', '7'}, 0, 10);
-      assertEquals(new DoubleWritable((double).47483E-7), b.getObject());
+      assertEquals(new DoubleWritable((double).47483E-7), b.getWritableObject());
       initLazyObject(b,new byte[]{'-', '2', '1', '4', '7', '4', '8', '3', '6', '4', '.'}, 0, 11);
-      assertEquals(new DoubleWritable((double)-214748364.), b.getObject());
+      assertEquals(new DoubleWritable((double)-214748364.), b.getWritableObject());
       initLazyObject(b,new byte[]{'+', '2', '1', '4', '7', '4', '8', '3', '6', '4', '.'}, 0, 11);
-      assertEquals(new DoubleWritable((double)+214748364.), b.getObject());
+      assertEquals(new DoubleWritable((double)+214748364.), b.getWritableObject());
 
       initLazyObject(b,new byte[]{'.', '0'}, 0, 2);
-      assertEquals(new DoubleWritable((double).0), b.getObject());
+      assertEquals(new DoubleWritable((double).0), b.getWritableObject());
       initLazyObject(b,new byte[]{'0', '.'}, 0, 2);
-      assertEquals(new DoubleWritable((double)0.), b.getObject());
+      assertEquals(new DoubleWritable((double)0.), b.getWritableObject());
       
       initLazyObject(b,new byte[]{'a', '1', 'b'}, 1, 2);
-      assertNull(b.getObject());
-      assertNull(b.getObject());
+      assertNull(b.getWritableObject());
+      assertNull(b.getWritableObject());
       initLazyObject(b,new byte[]{'.', '1', '2', '3'}, 0, 1);
-      assertNull(b.getObject());
+      assertNull(b.getWritableObject());
       initLazyObject(b,new byte[]{'-', '1', '2', '3'}, 0, 1);
-      assertNull(b.getObject());
+      assertNull(b.getWritableObject());
       initLazyObject(b,new byte[]{'+', '1', '2', '3'}, 0, 1);
-      assertNull(b.getObject());
+      assertNull(b.getWritableObject());
       
       initLazyObject(b,new byte[]{'-', '1', 'e', '3', '3', '3', '3', '3', '3'}, 0, 9);
-      assertEquals(new DoubleWritable(Double.NEGATIVE_INFINITY), b.getObject());
+      assertEquals(new DoubleWritable(Double.NEGATIVE_INFINITY), b.getWritableObject());
       initLazyObject(b,new byte[]{'+', '1', 'e', '3', '3', '3', '3', '3', '3'}, 0, 9);
-      assertEquals(new DoubleWritable(Double.POSITIVE_INFINITY), b.getObject());
+      assertEquals(new DoubleWritable(Double.POSITIVE_INFINITY), b.getWritableObject());
 
       initLazyObject(b,new byte[]{'+', '1', 'e', '-', '3', '3', '3', '3', '3'}, 0, 8);
-      assertEquals(new DoubleWritable((double)0), b.getObject());
+      assertEquals(new DoubleWritable((double)0), b.getWritableObject());
       initLazyObject(b,new byte[]{'-', '1', 'e', '-', '3', '3', '3', '3', '3'}, 0, 8);
-      assertEquals(new DoubleWritable((double)-0.0), b.getObject());
+      assertEquals(new DoubleWritable((double)-0.0), b.getWritableObject());
       
     } catch (Throwable e) {
       e.printStackTrace();
@@ -328,13 +331,14 @@
    */
   public void testLazyString() throws Throwable {
     try {
-      LazyString b = new LazyString();
+      LazyString b = new LazyString(LazyPrimitiveObjectInspectorFactory
+          .getLazyStringObjectInspector(false,(byte)0));
       initLazyObject(b,new byte[]{'0'}, 0, 0);
-      assertEquals(new Text(""), b.getObject());
+      assertEquals(new Text(""), b.getWritableObject());
       initLazyObject(b,new byte[]{'0'}, 0, 1);
-      assertEquals(new Text("0"), b.getObject());
+      assertEquals(new Text("0"), b.getWritableObject());
       initLazyObject(b,new byte[]{'0', '1', '2'}, 1, 1);
-      assertEquals(new Text("1"), b.getObject());
+      assertEquals(new Text("1"), b.getWritableObject());
       
     } catch (Throwable e) {
       e.printStackTrace();

Modified: hadoop/hive/trunk/serde/src/test/org/apache/hadoop/hive/serde2/lazy/TestLazySimpleSerDe.java
URL: http://svn.apache.org/viewvc/hadoop/hive/trunk/serde/src/test/org/apache/hadoop/hive/serde2/lazy/TestLazySimpleSerDe.java?rev=790435&r1=790434&r2=790435&view=diff
==============================================================================
--- hadoop/hive/trunk/serde/src/test/org/apache/hadoop/hive/serde2/lazy/TestLazySimpleSerDe.java (original)
+++ hadoop/hive/trunk/serde/src/test/org/apache/hadoop/hive/serde2/lazy/TestLazySimpleSerDe.java Thu Jul  2 02:03:14 2009
@@ -77,6 +77,9 @@
     Object row = serDe.deserialize(t);
     for (int i = 0; i < fieldRefs.size(); i++) {
       Object fieldData = oi.getStructFieldData(row, fieldRefs.get(i));
+      if (fieldData != null) {
+        fieldData = ((LazyPrimitive)fieldData).getWritableObject();
+      }
       assertEquals("Field " + i, expectedFieldsData[i], fieldData);
     }
     // Serialize 



Mime
View raw message