[Hive_6] Hive 的内置函数应用
0. 說明
Hive 的內置函數的基本操作 | 時間函數 | String 函數 | 條件語句 | explode | split | substring?
?
1. 基本操作
查看函數
show functions;?
查看函數的用法
desc function function_name;?
查看函數的擴展信息
desc function extended format_name;?
?
?
2. 時間函數
?
select current_database() //當前數據庫 select current_date() //當前日期 select current_timestamp() //當前時間戳,精確到毫秒 select date_format( current_timestamp(), 'yyyy-MM-dd HH:mm:ss'); //將時間格式化 select unix_timestamp(current_timestamp()); //將日期轉換成時間戳,精確到秒 select from_unixtime(153361440000, 'yyyy-MM-dd'); //將時間戳轉化成日期 select datediff('2018-03-01','2018-02-01'); //計算兩個指定日期相差多少天?
?
?
3. String 函數
select split('hello world',' '); // 以空格進行切割成 Array 數組 select substr('hello world', 7); // 切割字符串 worldselect trim(' world'); //去掉前后的空格format_number() //select format_number(1234.345,2); => 1,234.35 //select format_number(1234.345,'000000.00'); => 001234.35 //select format_number(1234.345,'########.##'); => 1234.35select concat('hello', ' world'); // 拼串操作,返回 hello worldselect length('helloworld'); // 10?
?
?
4. 條件語句
4.1 if
select if( age > 10 ,'old', 'young') from user_par; // 相當于三元運算符。
// 第一個表達式成立返回第二個表達式
// 第一個不成立返回第三個表達式
?
4.2 case
select case when age<20 then 'young' when age<40 then 'middle' else 'old' end from user_par; // 小于20,返回 young
// 小于40,返回 middle
// 否則,返回 old
?
?5.?explode
5.1 描述
separates the elements of array a into multiple rows
or the elements of a map into multiple rows and columns
分裂 array 數組的中的元素變成多行
或者分裂 map 中的元素變成多行和多列
是一個表生成函數
5.2 使用方法
explode(array)
?
?
?
6.?split
6.1 描述
Splits str around occurances that match regex
拆分與正則表達式匹配的事件
?
6.2 使用方法
split(str, regex)
?
?
7. substr
7.1 描述
截取從指定位置開始指定長度的的字符串
默認從第一位開始截取
?
7.2 使用方法
substr(str, pos[, len])
?
?
?
?
轉載于:https://www.cnblogs.com/share23/p/10223898.html
總結
以上是生活随笔為你收集整理的[Hive_6] Hive 的内置函数应用的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Linux系统故障修复-MBR损坏,gr
- 下一篇: Hello World!