You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@hive.apache.org by lei liu <li...@gmail.com> on 2010/10/19 10:41:09 UTC

I define one UDF function, the UDf retunr List ,but When I use ResultSet to receive result hive throw exception

I define one UDF function, like as below :
public class TestUDF extends GenericUDF{

    private ObjectInspector[] argumentOIs;

    @Override
    public Object evaluate(DeferredObject[] arguments) throws HiveException
{
      ArrayList<DoubleWritable[]> result = new
ArrayList<DoubleWritable[]>();
      DoubleWritable[] bin = new DoubleWritable[2];
      bin[0] = new DoubleWritable(0);
      bin[1] = new DoubleWritable(1);
      result.add(bin);
     return result;
    }

    @Override
    public String getDisplayString(String[] children) {
        // TODO Auto-generated method stub
        return "";
    }

    @Override
    public ObjectInspector initialize(ObjectInspector[] arguments)
            throws UDFArgumentException {
        argumentOIs = arguments;

        ArrayList<ObjectInspector> foi = new ArrayList<ObjectInspector>();

foi.add(PrimitiveObjectInspectorFactory.writableDoubleObjectInspector);

foi.add(PrimitiveObjectInspectorFactory.writableDoubleObjectInspector);
        ArrayList<String> fname = new ArrayList<String>();
        fname.add("x");
        fname.add("y");

        return
ObjectInspectorFactory.getStandardListObjectInspector(ObjectInspectorFactory.getStandardStructObjectInspector(fname,
foi)) ;
    }

}


When I run  "select id,  test(age) from test1" statement and use ResultSet
to receive result, hive throw below  exception:
Returning Thrift schema: Schema(fieldSchemas:[FieldSchema(name:id, type:i32,
comment:null), FieldSchema(name:_c1, type:list<struct<x:double,y:double>>,
comment:null)], properties:null)
2010-10-19 16:36:22,493 INFO  service.HiveServer
(HiveServer.java:getThriftSchema(213)) - Returning schema:
Schema(fieldSchemas:[FieldSchema(name:id, type:i32, comment:null),
FieldSchema(name:_c1, type:list<struct<x:double,y:double>>, comment:null)],
properties:null)
org.apache.hadoop.hive.serde2.dynamic_type.ParseException: Encountered
"struct" at line 1, column 29.
Was expecting one of:
    "bool" ...
    "i16" ...
    "i32" ...
    "i64" ...
    "double" ...
    "string" ...
    "map" ...
    "list" ...
    "set" ...
    <IDENTIFIER> ...

RE: I define one UDF function, the UDf retunr List ,but When I use ResultSet to receive result hive throw exception

Posted by "Howell, Nathan" <nh...@ebay.com>.
Try returning a non-empty string from getDisplayString, I've run across this issue before.

I use a helper class that looks similar to this Scala function:

override def getDisplayString (children: Array[String]): String =
  children.mkString("FunctionName(", ", ", ")")

From: Steven Wong [mailto:swong@netflix.com]
Sent: Tuesday, October 19, 2010 11:48 AM
To: user@hive.apache.org; hive-user@hadoop.apache.org
Subject: RE: I define one UDF function, the UDf retunr List ,but When I use ResultSet to receive result hive throw exception

Your Hive version is not latest trunk, right? I suspect the error is fixed in HIVE-1378 in trunk.


From: lei liu [mailto:liulei412@gmail.com]
Sent: Tuesday, October 19, 2010 1:41 AM
To: hive-user@hadoop.apache.org
Subject: I define one UDF function, the UDf retunr List ,but When I use ResultSet to receive result hive throw exception

I define one UDF function, like as below :
public class TestUDF extends GenericUDF{

    private ObjectInspector[] argumentOIs;

    @Override
    public Object evaluate(DeferredObject[] arguments) throws HiveException {
      ArrayList<DoubleWritable[]> result = new ArrayList<DoubleWritable[]>();
      DoubleWritable[] bin = new DoubleWritable[2];
      bin[0] = new DoubleWritable(0);
      bin[1] = new DoubleWritable(1);
      result.add(bin);
     return result;
    }

    @Override
    public String getDisplayString(String[] children) {
        // TODO Auto-generated method stub
        return "";
    }

