iceberg-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From GitBox <...@apache.org>
Subject [GitHub] [iceberg] rdblue commented on a change in pull request #1103: Add IcebergSerDe
Date Tue, 30 Jun 2020 01:09:06 GMT

rdblue commented on a change in pull request #1103:
URL: https://github.com/apache/iceberg/pull/1103#discussion_r447348111



##########
File path: mr/src/main/java/org/apache/iceberg/mr/mapred/serde/objectinspector/IcebergObjectInspector.java
##########
@@ -0,0 +1,118 @@
+/*
+ * 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.mapred.serde.objectinspector;
+
+import java.util.List;
+import javax.annotation.Nullable;
+import org.apache.hadoop.hive.serde2.objectinspector.ObjectInspector;
+import org.apache.hadoop.hive.serde2.objectinspector.ObjectInspectorFactory;
+import org.apache.hadoop.hive.serde2.objectinspector.primitive.PrimitiveObjectInspectorFactory;
+import org.apache.hadoop.hive.serde2.typeinfo.PrimitiveTypeInfo;
+import org.apache.hadoop.hive.serde2.typeinfo.TypeInfoFactory;
+import org.apache.iceberg.Schema;
+import org.apache.iceberg.types.Type;
+import org.apache.iceberg.types.TypeUtil;
+import org.apache.iceberg.types.Types;
+
+public final class IcebergObjectInspector extends TypeUtil.SchemaVisitor<ObjectInspector>
{
+
+  public static ObjectInspector create(@Nullable Schema schema) {
+    if (schema == null) {
+      return IcebergRecordObjectInspector.empty();
+    }
+
+    return TypeUtil.visit(schema, new IcebergObjectInspector());
+  }
+
+  public static ObjectInspector create(Types.NestedField... fields) {
+    return create(new Schema(fields));
+  }
+
+  @Override
+  public ObjectInspector field(Types.NestedField field, ObjectInspector fieldObjectInspector)
{
+    return fieldObjectInspector;
+  }
+
+  @Override
+  public ObjectInspector list(Types.ListType listTypeInfo, ObjectInspector listObjectInspector)
{
+    return ObjectInspectorFactory.getStandardListObjectInspector(listObjectInspector);
+  }
+
+  @Override
+  public ObjectInspector map(Types.MapType mapType,
+                             ObjectInspector keyObjectInspector, ObjectInspector valueObjectInspector)
{
+    return ObjectInspectorFactory.getStandardMapObjectInspector(keyObjectInspector, valueObjectInspector);
+  }
+
+  @Override
+  public ObjectInspector primitive(Type.PrimitiveType primitiveType) {
+    final PrimitiveTypeInfo primitiveTypeInfo;
+
+    switch (primitiveType.typeId()) {
+      case BINARY:
+        return IcebergBinaryObjectInspector.get();
+      case BOOLEAN:
+        primitiveTypeInfo = TypeInfoFactory.booleanTypeInfo;
+        break;
+      case DATE:
+        return IcebergDateObjectInspector.get();
+      case DECIMAL:
+        Types.DecimalType type = (Types.DecimalType) primitiveType;
+        return IcebergDecimalObjectInspector.get(type.precision(), type.scale());
+      case DOUBLE:
+        primitiveTypeInfo = TypeInfoFactory.doubleTypeInfo;
+        break;
+      case FLOAT:
+        primitiveTypeInfo = TypeInfoFactory.floatTypeInfo;
+        break;
+      case INTEGER:
+        primitiveTypeInfo = TypeInfoFactory.intTypeInfo;
+        break;
+      case LONG:
+        primitiveTypeInfo = TypeInfoFactory.longTypeInfo;
+        break;
+      case STRING:
+        primitiveTypeInfo = TypeInfoFactory.stringTypeInfo;
+        break;
+      case TIMESTAMP:
+        boolean adjustToUTC = ((Types.TimestampType) primitiveType).shouldAdjustToUTC();
+        return IcebergTimestampObjectInspector.get(adjustToUTC);
+
+      case FIXED:
+      case TIME:
+      case UUID:
+      default:
+        throw new IllegalArgumentException(primitiveType.typeId() + " type is not supported");

Review comment:
       Couldn't fixed by read as binary? And UUID as string? And doesn't Hive support time?




----------------------------------------------------------------
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:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org


Mime
View raw message