1

I tried to create an hive UDF, which returns multiple results. longitude and latitude are arguments for UDF.

When I run the function, I got "FAILED: RuntimeException Internal error: Cannot find ObjectInspector for UNKNOWN" error.

Code:

import java.util.ArrayList;

import org.apache.hadoop.hive.ql.exec.UDFArgumentException;
import org.apache.hadoop.hive.ql.exec.UDFArgumentLengthException;
import org.apache.hadoop.hive.ql.metadata.HiveException;
import org.apache.hadoop.hive.ql.udf.generic.GenericUDF;
import org.apache.hadoop.hive.serde2.objectinspector.ObjectInspector;
import org.apache.hadoop.hive.serde2.objectinspector.ObjectInspectorFactory;
import org.apache.hadoop.hive.serde2.objectinspector.primitive.PrimitiveObjectInspectorFactory;


public class GetStateName extends GenericUDF {
    private ArrayList<String> result;

    public Object evaluate(DeferredObject[] arg0) throws HiveException {
        String lat = arg0[0].toString();
        String lng = arg0[1].toString();
        ArrayList<String> tmpLatLng = LookUp.getLatLng(lat,lng);

        result = new ArrayList<String>();
        result.add(tmpLatLng.get(0));
        result.add(tmpLatLng.get(1));
        return result;
    }

    public String getDisplayString(String[] arg0) {
        return new String("Address");
    }


    public ObjectInspector initialize(ObjectInspector[] arguments)
            throws UDFArgumentException {
        // Exactly one input argument
        if( arguments.length != 2 ) {
            throw new UDFArgumentLengthException( " accepts exactly two argument.");
        }

        return ObjectInspectorFactory.getStandardListObjectInspector(PrimitiveObjectInspectorFactory.javaHiveVarcharObjectInspector);
    }

}
Billal Begueradj
  • 20,717
  • 43
  • 112
  • 130
Var
  • 11
  • 3

1 Answers1

0

hive UDF not support Object as return type, Replace Object with String。 public Object evaluate -> public String evaluate

data dev
  • 13
  • 3