1.导入Eclipse编码jar包
hadoop-auth-2.4.0.2.1.3.0-563.jar
hadoop-common-2.4.0.2.1.3.0-563.jar
hive-exec-0.13.0.2.1.3.0-563.jar
2.代码
[mw_shl_code=java,true]import org.apache.hadoop.hive.ql.exec.Description;
import org.apache.hadoop.hive.ql.exec.UDF;
import org.apache.hadoop.hive.ql.udf.UDFType;
import org.apache.hadoop.io.LongWritable;
/*
* UDF RowSequence
*/
@Description(name = "auto_sequence",
value = "_FUNC_() - Returns a generated row sequence number starting from 1")
@UDFType(deterministic = false)
public class RowSequence extends UDF {
private LongWritable result = new LongWritable();
public RowSequence(){
result.set(0);
}
public LongWritable evaluate(){
result.set(result.get() + 1);
return result;
}
}[/mw_shl_code]
3.将jar包导出上传到hive上运行
(1)从Eclipse导出jarbao
spacer.gif
(2)将autoSequence.jar放到/usr/lib/hive/lib
hive
add jar /usr/lib/hive/lib/autoSequence.jar;
create temporary function auto_sequence as 'com.redhadoop.autosequence.RowSequence';
select auto_sequence(),uname from tb_user
|
|