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



##########
File path: mr/src/main/java/org/apache/iceberg/mr/hive/Deserializer.java
##########
@@ -0,0 +1,129 @@
+/*
+ * 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.List;
+import java.util.UUID;
+import org.apache.hadoop.hive.serde2.SerDeException;
+import org.apache.hadoop.hive.serde2.objectinspector.ObjectInspector;
+import org.apache.hadoop.hive.serde2.objectinspector.StructField;
+import org.apache.hadoop.hive.serde2.objectinspector.StructObjectInspector;
+import 
org.apache.hadoop.hive.serde2.objectinspector.primitive.BooleanObjectInspector;
+import 
org.apache.hadoop.hive.serde2.objectinspector.primitive.DoubleObjectInspector;
+import 
org.apache.hadoop.hive.serde2.objectinspector.primitive.FloatObjectInspector;
+import 
org.apache.hadoop.hive.serde2.objectinspector.primitive.IntObjectInspector;
+import 
org.apache.hadoop.hive.serde2.objectinspector.primitive.LongObjectInspector;
+import 
org.apache.hadoop.hive.serde2.objectinspector.primitive.StringObjectInspector;
+import org.apache.iceberg.Schema;
+import org.apache.iceberg.data.GenericRecord;
+import org.apache.iceberg.data.Record;
+import 
org.apache.iceberg.mr.hive.serde.objectinspector.IcebergWriteObjectInspector;
+import org.apache.iceberg.types.Type;
+import org.apache.iceberg.types.Types;
+
+class Deserializer {
+  private FieldDeserializer fieldDeserializer;
+
+  Deserializer(Schema schema, ObjectInspector fieldInspector) throws 
SerDeException {
+    this.fieldDeserializer = deserializer(schema.asStruct(), fieldInspector);
+  }
+
+  Record deserialize(Object data) {
+    return (Record) fieldDeserializer.value(data);
+  }
+
+  private interface FieldDeserializer {
+    Object value(Object object);
+  }
+
+  private static FieldDeserializer deserializer(Type type, ObjectInspector 
fieldInspector) throws SerDeException {
+    switch (type.typeId()) {
+      case BOOLEAN:
+        return o -> ((BooleanObjectInspector) fieldInspector).get(o);
+      case INTEGER:
+        return o -> ((IntObjectInspector) fieldInspector).get(o);
+      case LONG:
+        return o -> ((LongObjectInspector) fieldInspector).get(o);
+      case FLOAT:
+        return o -> ((FloatObjectInspector) fieldInspector).get(o);
+      case DOUBLE:
+        return o -> ((DoubleObjectInspector) fieldInspector).get(o);
+      case STRING:
+        return o -> ((StringObjectInspector) 
fieldInspector).getPrimitiveJavaObject(o);
+      case UUID:
+        // TODO: This will not work with Parquet. Parquet UUID expect byte[], 
others are expecting UUID
+        return o -> UUID.fromString(((StringObjectInspector) 
fieldInspector).getPrimitiveJavaObject(o));
+      case DATE:
+      case TIMESTAMP:
+      case FIXED:
+      case BINARY:
+      case DECIMAL:
+        // Iceberg specific conversions
+        return o -> ((IcebergWriteObjectInspector) 
fieldInspector).getIcebergObject(o);
+      case STRUCT:
+        return new StructDeserializer((Types.StructType) type, 
(StructObjectInspector) fieldInspector);
+      case LIST:
+      case MAP:
+      case TIME:
+      default:
+        throw new SerDeException("Unsupported column type: " + type);

Review comment:
       Haven't planned for that but it was quite easy with the Visitor, so I 
have done this.




----------------------------------------------------------------
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