hive用户自定义函数
2011-08-02 17:01
218 查看
--查看系统自带函数
hive> show functions;
OK
!
!=
%
&
*
+
-
/
<
<=
<>
=
==
>
>=
^
abs
acos
and
array
array_contains
ascii
asin
atan
avg
bigint
bin
boolean
case
ceil
ceiling
coalesce
collect_set
concat
concat_ws
context_ngrams
conv
corr
cos
count
covar_pop
covar_samp
create_union
date_add
date_sub
datediff
day
dayofmonth
degrees
div
double
e
elt
exp
explode
field
find_in_set
float
floor
from_unixtime
get_json_object
hash
hex
histogram_numeric
hour
if
in
index
instr
int
isnotnull
isnull
json_tuple
lcase
length
like
ln
locate
log
log10
log2
lower
lpad
ltrim
map
max
min
minute
month
negative
ngrams
not
or
parse_url
parse_url_tuple
percentile
percentile_approx
pi
pmod
positive
pow
power
radians
rand
reflect
regexp
regexp_extract
regexp_replace
repeat
reverse
rlike
round
rpad
rtrim
second
sentences
sign
sin
size
smallint
space
split
sqrt
std
stddev
stddev_pop
stddev_samp
str_to_map
string
struct
substr
substring
sum
tan
tinyint
to_date
trim
ucase
unhex
unix_timestamp
upper
var_pop
var_samp
variance
weekofyear
when
xpath
xpath_boolean
xpath_double
xpath_float
xpath_int
xpath_long
xpath_number
xpath_short
xpath_string
year
|
~
Time taken: 0.134 seconds
--查看函数描述信息
hive> describe function abs;
OK
abs(x) - returns the absolute value of x
Time taken: 0.214 seconds
hive> describe function substring;
OK
substring(str, pos[, len]) - returns the substring of str that starts at pos and is of length len
Time taken: 0.084 seconds
package com.lpxuan.hive.udf;
import org.apache.hadoop.hive.ql.exec.UDF;
import org.apache.hadoop.io.Text;
public class CompanyLength extends UDF{
public int getCompanyLength(String company_name){
if(company_name == null) {
return -1;
}
else return company_name.length();
}
}
lpxuan@hadoop1:~/mycode/com/lpxuan/hive/udf$ javac CompanyLength.java
lpxuan@hadoop1:~/mycode/com/lpxuan/hive/udf$ ls
CompanyLength.class CompanyLength.java
lpxuan@hadoop1:~/mycode/com/lpxuan/hive/udf$ jar cvf CompanyLength.jar CompanyLength.class
标明清单(manifest)
增加:CompanyLength.class(读入= 392) (写出= 277)(压缩了 29%)
lpxuan@hadoop1:~/mycode/com/lpxuan/hive/udf$ ls
CompanyLength.class CompanyLength.jar CompanyLength.java
root@hadoop1:/home/lpxuan/mycode/com/lpxuan/hive/udf# mv CompanyLength.jar /opt/hadoop/mytest/
hive> add jar /opt/hadoop/mytest/CompanyLength.jar
/hadoop/mytest/CompanyLength.jar to class path
Added resource: /opt/hadoop/mytest/CompanyLength.jar
create temporary function company_length as 'com.lpxuan.hive.udf.CompanyLength.getCompanyLength';
hive> show functions;
OK
!
!=
%
&
*
+
-
/
<
<=
<>
=
==
>
>=
^
abs
acos
and
array
array_contains
ascii
asin
atan
avg
bigint
bin
boolean
case
ceil
ceiling
coalesce
collect_set
concat
concat_ws
context_ngrams
conv
corr
cos
count
covar_pop
covar_samp
create_union
date_add
date_sub
datediff
day
dayofmonth
degrees
div
double
e
elt
exp
explode
field
find_in_set
float
floor
from_unixtime
get_json_object
hash
hex
histogram_numeric
hour
if
in
index
instr
int
isnotnull
isnull
json_tuple
lcase
length
like
ln
locate
log
log10
log2
lower
lpad
ltrim
map
max
min
minute
month
negative
ngrams
not
or
parse_url
parse_url_tuple
percentile
percentile_approx
pi
pmod
positive
pow
power
radians
rand
reflect
regexp
regexp_extract
regexp_replace
repeat
reverse
rlike
round
rpad
rtrim
second
sentences
sign
sin
size
smallint
space
split
sqrt
std
stddev
stddev_pop
stddev_samp
str_to_map
string
struct
substr
substring
sum
tan
tinyint
to_date
trim
ucase
unhex
unix_timestamp
upper
var_pop
var_samp
variance
weekofyear
when
xpath
xpath_boolean
xpath_double
xpath_float
xpath_int
xpath_long
xpath_number
xpath_short
xpath_string
year
|
~
Time taken: 0.134 seconds
--查看函数描述信息
hive> describe function abs;
OK
abs(x) - returns the absolute value of x
Time taken: 0.214 seconds
hive> describe function substring;
OK
substring(str, pos[, len]) - returns the substring of str that starts at pos and is of length len
Time taken: 0.084 seconds
package com.lpxuan.hive.udf;
import org.apache.hadoop.hive.ql.exec.UDF;
import org.apache.hadoop.io.Text;
public class CompanyLength extends UDF{
public int getCompanyLength(String company_name){
if(company_name == null) {
return -1;
}
else return company_name.length();
}
}
lpxuan@hadoop1:~/mycode/com/lpxuan/hive/udf$ javac CompanyLength.java
lpxuan@hadoop1:~/mycode/com/lpxuan/hive/udf$ ls
CompanyLength.class CompanyLength.java
lpxuan@hadoop1:~/mycode/com/lpxuan/hive/udf$ jar cvf CompanyLength.jar CompanyLength.class
标明清单(manifest)
增加:CompanyLength.class(读入= 392) (写出= 277)(压缩了 29%)
lpxuan@hadoop1:~/mycode/com/lpxuan/hive/udf$ ls
CompanyLength.class CompanyLength.jar CompanyLength.java
root@hadoop1:/home/lpxuan/mycode/com/lpxuan/hive/udf# mv CompanyLength.jar /opt/hadoop/mytest/
hive> add jar /opt/hadoop/mytest/CompanyLength.jar
/hadoop/mytest/CompanyLength.jar to class path
Added resource: /opt/hadoop/mytest/CompanyLength.jar
create temporary function company_length as 'com.lpxuan.hive.udf.CompanyLength.getCompanyLength';
相关文章推荐
- hive用户自定义函数
- Hive中的用户自定义函数UDF
- Hive 文件格式 & Hive操作(外部表、内部表、区、桶、视图、索引、join用法、内置操作符与函数、复合类型、用户自定义函数UDF、查询优化和权限控制)
- Hive 之 用户自定义函数 UDF UDAF UDTF
- Hive 用户自定义函数 UDF,UDAF
- HIVE 用户自定义函数(UDF)
- 一个很简单的用户自定义函数!
- [一起学Hive]之二十-自定义HiveServer2的用户安全认证
- Loadrunner 用户自定义函数使用
- hdfs,hive,yarn,hbase基于系统用户的安全管理
- SQL Server--用户自定义函数
- CDH hue用户权限管理,给用户hive权限
- hadoop+hive多用户访问支持
- MS SQL入门基础:用户自定义函数
- hive对电商用户订单行为特征分析(二)
- hive超级用户drop partition无权限问题bug 推荐
- SQL Server--用户自定义函数
- mssql用户自定义函数
- 存储过程与用户自定义函数的区别
- Aerospike实战之UDF(用户自定义函数)