Github user GodenYao commented on a diff in the pull request: https://github.com/apache/incubator-hawq/pull/873#discussion_r77084340 --- Diff: pxf/pxf-hive/src/main/java/org/apache/hawq/pxf/plugins/hive/utilities/HiveUtilities.java --- @@ -256,4 +257,68 @@ private static boolean verifyIntegerModifiers(String[] modifiers) { throw new RuntimeException("Failed connecting to Hive MetaStore service: " + cause.getMessage(), cause); } } + + + /** + * Converts HAWQ type to hive type. The supported mappings are:<ul> + * <li>{@code BOOLEAN -> boolean}</li> + * <li>{@code SMALLINT -> smallint (tinyint is converted to smallint)}</li> + * <li>{@code BIGINT -> bigint}</li> + * <li>{@code TIMESTAMP -> timestamp}</li> + * <li>{@code NUMERIC -> decimal}</li> + * <li>{@code BYTEA -> binary}</li> + * <li>{@code INTERGER -> int}</li> + * <li>{@code TEXT -> string}</li> + * <li>{@code REAL -> float}</li> + * <li>{@code FLOAT8 -> double}</li> + * </ul> + * All other types (both in HAWQ and in HIVE) are not supported. + * + * @param type HAWQ data type + * @param name field name + * @return Hive type + * @throws UnsupportedTypeException if type is not supported + */ + public static String toCompatibleHiveType(DataType type) { + + EnumHiveToHawqType hiveToHawqType = EnumHiveToHawqType.getCompatibleHawqToHiveType(type); + return hiveToHawqType.getTypeName(); + } + + + + public static void validateTypeCompatible(DataType hawqDataType, Integer[] hawqTypeMods, String hiveType, String hawqColumnName) { + + EnumHiveToHawqType hiveToHawqType = EnumHiveToHawqType.getHiveToHawqType(hiveType); + EnumHawqType expectedHawqType = hiveToHawqType.getHawqType(); + + if (!expectedHawqType.getDataType().equals(hawqDataType)) { + throw new UnsupportedTypeException("Invalid definition for column " + hawqColumnName + + ": expected HAWQ type " + expectedHawqType.getDataType() + + ", actual HAWQ type " + hawqDataType); + } + + if ((hawqTypeMods == null || hawqTypeMods.length == 0) && expectedHawqType.isMandatoryModifiers()) + throw new UnsupportedTypeException("Invalid definition for column " + hawqColumnName + ": modifiers are mandatory for type " + expectedHawqType.getTypeName()); + --- End diff -- Another thing: ``` CharType("char", EnumHawqType.BpcharType, "[(,)]"), ``` according to the code above, we convert Hive: char to HAWQ: Bpchar type. In that case, why do we need to check modifier as HAWQ: char (xxx) won't be compared, it's different oid of HAWQ: Bpchar
--- If your project is set up for it, you can reply to this email and have your reply appear on GitHub as well. If your project does not have this feature enabled and wishes so, or if the feature is enabled but not working, please contact infrastructure at infrastruct...@apache.org or file a JIRA ticket with INFRA. ---