qphien commented on a change in pull request #1612:
URL: https://github.com/apache/iceberg/pull/1612#discussion_r521340803



##########
File path: mr/src/main/java/org/apache/iceberg/mr/hive/HiveSchemaVisitor.java
##########
@@ -0,0 +1,105 @@
+/*
+ * 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.ArrayList;
+import java.util.List;
+import org.apache.hadoop.hive.serde2.typeinfo.DecimalTypeInfo;
+import org.apache.hadoop.hive.serde2.typeinfo.ListTypeInfo;
+import org.apache.hadoop.hive.serde2.typeinfo.MapTypeInfo;
+import org.apache.hadoop.hive.serde2.typeinfo.PrimitiveTypeInfo;
+import org.apache.hadoop.hive.serde2.typeinfo.StructTypeInfo;
+import org.apache.hadoop.hive.serde2.typeinfo.TypeInfo;
+import org.apache.iceberg.types.Type;
+import org.apache.iceberg.types.Types;
+
+public class HiveSchemaVisitor {
+  private int id;
+
+  public HiveSchemaVisitor() {
+    id = 0;
+  }
+
+  List<Types.NestedField> visit(List<String> names, List<TypeInfo> typeInfos) {
+    List<Types.NestedField> result = new ArrayList<>(names.size());
+    for (int i = 0; i < names.size(); ++i) {
+      result.add(Types.NestedField.optional(id++, names.get(i), 
visit(typeInfos.get(i))));
+    }
+
+    return result;
+  }
+
+  Type visit(TypeInfo typeInfo) {
+    switch (typeInfo.getCategory()) {
+      case PRIMITIVE:
+        switch (((PrimitiveTypeInfo) typeInfo).getPrimitiveCategory()) {
+          case FLOAT:
+            return Types.FloatType.get();
+          case DOUBLE:
+            return Types.DoubleType.get();
+          case BOOLEAN:
+            return Types.BooleanType.get();
+          case BYTE:
+          case SHORT:
+          case INT:
+            return Types.IntegerType.get();
+          case LONG:
+            return Types.LongType.get();
+          case BINARY:
+            return Types.BinaryType.get();
+          case STRING:
+          case CHAR:
+          case VARCHAR:
+            return Types.StringType.get();
+          case TIMESTAMP:
+            return Types.TimestampType.withoutZone();

Review comment:
       Sorry for my late reply. I have a iceberg table schema like below:
   ```
   hive (default)> desc complex_iceberg_table_2;
   OK
   col_name     data_type       comment
   id                   bigint                  from deserializer
   user                 string                  from deserializer
   asset                decimal(7,3)            from deserializer
   event_time           timestamp               from deserializer
   day                  date                    from deserializer
   logs                 array<string>           from deserializer
   location             map<string,string>      from deserializer
   verbose              struct<idcomment:string,count:int,elements:array<int>>  
from deserializer
   ```
   
   when i select event_time, hive throws ClassCastException
   ```
   hive (default)> select event_time from complex_iceberg_table_2;
   OK
   event_time
   Failed with exception 
java.io.IOException:org.apache.hadoop.hive.ql.metadata.HiveException: 
java.lang.ClassCastException: java.time.OffsetDateTime cannot be cast to 
java.time.LocalDateTime
   ```




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