hive-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From zs...@apache.org
Subject svn commit: r745212 [9/9] - in /hadoop/hive/trunk: ./ metastore/if/ metastore/src/gen-javabean/org/apache/hadoop/hive/metastore/api/ metastore/src/gen-php/ metastore/src/gen-py/hive_metastore/ metastore/src/java/org/apache/hadoop/hive/metastore/ ql/src...
Date Tue, 17 Feb 2009 19:39:32 GMT
Added: 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=745212&view=auto
==============================================================================
--- hadoop/hive/trunk/serde/src/test/org/apache/hadoop/hive/serde2/lazy/TestLazyPrimitive.java
(added)
+++ hadoop/hive/trunk/serde/src/test/org/apache/hadoop/hive/serde2/lazy/TestLazyPrimitive.java
Tue Feb 17 19:39:29 2009
@@ -0,0 +1,316 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.hadoop.hive.serde2.lazy;
+
+
+import junit.framework.TestCase;
+
+public class TestLazyPrimitive extends TestCase {
+
+  /**
+   * Test the LazyByte class.
+   */
+  public void testLazyByte() throws Throwable {
+    try {
+      LazyByte b = new LazyByte();
+      b.setAll(new byte[]{'0'}, 0, 1);
+      assertEquals(Byte.valueOf((byte)0), b.getPrimitiveObject());
+      b.setAll(new byte[]{'+', '0'}, 0, 2);
+      assertEquals(Byte.valueOf((byte)0), b.getPrimitiveObject());
+      b.setAll(new byte[]{'-', '0'}, 0, 2);
+      assertEquals(Byte.valueOf((byte)0), b.getPrimitiveObject());
+      b.setAll(new byte[]{'a', '1', 'b'}, 1, 1);
+      assertEquals(Byte.valueOf((byte)1), b.getPrimitiveObject());
+      b.setAll(new byte[]{'a', '-', '1'}, 1, 2);
+      assertEquals(Byte.valueOf((byte)-1), b.getPrimitiveObject());
+      b.setAll(new byte[]{'a', '+', '1'}, 1, 2);
+      assertEquals(Byte.valueOf((byte)1), b.getPrimitiveObject());
+      b.setAll(new byte[]{'-', '1', '2', '8'}, 0, 4);
+      assertEquals(Byte.valueOf((byte)-128), b.getPrimitiveObject());
+      b.setAll(new byte[]{'+', '1', '2', '7'}, 0, 4);
+      assertEquals(Byte.valueOf((byte)127), b.getPrimitiveObject());
+      
+      b.setAll(new byte[]{'a', '1', 'b'}, 1, 2);
+      assertNull(b.getPrimitiveObject());
+      b.setAll(new byte[]{'+', '1', '2', '8'}, 0, 4);
+      assertNull(b.getPrimitiveObject());
+      b.setAll(new byte[]{'-', '1', '2', '9'}, 0, 4);
+      assertNull(b.getPrimitiveObject());
+      b.setAll(new byte[]{'-', '1', '2', '3'}, 0, 1);
+      assertNull(b.getPrimitiveObject());
+      b.setAll(new byte[]{'+', '1', '2', '3'}, 0, 1);
+      assertNull(b.getPrimitiveObject());
+     
+    } catch (Throwable e) {
+      e.printStackTrace();
+      throw e;
+    }
+  }
+    
+  /**
+   * Test the LazyShort class.
+   */
+  public void testLazyShort() throws Throwable {
+    try {
+      LazyShort b = new LazyShort();
+      b.setAll(new byte[]{'0'}, 0, 1);
+      assertEquals(Short.valueOf((short)0), b.getPrimitiveObject());
+      b.setAll(new byte[]{'+', '0'}, 0, 2);
+      assertEquals(Short.valueOf((short)0), b.getPrimitiveObject());
+      b.setAll(new byte[]{'-', '0'}, 0, 2);
+      assertEquals(Short.valueOf((short)0), b.getPrimitiveObject());
+      b.setAll(new byte[]{'a', '1', 'b'}, 1, 1);
+      assertEquals(Short.valueOf((short)1), b.getPrimitiveObject());
+      b.setAll(new byte[]{'a', '-', '1'}, 1, 2);
+      assertEquals(Short.valueOf((short)-1), b.getPrimitiveObject());
+      b.setAll(new byte[]{'a', '+', '1'}, 1, 2);
+      assertEquals(Short.valueOf((short)1), b.getPrimitiveObject());
+      b.setAll(new byte[]{'-', '1', '2', '8'}, 0, 4);
+      assertEquals(Short.valueOf((short)-128), b.getPrimitiveObject());
+      b.setAll(new byte[]{'+', '1', '2', '7'}, 0, 4);
+      assertEquals(Short.valueOf((short)127), b.getPrimitiveObject());
+      b.setAll(new byte[]{'-', '3', '2', '7', '6', '8'}, 0, 6);
+      assertEquals(Short.valueOf((short)-32768), b.getPrimitiveObject());
+      b.setAll(new byte[]{'+', '3', '2', '7', '6', '7'}, 0, 6);
+      assertEquals(Short.valueOf((short)32767), b.getPrimitiveObject());
+
+      b.setAll(new byte[]{'a', '1', 'b'}, 1, 2);
+      assertNull(b.getPrimitiveObject());
+      b.setAll(new byte[]{'-', '3', '2', '7', '6', '9'}, 0, 6);
+      assertNull(b.getPrimitiveObject());
+      b.setAll(new byte[]{'+', '3', '2', '7', '6', '8'}, 0, 6);
+      assertNull(b.getPrimitiveObject());
+      b.setAll(new byte[]{'-', '1', '2', '3'}, 0, 1);
+      assertNull(b.getPrimitiveObject());
+      b.setAll(new byte[]{'+', '1', '2', '3'}, 0, 1);
+      assertNull(b.getPrimitiveObject());
+
+    } catch (Throwable e) {
+      e.printStackTrace();
+      throw e;
+    }
+  }
+     
+
+  /**
+   * Test the LazyInteger class.
+   */
+  public void testLazyInteger() throws Throwable {
+    try {
+      LazyInteger b = new LazyInteger();
+      b.setAll(new byte[]{'0'}, 0, 1);
+      assertEquals(Integer.valueOf((int)0), b.getPrimitiveObject());
+      b.setAll(new byte[]{'+', '0'}, 0, 2);
+      assertEquals(Integer.valueOf((int)0), b.getPrimitiveObject());
+      b.setAll(new byte[]{'-', '0'}, 0, 2);
+      assertEquals(Integer.valueOf((int)0), b.getPrimitiveObject());
+      b.setAll(new byte[]{'a', '1', 'b'}, 1, 1);
+      assertEquals(Integer.valueOf((int)1), b.getPrimitiveObject());
+      b.setAll(new byte[]{'a', '-', '1'}, 1, 2);
+      assertEquals(Integer.valueOf((int)-1), b.getPrimitiveObject());
+      b.setAll(new byte[]{'a', '+', '1'}, 1, 2);
+      assertEquals(Integer.valueOf((int)1), b.getPrimitiveObject());
+      b.setAll(new byte[]{'-', '1', '2', '8'}, 0, 4);
+      assertEquals(Integer.valueOf((int)-128), b.getPrimitiveObject());
+      b.setAll(new byte[]{'+', '1', '2', '7'}, 0, 4);
+      assertEquals(Integer.valueOf((int)127), b.getPrimitiveObject());
+      b.setAll(new byte[]{'-', '3', '2', '7', '6', '8'}, 0, 6);
+      assertEquals(Integer.valueOf((int)-32768), b.getPrimitiveObject());
+      b.setAll(new byte[]{'+', '3', '2', '7', '6', '7'}, 0, 6);
+      assertEquals(Integer.valueOf((int)32767), b.getPrimitiveObject());
+      b.setAll(new byte[]{'-', '2', '1', '4', '7', '4', '8', '3', '6', '4', '8'}, 0, 11);
+      assertEquals(Integer.valueOf((int)-2147483648), b.getPrimitiveObject());
+      b.setAll(new byte[]{'+', '2', '1', '4', '7', '4', '8', '3', '6', '4', '7'}, 0, 11);
+      assertEquals(Integer.valueOf((int)2147483647), b.getPrimitiveObject());
+
+      b.setAll(new byte[]{'a', '1', 'b'}, 1, 2);
+      assertNull(b.getPrimitiveObject());
+      b.setAll(new byte[]{'-', '2', '1', '4', '7', '4', '8', '3', '6', '4', '9'}, 0, 11);
+      assertNull(b.getPrimitiveObject());
+      b.setAll(new byte[]{'+', '2', '1', '4', '7', '4', '8', '3', '6', '4', '8'}, 0, 11);
+      assertNull(b.getPrimitiveObject());
+      b.setAll(new byte[]{'-', '1', '2', '3'}, 0, 1);
+      assertNull(b.getPrimitiveObject());
+      b.setAll(new byte[]{'+', '1', '2', '3'}, 0, 1);
+      assertNull(b.getPrimitiveObject());
+
+    } catch (Throwable e) {
+      e.printStackTrace();
+      throw e;
+    }
+  }
+    
+  
+  /**
+   * Test the LazyLong class.
+   */
+  public void testLazyLong() throws Throwable {
+    try {
+      LazyLong b = new LazyLong();
+      b.setAll(new byte[]{'0'}, 0, 1);
+      assertEquals(Long.valueOf((long)0), b.getPrimitiveObject());
+      b.setAll(new byte[]{'+', '0'}, 0, 2);
+      assertEquals(Long.valueOf((long)0), b.getPrimitiveObject());
+      b.setAll(new byte[]{'-', '0'}, 0, 2);
+      assertEquals(Long.valueOf((long)0), b.getPrimitiveObject());
+      b.setAll(new byte[]{'a', '1', 'b'}, 1, 1);
+      assertEquals(Long.valueOf((long)1), b.getPrimitiveObject());
+      b.setAll(new byte[]{'a', '-', '1'}, 1, 2);
+      assertEquals(Long.valueOf((long)-1), b.getPrimitiveObject());
+      b.setAll(new byte[]{'a', '+', '1'}, 1, 2);
+      assertEquals(Long.valueOf((long)1), b.getPrimitiveObject());
+      b.setAll(new byte[]{'-', '1', '2', '8'}, 0, 4);
+      assertEquals(Long.valueOf((long)-128), b.getPrimitiveObject());
+      b.setAll(new byte[]{'+', '1', '2', '7'}, 0, 4);
+      assertEquals(Long.valueOf((long)127), b.getPrimitiveObject());
+      b.setAll(new byte[]{'-', '3', '2', '7', '6', '8'}, 0, 6);
+      assertEquals(Long.valueOf((long)-32768), b.getPrimitiveObject());
+      b.setAll(new byte[]{'+', '3', '2', '7', '6', '7'}, 0, 6);
+      assertEquals(Long.valueOf((long)32767), b.getPrimitiveObject());
+      b.setAll(new byte[]{'-', '2', '1', '4', '7', '4', '8', '3', '6', '4', '8'}, 0, 11);
+      assertEquals(Long.valueOf((long)-2147483648), b.getPrimitiveObject());
+      b.setAll(new byte[]{'+', '2', '1', '4', '7', '4', '8', '3', '6', '4', '7'}, 0, 11);
+      assertEquals(Long.valueOf((long)2147483647), b.getPrimitiveObject());
+      b.setAll(new byte[]{'-', '9', '2', '2', '3', '3', '7', '2', '0', '3', '6', '8', '5',
+          '4', '7', '7', '5', '8', '0', '8'}, 0, 20);
+      assertEquals(Long.valueOf((long)-9223372036854775808L), b.getPrimitiveObject());
+      b.setAll(new byte[]{'+', '9', '2', '2', '3', '3', '7', '2', '0', '3', '6', '8', '5',
+          '4', '7', '7', '5', '8', '0', '7'}, 0, 20);
+      assertEquals(Long.valueOf((long)9223372036854775807L), b.getPrimitiveObject());
+
+      b.setAll(new byte[]{'a', '1', 'b'}, 1, 2);
+      assertNull(b.getPrimitiveObject());
+      b.setAll(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.getPrimitiveObject());
+      b.setAll(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.getPrimitiveObject());
+      b.setAll(new byte[]{'-', '1', '2', '3'}, 0, 1);
+      assertNull(b.getPrimitiveObject());
+      b.setAll(new byte[]{'+', '1', '2', '3'}, 0, 1);
+      assertNull(b.getPrimitiveObject());
+
+    } catch (Throwable e) {
+      e.printStackTrace();
+      throw e;
+    }
+  }
+
+  /**
+   * Test the LazyDouble class.
+   */
+  public void testLazyDouble() throws Throwable {
+    try {
+      LazyDouble b = new LazyDouble();
+      b.setAll(new byte[]{'0'}, 0, 1);
+      assertEquals(Double.valueOf((double)0), b.getPrimitiveObject());
+      b.setAll(new byte[]{'+', '0'}, 0, 2);
+      assertEquals(Double.valueOf((double)0), b.getPrimitiveObject());
+      b.setAll(new byte[]{'-', '0'}, 0, 2);
+      assertEquals(Double.valueOf((double)-0.0), b.getPrimitiveObject());
+      b.setAll(new byte[]{'a', '1', 'b'}, 1, 1);
+      assertEquals(Double.valueOf((double)1), b.getPrimitiveObject());
+      b.setAll(new byte[]{'a', '-', '1'}, 1, 2);
+      assertEquals(Double.valueOf((double)-1), b.getPrimitiveObject());
+      b.setAll(new byte[]{'a', '+', '1'}, 1, 2);
+      assertEquals(Double.valueOf((double)1), b.getPrimitiveObject());
+      b.setAll(new byte[]{'-', '1', '2', '8'}, 0, 4);
+      assertEquals(Double.valueOf((double)-128), b.getPrimitiveObject());
+      b.setAll(new byte[]{'+', '1', '2', '7'}, 0, 4);
+      assertEquals(Double.valueOf((double)127), b.getPrimitiveObject());
+      b.setAll(new byte[]{'-', '3', '2', '7', '6', '8'}, 0, 6);
+      assertEquals(Double.valueOf((double)-32768), b.getPrimitiveObject());
+      b.setAll(new byte[]{'+', '3', '2', '7', '6', '7'}, 0, 6);
+      assertEquals(Double.valueOf((double)32767), b.getPrimitiveObject());
+      b.setAll(new byte[]{'-', '2', '1', '4', '7', '4', '8', '3', '6', '4', '8'}, 0, 11);
+      assertEquals(Double.valueOf((double)-2147483648), b.getPrimitiveObject());
+      b.setAll(new byte[]{'+', '2', '1', '4', '7', '4', '8', '3', '6', '4', '7'}, 0, 11);
+      assertEquals(Double.valueOf((double)2147483647), b.getPrimitiveObject());
+      b.setAll(new byte[]{'-', '9', '2', '2', '3', '3', '7', '2', '0', '3', '6', '8', '5',
+          '4', '7', '7', '5', '8', '0', '8'}, 0, 20);
+      assertEquals(Double.valueOf((double)-9223372036854775808L), b.getPrimitiveObject());
+      b.setAll(new byte[]{'+', '9', '2', '2', '3', '3', '7', '2', '0', '3', '6', '8', '5',
+          '4', '7', '7', '5', '8', '0', '7'}, 0, 20);
+      assertEquals(Double.valueOf((long)9223372036854775807L), b.getPrimitiveObject());
+
+      b.setAll(new byte[]{'-', '3', '.', '7', '6', '8'}, 0, 6);
+      assertEquals(Double.valueOf((double)-3.768), b.getPrimitiveObject());
+      b.setAll(new byte[]{'+', '3', '.', '7', '6', '7'}, 0, 6);
+      assertEquals(Double.valueOf((double)3.767), b.getPrimitiveObject());
+      b.setAll(new byte[]{'-', '2', '.', '4', '7', '4', '8', '3', '6', 'e', '8'}, 0, 11);
+      assertEquals(Double.valueOf((double)-2.474836e8), b.getPrimitiveObject());
+      b.setAll(new byte[]{'+', '2', '.', '4', '7', '4', '8', '3', 'E', '-', '7'}, 0, 11);
+      assertEquals(Double.valueOf((double)2.47483E-7), b.getPrimitiveObject());
+      b.setAll(new byte[]{'-', '.', '4', '7', '4', '8', '3', '6', 'e', '8'}, 0, 10);
+      assertEquals(Double.valueOf((double)-.474836e8), b.getPrimitiveObject());
+      b.setAll(new byte[]{'+', '.', '4', '7', '4', '8', '3', 'E', '-', '7'}, 0, 10);
+      assertEquals(Double.valueOf((double).47483E-7), b.getPrimitiveObject());
+      b.setAll(new byte[]{'-', '2', '1', '4', '7', '4', '8', '3', '6', '4', '.'}, 0, 11);
+      assertEquals(Double.valueOf((double)-214748364.), b.getPrimitiveObject());
+      b.setAll(new byte[]{'+', '2', '1', '4', '7', '4', '8', '3', '6', '4', '.'}, 0, 11);
+      assertEquals(Double.valueOf((double)+214748364.), b.getPrimitiveObject());
+
+      b.setAll(new byte[]{'.', '0'}, 0, 2);
+      assertEquals(Double.valueOf((double).0), b.getPrimitiveObject());
+      b.setAll(new byte[]{'0', '.'}, 0, 2);
+      assertEquals(Double.valueOf((double)0.), b.getPrimitiveObject());
+      
+      b.setAll(new byte[]{'a', '1', 'b'}, 1, 2);
+      assertNull(b.getPrimitiveObject());
+      assertNull(b.getPrimitiveObject());
+      b.setAll(new byte[]{'.', '1', '2', '3'}, 0, 1);
+      assertNull(b.getPrimitiveObject());
+      b.setAll(new byte[]{'-', '1', '2', '3'}, 0, 1);
+      assertNull(b.getPrimitiveObject());
+      b.setAll(new byte[]{'+', '1', '2', '3'}, 0, 1);
+      assertNull(b.getPrimitiveObject());
+      
+      b.setAll(new byte[]{'-', '1', 'e', '3', '3', '3', '3', '3', '3'}, 0, 9);
+      assertEquals(Double.NEGATIVE_INFINITY, b.getPrimitiveObject());
+      b.setAll(new byte[]{'+', '1', 'e', '3', '3', '3', '3', '3', '3'}, 0, 9);
+      assertEquals(Double.POSITIVE_INFINITY, b.getPrimitiveObject());
+
+      b.setAll(new byte[]{'+', '1', 'e', '-', '3', '3', '3', '3', '3'}, 0, 8);
+      assertEquals(Double.valueOf((double)0), b.getPrimitiveObject());
+      b.setAll(new byte[]{'-', '1', 'e', '-', '3', '3', '3', '3', '3'}, 0, 8);
+      assertEquals(Double.valueOf((double)-0.0), b.getPrimitiveObject());
+      
+    } catch (Throwable e) {
+      e.printStackTrace();
+      throw e;
+    }
+  }
+  
+  /**
+   * Test the LazyString class.
+   */
+  public void testLazyString() throws Throwable {
+    try {
+      LazyString b = new LazyString();
+      b.setAll(new byte[]{'0'}, 0, 1);
+      assertEquals("0", b.getPrimitiveObject());
+      b.setAll(new byte[]{'0', '1', '2'}, 1, 1);
+      assertEquals("1", b.getPrimitiveObject());
+      
+    } catch (Throwable e) {
+      e.printStackTrace();
+      throw e;
+    }
+  }
+}

