Github user GodenYao commented on a diff in the pull request:
https://github.com/apache/incubator-hawq/pull/873#discussion_r77076942
--- 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());
+
+ switch (hawqDataType) {
+ case NUMERIC:
+ case VARCHAR:
+ case BPCHAR:
+ case CHAR:
+ if (hawqTypeMods != null && hawqTypeMods.length > 0) {
+ Integer[] hiveTypeModifiers = EnumHiveToHawqType
+ .extractModifiers(hiveType);
+ for (int i = 0; i < hiveTypeModifiers.length; i++) {
+ if (hawqTypeMods[i] < hiveTypeModifiers[i])
+ throw new UnsupportedTypeException(
+ "Invalid definition for column " +
hawqColumnName
+ + ": modifiers are not
compatible, "
+ +
Arrays.toString(hiveTypeModifiers) + ", "
+ +
Arrays.toString(hawqTypeMods));
--- End diff --
same as above comment, should tell user the length for modifier , for
numeric, it needs to be exactly match I suppose? for VARCHAR, BPCHAR and CHAR,
if modifier exists on HAWQ side, it needs to be >= Hive same type modifier.
---
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 [email protected] or file a JIRA ticket
with INFRA.
---