lirui-apache commented on a change in pull request #8536: [FLINK-12568][hive] 
Implement TableSink and OutputFormat to write Hive tables
URL: https://github.com/apache/flink/pull/8536#discussion_r287633517
 
 

 ##########
 File path: 
flink-connectors/flink-connector-hive/src/main/java/org/apache/flink/batch/connectors/hive/HiveTableUtil.java
 ##########
 @@ -0,0 +1,103 @@
+/*
+ * 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.flink.batch.connectors.hive;
+
+import org.apache.flink.api.common.typeinfo.BasicTypeInfo;
+import org.apache.flink.api.common.typeinfo.PrimitiveArrayTypeInfo;
+import org.apache.flink.api.common.typeinfo.SqlTimeTypeInfo;
+import org.apache.flink.api.common.typeinfo.TypeInformation;
+
+import org.apache.hadoop.hive.serde2.objectinspector.ObjectInspector;
+import 
org.apache.hadoop.hive.serde2.objectinspector.primitive.PrimitiveObjectInspectorFactory;
+import org.apache.hadoop.hive.serde2.typeinfo.PrimitiveTypeInfo;
+import org.apache.hadoop.hive.serde2.typeinfo.TypeInfo;
+import org.apache.hadoop.hive.serde2.typeinfo.TypeInfoFactory;
+
+import java.io.IOException;
+
+/**
+ * Util class for accessing Hive tables.
+ */
+public class HiveTableUtil {
+
+       private HiveTableUtil() {
+       }
+
+       /**
+        * Get Hive {@link ObjectInspector} for a Flink {@link TypeInformation}.
+        */
+       public static ObjectInspector getObjectInspector(TypeInformation 
flinkType) throws IOException {
+               return getObjectInspector(toHiveTypeInfo(flinkType));
+       }
+
+       // TODO: reuse Hive's TypeInfoUtils?
+       private static ObjectInspector getObjectInspector(TypeInfo type) throws 
IOException {
+               switch (type.getCategory()) {
+
+                       case PRIMITIVE:
+                               PrimitiveTypeInfo primitiveType = 
(PrimitiveTypeInfo) type;
+                               return 
PrimitiveObjectInspectorFactory.getPrimitiveJavaObjectInspector(primitiveType);
+
+                       // TODO: support complex types
+                       default:
+                               throw new IOException("Unsupported Hive type 
category " + type.getCategory());
+               }
+       }
+
+       /**
+        * Converts a Flink {@link TypeInformation} to corresponding Hive 
{@link TypeInfo}.
+        */
+       public static TypeInfo toHiveTypeInfo(TypeInformation flinkType) {
 
 Review comment:
   It's not. We need a `TypeInfo` here and `HiveTypeUtil.toHiveType()` gives 
the name of a hive type. But I guess this method can be moved to `HiveTypeUtil`

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


With regards,
Apache Git Services

Reply via email to