java - Getting ClassCastException while developing UDTF in Hive -


i getting issue classcastexception while developing udtf in hive.

here details :

  1. i trying implement loop kind of functionality can pass 3 parameters for_each(start,stop,increment).
  2. if pass parameters values for_each(1 , 10 , 1) works fine.
  3. whereas, stop value parameter trying pass result of 1 of udf function (eg. stopvlaue() value for_each(1 , stopvalue() , 1). stopo dovalue() function returns me intwritable. when try getting below exception : "classcastexception org.apache.hadoop.hive.serde2.objectinspector.primitive.writableintobjectinspector cannot cast org.apache.hadoop.hive.serde2.objectinspector.primitive.writableconstantintobjectinspector"

here udtf:

public class generateseries extends genericudtf {     intwritable start;     intwritable end;     intwritable inc;     object[] forwardobj = null;        @override     public structobjectinspector initialize(objectinspector[] args) throws udfargumentexception      {          start=((writableconstantintobjectinspector) args[0]).getwritableconstantvalue();         end=((writableconstantintobjectinspector) args[1]).getwritableconstantvalue();         if (args.length == 3)          {             inc =((writableconstantintobjectinspector) args[2]).getwritableconstantvalue();         } else {             inc = new intwritable(1);         }         this.forwardobj = new object[1];         arraylist<string> fieldnames = new arraylist<string>();         arraylist<objectinspector> fieldois = new arraylist<objectinspector>();         fieldnames.add("col0");         fieldois.add(primitiveobjectinspectorfactory.getprimitivejavaobjectinspector(primitivecategory.int));         return objectinspectorfactory.getstandardstructobjectinspector(fieldnames, fieldois);     }     @override     public void process(object[] args) throws hiveexception, udfargumentexception      {         (int = start.get(); < end.get(); = + inc.get())          {             this.forwardobj[0] = new integer(i);             forward(forwardobj);         }     }      @override     public void close() throws hiveexception {         // todo auto-generated method stub      } } 

any idea how can resolve issue?

thanks in advance

the initialize method, in cases, not give actual value of input function, can different different rows. tells types of input. actual values can consistently accessed process method. you're taking advantage of 1 notable exception, constants. general pattern should follow instead is:

  1. store input inspectors in instances variables in initialize method. can check types expect, won't writableconstantintobjectinspector. should subclasses of primitiveobjectinspector , if call getprimitivecategory method, should primtivecategory.int.
  2. use stored input inspectors retrieve data in objects passed in process method. example, integer n = (integer)inspector.getprimitivejavaobject(args[0])

Comments

Popular posts from this blog

c++ - CryptStringToBinary API behavior -

java.util.scanner - How to read and add only numbers to array from a text file -

iphone - Three second countdown in cocos2d -