hive常用函式

2021-10-12 18:19:03 字數 1106 閱讀 5154

一、型別

(1)udf(user-defined-function)

一進一出 select upper(「dd」) from emp;

(2)udaf(user-defined aggregation function)

聚集函式,多進一出

類似於:count/max/min

(3)udtf(user-defined table-generating functions)

一進多出

二、常用函式

(1)檢視

1.檢視系統自帶的函式

hive> show functions;

2.顯示自帶的函式的用法

hive> desc function upper;
3.詳細顯示自帶的函式的用法
hive> desc function extended upper;
(2)使用

1、轉大小寫

lcase(「abc」) abc

ucase(「abc」) abc

2、擷取

substr(「hello」,2) ello

substr(「helllo」,-2) lo

substr(「hello」,2,3) ell

(第乙個數字代表開始擷取的位置,第二個數字代表街擷取的位數)

3、絕對值

abs(-1) 1

4、切割

select split(「a|b|c」,』\|』); \轉義

結果:[「a」,「b」,「c」]

5、合併

concat(「a」,「b」) ab

concat_ws(』|』,「a」,「b」) a|b

6、collect_set( ) 結果放在陣列裡面,陣列中的元素是去過重的

例項:行轉列

concat_ws(』|』,collect_set(t.name)

列轉行:

lateral view explode (category) temptable as cate ;

Hive常用函式

if判斷 select if 1 1,yes no 返回yes 語法 case expression when condition1 then result1 when condition2 then result2 else result end 例子 case a when 1 then one...

hive常用函式

hive常用函式 1 檢視函式用法 desc function 函式名 desc function extended 函式名 2 獲取array陣列長度 size函式 select size collect list field from table select size split hello ...

Hive常用函式

常用日期函式 unix timestamp 返回當前或指定時間的時間戳 from unixtime 將時間戳轉為日期格式 current date 當前日期 current timestamp 當前的日期加時間 to date 抽取日期部分 year 獲取年 month 獲取月 day 獲取日 ho...