You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@hive.apache.org by "navanee (JIRA)" <ji...@apache.org> on 2014/05/28 11:41:01 UTC

[jira] [Commented] (HIVE-7132) Hive 0.11.0 Custom UDTF doesnt call close method

    [ https://issues.apache.org/jira/browse/HIVE-7132?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14010962#comment-14010962 ] 

navanee commented on HIVE-7132:
-------------------------------

One More Simple Example,

import java.util.ArrayList;
 
import org.apache.hadoop.hive.ql.exec.UDFArgumentException;
import org.apache.hadoop.hive.ql.metadata.HiveException;
import org.apache.hadoop.hive.ql.udf.generic.GenericUDTF;
import org.apache.hadoop.hive.serde2.objectinspector.ObjectInspector;
import org.apache.hadoop.hive.serde2.objectinspector.ObjectInspectorFactory;
import org.apache.hadoop.hive.serde2.objectinspector.StructObjectInspector;
import org.apache.hadoop.hive.serde2.objectinspector.primitive.PrimitiveObjectInspectorFactory;
 
 
/**
 * GenericUDTFCount2 outputs the number of rows seen, twice. It's output twice
 * to test outputting of rows on close with lateral view.
 *
 */
public class GenericUDTFCount2 extends GenericUDTF {
 
  Integer count = Integer.valueOf(0);
  Object forwardObj[] = new Object[1];
 
  @Override
  public void close() throws HiveException {
    forwardObj[0] = count;
    forward(forwardObj);
    forward(forwardObj);
  }
 
  @Override
  public StructObjectInspector initialize(ObjectInspector[] argOIs) throws UDFArgumentException {
    ArrayList<String> fieldNames = new ArrayList<String>();
    ArrayList<ObjectInspector> fieldOIs = new ArrayList<ObjectInspector>();
    fieldNames.add("col1");
    fieldOIs.add(PrimitiveObjectInspectorFactory.javaIntObjectInspector);
    return ObjectInspectorFactory.getStandardStructObjectInspector(fieldNames,
        fieldOIs);
  }
 
  @Override
  public void process(Object[] args) throws HiveException {
    count = Integer.valueOf(count.intValue() + 1);
  }

> Hive 0.11.0 Custom UDTF doesnt call close method
> ------------------------------------------------
>
>                 Key: HIVE-7132
>                 URL: https://issues.apache.org/jira/browse/HIVE-7132
>             Project: Hive
>          Issue Type: Bug
>          Components: Query Processor
>    Affects Versions: 0.11.0
>         Environment: shark 0.9.1,hive 0.11.0
>            Reporter: navanee
>
> In My Custom UDTF, Process method collects all row info and store them in array list, 
> and in close method, i will try to forward the array list.
> But some how ,my close method didnt get called while executing custom UDTF, getting empty as result.
> private PrimitiveObjectInspector[] inputOIs; // input ObjectInspectors
> private List<Set<Object>> distincts = new ArrayList<Set<Object>>();
>  @Override
>   public void process(Object[] arg0) throws HiveException {
>     for (int i = 0; i < arg0.length; i++) {
>         String value =  inputOIs[i].getPrimitiveJavaObject(arg0[i]).toString();
>         distincts.get(i).add(value);
>    }
> }
> @Override
>   public void close() throws HiveException {
>      forward(new Object[]{distincts});
>  }
>   @Override
>   public StructObjectInspector initialize(ObjectInspector[] arg0) throws UDFArgumentException {
>     inputOIs=new PrimitiveObjectInspector[arg0.length]; 
>     List<String> _fields = new ArrayList<String>();
>     List<ObjectInspector> fieldOIs = new ArrayList<ObjectInspector>();
>   for (int i = 0; i < arg0.length; i++) {
>       inputOIs[i]=(PrimitiveObjectInspector) arg0[i];
>       distincts.add(new HashSet<Object>());
>       _fields.add(new Integer(i).toString());
>         fieldOIs.add(PrimitiveObjectInspectorFactory.javaStringObjectInspector);
>     }
>     return ObjectInspectorFactory.getStandardStructObjectInspector(_fields, fieldOIs);
>   }
> I tried the same code in hive 0.12, its working perfectly. But i am using shark 0.9.1, supports only hive 0.11.
> Please help me on the issue



--
This message was sent by Atlassian JIRA
(v6.2#6252)