hive 查詢函式並檢視函式使用方法
阿新 • • 發佈:2019-01-05
我們在使用hive函式時經常會出現對函式名、引數使用及返回值等記憶模糊,然後需要到網上各種查詢資料。
今天來教大家一種使用hive命令模糊查詢相關函式名稱、函式的用法及詳細說明並舉例,較少大家查詢資料的時間,提高效率。
1.檢視date相關的函式
show functions like '*date*';
OK
current_date
date_add
date_format
date_sub
datediff
to_date
2.檢視datediff函式的用法
desc function datediff;
OK
datediff(date1, date2) - Returns the number of days between date1 and date2
Time taken: 0.03 seconds, Fetched: 1 row(s)
3.檢視datediff函式的詳細說明並舉例
desc function extended datediff;
OK
datediff(date1, date2) - Returns the number of days between date1 and date2
date1 and date2 are strings in the format 'yyyy-MM-dd HH:mm:ss' or 'yyyy-MM-dd'. The time parts are ignored.If date1 is earlier than date2, the result is negative.
Example:
> SELECT datediff('2009-07-30', '2009-07-31') FROM src LIMIT 1;
1
Function class:org.apache.hadoop.hive.ql.udf.generic.GenericUDFDateDiff
Function type:BUILTIN
Time taken: 0.015 seconds, Fetched: 7 row(s)
4.測試
select datediff('2018-12-25', '2018-12-26');
OK
-1
Time taken: 0.128 seconds, Fetched: 1 row(s)