Github user sansanichfb commented on a diff in the pull request: https://github.com/apache/incubator-hawq/pull/873#discussion_r77881496 --- Diff: pxf/pxf-hive/src/main/java/org/apache/hawq/pxf/plugins/hive/utilities/HiveUtilities.java --- @@ -256,4 +257,61 @@ private static boolean verifyIntegerModifiers(String[] modifiers) { throw new RuntimeException("Failed connecting to Hive MetaStore service: " + cause.getMessage(), cause); } } + + + /** + * Converts HAWQ type to hive type. + * @see EnumHiveToHawqType For supported mappings + * @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.getCompatibleHiveToHawqType(type); + return hiveToHawqType.getTypeName(); + } + + + + /** + * Validates whether given HAWQ and Hive data types are compatible + * + * @param hawqDataType HAWQ data type + * @param hawqTypeMods HAWQ type modifiers + * @param hiveType full Hive type, i.e. decimal(10,2) + * @param hawqColumnName Hive column name + * @throws UnsupportedTypeException if types are incompatible + */ + 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); + } + + switch (hawqDataType) { + case NUMERIC: + case VARCHAR: + case BPCHAR: + if (hawqTypeMods != null && hawqTypeMods.length > 0) { + Integer[] hiveTypeModifiers = EnumHiveToHawqType + .extractModifiers(hiveType); + for (int i = 0; i < hiveTypeModifiers.length; i++) { --- End diff -- Yes, we require HAWQ's type equal or bigger than Hive or no modifiers at all. Will add it to Javadoc.
--- 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. ---