pvary commented on a change in pull request #1854:
URL: https://github.com/apache/iceberg/pull/1854#discussion_r537123044



##########
File path: mr/src/test/java/org/apache/iceberg/mr/hive/TestDeserializer.java
##########
@@ -0,0 +1,113 @@
+/*
+ * 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.iceberg.mr.hive;
+
+import java.util.Arrays;
+import org.apache.hadoop.hive.serde2.SerDeException;
+import org.apache.hadoop.hive.serde2.objectinspector.ObjectInspectorFactory;
+import 
org.apache.hadoop.hive.serde2.objectinspector.StandardStructObjectInspector;
+import 
org.apache.hadoop.hive.serde2.objectinspector.primitive.PrimitiveObjectInspectorFactory;
+import org.apache.hadoop.io.LongWritable;
+import org.apache.hadoop.io.Text;
+import org.apache.iceberg.Schema;
+import org.apache.iceberg.data.GenericRecord;
+import org.apache.iceberg.data.Record;
+import org.apache.iceberg.hive.MetastoreUtil;
+import org.apache.iceberg.types.Types;
+import org.junit.Assert;
+import org.junit.Assume;
+import org.junit.Test;
+
+import static org.apache.iceberg.types.Types.NestedField.optional;
+
+public class TestDeserializer {
+  private static final Schema CUSTOMER_SCHEMA = new Schema(
+      optional(1, "customer_id", Types.LongType.get()),
+      optional(2, "first_name", Types.StringType.get())
+  );
+
+  private static final StandardStructObjectInspector CUSTOMER_OBJECT_INSPECTOR 
=
+      ObjectInspectorFactory.getStandardStructObjectInspector(
+          Arrays.asList("customer_id", "first_name"),
+          Arrays.asList(
+              PrimitiveObjectInspectorFactory.writableLongObjectInspector,
+              PrimitiveObjectInspectorFactory.writableStringObjectInspector
+          ));
+
+
+  @Test
+  public void testSimpleDeserialize() throws SerDeException {
+    Deserializer deserializer = new Deserializer(CUSTOMER_SCHEMA, 
CUSTOMER_OBJECT_INSPECTOR);
+
+    Record expected = GenericRecord.create(CUSTOMER_SCHEMA);
+    expected.set(0, 1L);
+    expected.set(1, "Bob");
+
+    Record actual = deserializer.deserialize(new Object[] { new 
LongWritable(1L), new Text("Bob") });
+
+    Assert.assertEquals(expected, actual);
+  }
+
+  @Test
+  public void testDeserializeEverySupportedType() throws SerDeException {
+    // No test yet for Hive3 (Date/Timestamp creation)
+    Assume.assumeFalse(MetastoreUtil.hive3PresentOnClasspath());
+
+    Deserializer deserializer = new 
Deserializer(HiveIcebergTestUtils.FULL_SCHEMA,
+        HiveIcebergTestUtils.FULL_SCHEMA_OBJECT_INSPECTOR);
+
+    Record expected = HiveIcebergTestUtils.getTestRecord(false);
+    Record actual = 
deserializer.deserialize(HiveIcebergTestUtils.valuesForTestRecord(expected));
+
+    HiveIcebergTestUtils.assertEquals(expected, actual);
+  }
+
+  @Test
+  public void testNullDeserialize() throws SerDeException {
+    Deserializer deserializer = new 
Deserializer(HiveIcebergTestUtils.FULL_SCHEMA,
+        HiveIcebergTestUtils.FULL_SCHEMA_OBJECT_INSPECTOR);
+
+    Record expected = HiveIcebergTestUtils.getNullTestRecord();
+
+    Object[] nulls = new 
Object[HiveIcebergTestUtils.FULL_SCHEMA.columns().size()];
+    Arrays.fill(nulls, null);
+
+    Record actual = deserializer.deserialize(nulls);
+
+    Assert.assertEquals(expected, actual);
+
+    // Check null record as well
+    Assert.assertNull(deserializer.deserialize(null));
+  }
+
+  @Test(expected = SerDeException.class)
+  public void testSerDeException() throws SerDeException {

Review comment:
       Yeah. The SerDe should only throw SerDeException.
   But we can throw whatever we want here, and wrap it later to SerDeException.
   
   Fixed




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
[email protected]



---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to