You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@flink.apache.org by GitBox <gi...@apache.org> on 2019/06/06 17:33:03 UTC

[GitHub] [flink] bowenli86 commented on a change in pull request #8645: Support mapping BinaryType, VarBinaryType, CharType, VarCharType, and DecimalType between Flink and Hive in HiveCatalog

bowenli86 commented on a change in pull request #8645: Support mapping BinaryType, VarBinaryType, CharType, VarCharType, and DecimalType between Flink and Hive in HiveCatalog
URL: https://github.com/apache/flink/pull/8645#discussion_r291293042
 
 

 ##########
 File path: flink-connectors/flink-connector-hive/src/main/java/org/apache/flink/table/catalog/hive/util/HiveTypeUtil.java
 ##########
 @@ -18,127 +18,174 @@
 
 package org.apache.flink.table.catalog.hive.util;
 
-import org.apache.flink.api.common.typeinfo.BasicArrayTypeInfo;
-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.flink.table.api.DataTypes;
+import org.apache.flink.table.catalog.exceptions.CatalogException;
+import org.apache.flink.table.types.DataType;
+import org.apache.flink.table.types.logical.BinaryType;
+import org.apache.flink.table.types.logical.CharType;
+import org.apache.flink.table.types.logical.DecimalType;
+import org.apache.flink.table.types.logical.LogicalType;
+import org.apache.flink.table.types.logical.VarBinaryType;
+import org.apache.flink.table.types.logical.VarCharType;
 
-import org.apache.hadoop.hive.serde.serdeConstants;
+import org.apache.hadoop.hive.common.type.HiveChar;
+import org.apache.hadoop.hive.common.type.HiveVarchar;
+import org.apache.hadoop.hive.serde2.typeinfo.CharTypeInfo;
+import org.apache.hadoop.hive.serde2.typeinfo.DecimalTypeInfo;
 import org.apache.hadoop.hive.serde2.typeinfo.ListTypeInfo;
 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 org.apache.hadoop.hive.serde2.typeinfo.VarcharTypeInfo;
 
 /**
  * Utils to convert data types between Flink and Hive.
  */
 public class HiveTypeUtil {
 
-	// Note: Need to keep this in sync with BaseSemanticAnalyzer::getTypeStringFromAST
-	private static final String HIVE_ARRAY_TYPE_NAME_FORMAT = serdeConstants.LIST_TYPE_NAME + "<%s>";
-
 	private HiveTypeUtil() {
 	}
 
+	/**
+	 * Convert Flink data type to Hive data type name.
+	 * TODO: the following Hive types are not supported in Flink yet, including MAP, STRUCT
+	 *
+	 * @param type a Flink data type
+	 * @return the corresponding Hive data type name
+	 */
+	public static String toHiveTypeName(DataType type) {
+		return toHiveTypeInfo(type).getTypeName();
+	}
+
 	/**
 	 * Convert Flink data type to Hive data type.
-	 * TODO: the following Hive types are not supported in Flink yet, including CHAR, VARCHAR, DECIMAL, MAP, STRUCT
-	 * 		[FLINK-12386] Support complete mapping between Flink and Hive data types
 	 *
 	 * @param type a Flink data type
 	 * @return the corresponding Hive data type
 	 */
-	public static String toHiveType(TypeInformation type) {
-		if (type.equals(BasicTypeInfo.BOOLEAN_TYPE_INFO)) {
-			return serdeConstants.BOOLEAN_TYPE_NAME;
-		} else if (type.equals(BasicTypeInfo.BYTE_TYPE_INFO)) {
-			return serdeConstants.TINYINT_TYPE_NAME;
-		} else if (type.equals(BasicTypeInfo.SHORT_TYPE_INFO)) {
-			return serdeConstants.SMALLINT_TYPE_NAME;
-		} else if (type.equals(BasicTypeInfo.INT_TYPE_INFO)) {
-			return serdeConstants.INT_TYPE_NAME;
-		} else if (type.equals(BasicTypeInfo.LONG_TYPE_INFO)) {
-			return serdeConstants.BIGINT_TYPE_NAME;
-		} else if (type.equals(BasicTypeInfo.FLOAT_TYPE_INFO)) {
-			return serdeConstants.FLOAT_TYPE_NAME;
-		} else if (type.equals(BasicTypeInfo.DOUBLE_TYPE_INFO)) {
-			return serdeConstants.DOUBLE_TYPE_NAME;
-		} else if (type.equals(BasicTypeInfo.STRING_TYPE_INFO)) {
-			return serdeConstants.STRING_TYPE_NAME;
-		} else if (type.equals(SqlTimeTypeInfo.DATE)) {
-			return serdeConstants.DATE_TYPE_NAME;
-		} else if (type.equals(PrimitiveArrayTypeInfo.BYTE_PRIMITIVE_ARRAY_TYPE_INFO)) {
-			return serdeConstants.BINARY_TYPE_NAME;
-		} else if (type.equals(SqlTimeTypeInfo.TIMESTAMP)) {
-			return serdeConstants.TIMESTAMP_TYPE_NAME;
+	public static TypeInfo toHiveTypeInfo(DataType type) {
 
 Review comment:
   IIUC, the nullable flag only indicate nullability of the value, right? 
   
   From `LogicalType`'s javadoc:
   > The definition of a logical type .... contains information about the nullability of a value for efficient handling of scalar expressions
   
   That seems a bit irrelevant to the type conversion to me

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


With regards,
Apache Git Services