udf 操作用於單個資料行, 且產生乙個資料行作為資料行作為輸出。方法:
package org.saligia;
import org.apache.hadoop.hive.ql.exec.udf;
import org.apache.hadoop.io.text;
public
class
parseint
extends
udfcatch(numberformatexception e)
return value;
}}
hive> add
jar /home/saligia/tmp/parseint.jar;
added [/home/saligia
/tmp/
parseint.jar] to class
path
added
resources: [/home/saligia
/tmp/
parseint.jar]
hive> create temporary function parseint as
'org.saligia.parseint';
oktime taken: 0.072 seconds
hive> select parseint(id),parseint(context) from one;
ok1 -1
2 -1
3 -1
5 -1
6 -1
udaf 接受多個輸入資料行, 且產生乙個輸出行。方法:
udaf 通過定義乙個 udaf 方法來實現
package org.saligia;
import org.apache.hadoop.hive.ql.exec.udaf;
import org.apache.hadoop.hive.ql.exec.udafevaluator;
import org.apache.hadoop.io.intwritable;
public
class
maxget
extends
udaf
public
boolean
iterate(intwritable value)
if(res == null)else
return
true;
}public
boolean
merge(intwritable other)
public intwritable terminatepartial()
public intwritable terminate()
}}
必須實現的方法:
public
void
init();
pubilc boolean iterate(t);
public
boolean
merge(t);
public t terminate();
public t terminatepartial();
hive> add
jar /home/saligia/tmp/udaftest.jar;
added [/home/saligia
/tmp/
udaftest.jar] to class
path
added
resources: [/home/saligia
/tmp/
udaftest.jar]
hive> create
temporary
function mysum as
'org.saligia.maxget';
ok
hive> select mysum(id) from one;
hive自定義函式
1.建立類,繼承udf package com.hivedemo.udf import org.apache.hadoop.hive.ql.exec.description import org.apache.hadoop.hive.ql.exec.udf 自定義hive函式 description...
Hive 自定義函式
返回 所有自帶的函式 show functions 返回對該函式的解釋 desc function spilt 返回對該函式的使用例子 desc function extended split1.udf user defined function datediff,date format 等函式 一...
Hive 自定義函式
hive 支援自定義udf,udtf,udaf函式 以自定義udf為例 使用乙個名為evaluate的方法 package com.hive.custom import org.apache.hadoop.hive.ql.exec.udf import org.apache.hadoop.io.in...