Added: 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=745212&view=auto
==============================================================================
--- hadoop/hive/trunk/serde/src/test/org/apache/hadoop/hive/serde2/lazy/TestLazySimpleSerDe.java
(added)
+++ hadoop/hive/trunk/serde/src/test/org/apache/hadoop/hive/serde2/lazy/TestLazySimpleSerDe.java
Tue Feb 17 19:39:29 2009
@@ -0,0 +1,187 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.hadoop.hive.serde2.lazy;
+
+
+import java.util.List;
+import java.util.Properties;
+
+import org.apache.hadoop.conf.Configuration;
+import org.apache.hadoop.hive.serde.Constants;
+import org.apache.hadoop.hive.serde2.SerDeException;
+import org.apache.hadoop.hive.serde2.objectinspector.StructField;
+import org.apache.hadoop.hive.serde2.objectinspector.StructObjectInspector;
+import org.apache.hadoop.io.Text;
+
+import junit.framework.TestCase;
+
+public class TestLazySimpleSerDe extends TestCase {
+
+  /**
+   * Test the LazySimpleSerDe class.
+   */
+  public void testLazySimpleSerDe() throws Throwable {
+    try {
+      // Create the SerDe
+      LazySimpleSerDe serDe = new LazySimpleSerDe();
+      Configuration conf = new Configuration();
+      Properties tbl = createProperties();
+      serDe.initialize(conf, tbl);
+
+      // Data
+      Text t = new Text("123\t456\t789\t1000\t5.3\thive and hadoop\t1.\tNULL");
+      String s = "123\t456\t789\t1000\t5.3\thive and hadoop\tNULL\tNULL"; 
+      Object[] expectedFieldsData = { (Object)Byte.valueOf((byte)123),
+          Short.valueOf((short)456), Integer.valueOf(789),
+          Long.valueOf(1000), Double.valueOf(5.3), "hive and hadoop", null,
+          null
+      };
+      
+      // Test
+      deserializeAndSerialize(serDe, t, s, expectedFieldsData);
+     
+    } catch (Throwable e) {
+      e.printStackTrace();
+      throw e;
+    }
+  }
+
+  private void deserializeAndSerialize(LazySimpleSerDe serDe, Text t, String s,
+      Object[] expectedFieldsData) throws SerDeException {
+    // Get the row structure
+    StructObjectInspector oi = (StructObjectInspector)serDe.getObjectInspector();
+    List<? extends StructField> fieldRefs = oi.getAllStructFieldRefs();
+    assertEquals(8, fieldRefs.size());
+    
+    // Deserialize
+    Object row = serDe.deserialize(t);
+    for (int i = 0; i < fieldRefs.size(); i++) {
+      Object fieldData = oi.getStructFieldData(row, fieldRefs.get(i));
+      assertEquals("Field " + i, fieldData, expectedFieldsData[i]);
+    }
+    // Serialize 
+    assertEquals(Text.class, serDe.getSerializedClass());
+    Text serializedText = (Text)serDe.serialize(row, oi);
+    assertEquals("Serialized data", s, serializedText.toString());
+  }
+
+  private Properties createProperties() {
+    Properties tbl = new Properties();
+    
+    // Set the configuration parameters
+    tbl.setProperty(Constants.SERIALIZATION_FORMAT, "9");
+    tbl.setProperty("columns",
+        "abyte,ashort,aint,along,adouble,astring,anullint,anullstring");
+    tbl.setProperty("columns.types",
+        "tinyint:smallint:int:bigint:double:string:int:string");
+    tbl.setProperty(Constants.SERIALIZATION_NULL_FORMAT, "NULL");
+    return tbl;
+  }
+    
+  /**
+   * Test the LazySimpleSerDe class with LastColumnTakesRest option.
+   */
+  public void testLazySimpleSerDeLastColumnTakesRest() throws Throwable {
+    try {
+      // Create the SerDe
+      LazySimpleSerDe serDe = new LazySimpleSerDe();
+      Configuration conf = new Configuration();
+      Properties tbl = createProperties();
+      tbl.setProperty(Constants.SERIALIZATION_LAST_COLUMN_TAKES_REST, "true");
+      serDe.initialize(conf, tbl);
+      
+      // Data
+      Text t = new Text("123\t456\t789\t1000\t5.3\thive and hadoop\t1.\ta\tb\t");
+      String s = "123\t456\t789\t1000\t5.3\thive and hadoop\tNULL\ta\tb\t"; 
+      Object[] expectedFieldsData = { (Object)Byte.valueOf((byte)123),
+          Short.valueOf((short)456), Integer.valueOf(789),
+          Long.valueOf(1000), Double.valueOf(5.3), "hive and hadoop", null,
+          "a\tb\t"
+      };
+      
+      // Test
+      deserializeAndSerialize(serDe, t, s, expectedFieldsData);
+
+    } catch (Throwable e) {
+      e.printStackTrace();
+      throw e;
+    }
+  }
+
+  
+  /**
+   * Test the LazySimpleSerDe class with extra columns.
+   */
+  public void testLazySimpleSerDeExtraColumns() throws Throwable {
+    try {
+      // Create the SerDe
+      LazySimpleSerDe serDe = new LazySimpleSerDe();
+      Configuration conf = new Configuration();
+      Properties tbl = createProperties();
+      serDe.initialize(conf, tbl);
+      
+      // Data
+      Text t = new Text("123\t456\t789\t1000\t5.3\thive and hadoop\t1.\ta\tb\t");
+      String s = "123\t456\t789\t1000\t5.3\thive and hadoop\tNULL\ta"; 
+      Object[] expectedFieldsData = { (Object)Byte.valueOf((byte)123),
+          Short.valueOf((short)456), Integer.valueOf(789),
+          Long.valueOf(1000), Double.valueOf(5.3), "hive and hadoop", null,
+          "a"
+      };
+      
+      // Test
+      deserializeAndSerialize(serDe, t, s, expectedFieldsData);
+
+    } catch (Throwable e) {
+      e.printStackTrace();
+      throw e;
+    }
+  }
+
+  
+  /**
+   * Test the LazySimpleSerDe class with missing columns.
+   */
+  public void testLazySimpleSerDeMissingColumns() throws Throwable {
+    try {
+      // Create the SerDe
+      LazySimpleSerDe serDe = new LazySimpleSerDe();
+      Configuration conf = new Configuration();
+      Properties tbl = createProperties();
+      serDe.initialize(conf, tbl);
+      
+      // Data
+      Text t = new Text("123\t456\t789\t1000\t5.3\t");
+      String s = "123\t456\t789\t1000\t5.3\t\tNULL\tNULL"; 
+      Object[] expectedFieldsData = { (Object)Byte.valueOf((byte)123),
+          Short.valueOf((short)456), Integer.valueOf(789),
+          Long.valueOf(1000), Double.valueOf(5.3), "", null,
+          null
+      };
+      
+      // Test
+      deserializeAndSerialize(serDe, t, s, expectedFieldsData);
+
+    } catch (Throwable e) {
+      e.printStackTrace();
+      throw e;
+    }
+  }
+  
+  
+}



Mime
View raw message