Skip to content

Instantly share code, notes, and snippets.

@yssharma
Last active June 22, 2018 07:36
Show Gist options
  • Select an option

  • Save yssharma/4368970 to your computer and use it in GitHub Desktop.

Select an option

Save yssharma/4368970 to your computer and use it in GitHub Desktop.
Hive Auto increment UDF
package com.confusedcoders.hive.udf;
import org.apache.hadoop.hive.ql.exec.UDF;
public class AutoIncrUdf extends UDF{
int lastValue;
public int evaluate() {
lastValue++;
return lastValue;
}
}
@ranp
Copy link
Copy Markdown

ranp commented Jun 26, 2013

This did not work for me until I added a class annotation:
@UDFType(stateful = true)
public class AutoIncrUdf extends UDF {
...
}

@ysrotciv
Copy link
Copy Markdown

This did not work for me even I add the class annotation:
@UDFType(stateful = true)

@senprasenjit
Copy link
Copy Markdown

Also in addition to "statefull=true" you need to set mapper=1 , otherqise the desired output will not come.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment