java - Getting ClassCastException while developing UDTF in Hive -
i getting issue classcastexception while developing udtf in hive.
here details :
- i trying implement loop kind of functionality can pass 3 parameters for_each(start,stop,increment).
- if pass parameters values for_each(1 , 10 , 1) works fine.
- 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:
- store input inspectors in instances variables in
initializemethod. can check types expect, won'twritableconstantintobjectinspector. should subclasses ofprimitiveobjectinspector, if callgetprimitivecategorymethod, shouldprimtivecategory.int. - use stored input inspectors retrieve data in objects passed in
processmethod. example,integer n = (integer)inspector.getprimitivejavaobject(args[0])
Comments
Post a Comment