Uploaded image for project: 'Hive'
  1. Hive
  2. HIVE-3866

Allow sort_array to work on non-primitive types.

    XMLWordPrintableJSON

Details

    • Improvement
    • Status: Open
    • Major
    • Resolution: Unresolved
    • None
    • None
    • None
    • None

    Description

      It's also nice to be able to sort an array of structs, as a kind of generalization of HIVE-1128, so you can have not only the maximum value from a list but a sorted list of value and source keys. As with HIVE-3865 it's fairly easy to relax the assumption that sort_array works only on primitives:

      @@ -35,6 +35,7 @@ import org.apache.hadoop.hive.serde2.objectinspector.ObjectInspectorConverters;
      import org.apache.hadoop.hive.serde2.objectinspector.ObjectInspectorConverters.Converter;
      import org.apache.hadoop.hive.serde2.objectinspector.ObjectInspectorFactory;
      import org.apache.hadoop.hive.serde2.objectinspector.ObjectInspectorUtils;
      +import org.apache.hadoop.hive.serde2.typeinfo.TypeInfoUtils;

      /**

      • Generic UDF for array sort
        @@ -66,10 +67,12 @@ public class GenericUDFSortArray extends GenericUDF {

      switch(arguments[0].getCategory()) {
      case LIST:

      • if(((ListObjectInspector)(arguments[0])).getListElementObjectInspector()
      • .getCategory().equals(Category.PRIMITIVE)) { - break; - }

        + ObjectInspector loi = ((ListObjectInspector)(arguments[0])).getListElementObjectInspector();
        + if (!ObjectInspectorUtils.compareSupported(loi))

        { + throw new UDFArgumentTypeException(0, + "Cannot support comparison of map<> type or complex type containing map<>."); + }

        + break;
        default:
        throw new UDFArgumentTypeException(0, "Argument 1"
        + " of function SORT_ARRAY must be array "

      Attachments

        Issue Links

          Activity

            People

              Unassigned Unassigned
              rbodkin Ron Bodkin
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

                Created:
                Updated: