Github user sansanichfb commented on a diff in the pull request:

    https://github.com/apache/incubator-hawq/pull/873#discussion_r77883840
  
    --- Diff: 
pxf/pxf-hive/src/main/java/org/apache/hawq/pxf/plugins/hive/utilities/EnumHiveToHawqType.java
 ---
    @@ -110,4 +122,68 @@ public static EnumHiveToHawqType 
getHiveToHawqType(String hiveType) {
                     + hiveType + " to HAWQ's type");
         }
     
    +
    +    /**
    +     * 
    +     * @param dataType Hawq data type
    +     * @return compatible Hive type to given Hawq type, if there are more 
than one compatible types, it returns one with bigger size
    +     * @throws UnsupportedTypeException if there is no corresponding Hive 
type for given Hawq type
    +     */
    +    public static EnumHiveToHawqType getCompatibleHawqToHiveType(DataType 
dataType) {
    +
    +        SortedSet<EnumHiveToHawqType> types = new 
TreeSet<EnumHiveToHawqType>(
    +                new Comparator<EnumHiveToHawqType>() {
    +                    public int compare(EnumHiveToHawqType a,
    +                            EnumHiveToHawqType b) {
    +                        return Byte.compare(a.getSize(), b.getSize());
    +                    }
    +                });
    +
    +        for (EnumHiveToHawqType t : values()) {
    +            if (t.getHawqType().getDataType().equals(dataType)) {
    +                types.add(t);
    +            }
    +        }
    +
    +        if (types.size() == 0)
    +            throw new UnsupportedTypeException("Unable to find compatible 
Hive type for given HAWQ's type: " + dataType);
    +
    +        return types.last();
    +    }
    +
    +    /**
    +     * 
    +     * @param hiveType full Hive data type, i.e. varchar(10) etc
    +     * @return array of type modifiers
    +     * @throws UnsupportedTypeException if there is no such Hive type 
supported
    +     */
    +    public static Integer[] extractModifiers(String hiveType) {
    +        Integer[] result = null;
    +        for (EnumHiveToHawqType t : values()) {
    +            String hiveTypeName = hiveType;
    +            String splitExpression = t.getSplitExpression();
    +            if (splitExpression != null) {
    +                String[] tokens = hiveType.split(splitExpression);
    +                hiveTypeName = tokens[0];
    +                result = new Integer[tokens.length - 1];
    +                for (int i = 0; i < tokens.length - 1; i++)
    +                    result[i] = Integer.parseInt(tokens[i+1]);
    +            }
    +            if (t.getTypeName().toLowerCase()
    +                    .equals(hiveTypeName.toLowerCase())) {
    +                return result;
    +            }
    +        }
    +        throw new UnsupportedTypeException("Unable to map Hive's type: "
    +                + hiveType + " to HAWQ's type");
    +    }
    +
    +    /**
    --- End diff --
    
    I also was thinking this way, but it's private field so I've added Javadoc 
to public getter so it would be available to callers.


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

Reply via email to