    @Override
    public ObjectInspector initialize(ObjectInspector[] arguments)
            throws UDFArgumentException {
        argumentOIs = arguments;

        ArrayList<ObjectInspector> foi = new ArrayList<ObjectInspector>();
        foi.add(PrimitiveObjectInspectorFactory.writableDoubleObjectInspector);
        foi.add(PrimitiveObjectInspectorFactory.writableDoubleObjectInspector);
        ArrayList<String> fname = new ArrayList<String>();
        fname.add("x");
        fname.add("y");

        return ObjectInspectorFactory.getStandardListObjectInspector(ObjectInspectorFactory.getStandardStructObjectInspector(fname, foi)) ;
    }

}


When I run  "select id,  test(age) from test1" statement and use ResultSet to receive result, hive throw below  exception:
Returning Thrift schema: Schema(fieldSchemas:[FieldSchema(name:id, type:i32, comment:null), FieldSchema(name:_c1, type:list<struct<x:double,y:double>>, comment:null)], properties:null)
2010-10-19 16:36:22,493 INFO  service.HiveServer (HiveServer.java:getThriftSchema(213)) - Returning schema: Schema(fieldSchemas:[FieldSchema(name:id, type:i32, comment:null), FieldSchema(name:_c1, type:list<struct<x:double,y:double>>, comment:null)], properties:null)
org.apache.hadoop.hive.serde2.dynamic_type.ParseException: Encountered "struct" at line 1, column 29.
Was expecting one of:
    "bool" ...
    "i16" ...
    "i32" ...
    "i64" ...
    "double" ...
    "string" ...
    "map" ...
    "list" ...
    "set" ...
    <IDENTIFIER> ...

RE: I define one UDF function, the UDf retunr List ,but When I use ResultSet to receive result hive throw exception

Posted by Steven Wong <sw...@netflix.com>.
Your Hive version is not latest trunk, right? I suspect the error is fixed in HIVE-1378 in trunk.


From: lei liu [mailto:liulei412@gmail.com]
Sent: Tuesday, October 19, 2010 1:41 AM
To: hive-user@hadoop.apache.org
Subject: I define one UDF function, the UDf retunr List ,but When I use ResultSet to receive result hive throw exception

I define one UDF function, like as below :
public class TestUDF extends GenericUDF{

    private ObjectInspector[] argumentOIs;

    @Override
    public Object evaluate(DeferredObject[] arguments) throws HiveException {
      ArrayList<DoubleWritable[]> result = new ArrayList<DoubleWritable[]>();
      DoubleWritable[] bin = new DoubleWritable[2];
      bin[0] = new DoubleWritable(0);
      bin[1] = new DoubleWritable(1);
      result.add(bin);
     return result;
    }

    @Override
    public String getDisplayString(String[] children) {
        // TODO Auto-generated method stub
        return "";
    }

    @Override
    public ObjectInspector initialize(ObjectInspector[] arguments)
            throws UDFArgumentException {
        argumentOIs = arguments;

        ArrayList<ObjectInspector> foi = new ArrayList<ObjectInspector>();
        foi.add(PrimitiveObjectInspectorFactory.writableDoubleObjectInspector);
        foi.add(PrimitiveObjectInspectorFactory.writableDoubleObjectInspector);
        ArrayList<String> fname = new ArrayList<String>();
        fname.add("x");
        fname.add("y");

        return ObjectInspectorFactory.getStandardListObjectInspector(ObjectInspectorFactory.getStandardStructObjectInspector(fname, foi)) ;
    }

}


When I run  "select id,  test(age) from test1" statement and use ResultSet to receive result, hive throw below  exception:
Returning Thrift schema: Schema(fieldSchemas:[FieldSchema(name:id, type:i32, comment:null), FieldSchema(name:_c1, type:list<struct<x:double,y:double>>, comment:null)], properties:null)
2010-10-19 16:36:22,493 INFO  service.HiveServer (HiveServer.java:getThriftSchema(213)) - Returning schema: Schema(fieldSchemas:[FieldSchema(name:id, type:i32, comment:null), FieldSchema(name:_c1, type:list<struct<x:double,y:double>>, comment:null)], properties:null)
org.apache.hadoop.hive.serde2.dynamic_type.ParseException: Encountered "struct" at line 1, column 29.
Was expecting one of:
    "bool" ...
    "i16" ...
    "i32" ...
    "i64" ...
    "double" ...
    "string" ...
    "map" ...
    "list" ...
    "set" ...
    <IDENTIFIER> ...