string concat_ws(string SEP, string A, string B...)
hive> select * from student;
Jack male 50
Lily female 18
Alice female 20
hive> select concat_ws(',', name, sex, age) from student;
Jack,male,50
Lily,female,18
Alice,female,20
日期函数
Return type | Function | Example |
---|---|---|
date | current_date | 2020-03-26 |
timestamp | current_timestamp | 2020-03-26 16:06:13.914 |
string | date_format(date/timestamp/string ts, string fmt) | date_format(current_date,‘yyyy-MM-dd’) -> 2020-03-26 date_format(current_timestamp,‘yyyyMMdd’) -> 20200326 |
bigint | unix_timestamp() | 1585210047 |
bigint | unix_timestamp(string date) | unix_timestamp(‘1992-05-06 01:00:00’) -> 705085200 |
bigint | unix_timestamp(string date, string pattern) | unix_timestamp(‘19920506 01:00:00’,‘yyyyMMdd HH:mm:ss’) -> 705085200 |
string | from_unixtime(bigint unixtime[, string format]) | from_unixtime(705085200) -> 1992-05-06 01:00:00 |
分析函数
ROW_NUMBER() OVER(PARTITION BY column_name_1 ORDER BY column_name_2) new_column
新增一列new_column
,以column_name_1
为分区,根据column_name_2
排序,计算行数填充到new_column
中。
例子:
id name sex age
1 孙悟空 男 100
2 明世隐 男 101
3 高渐离 男 102
4 孙尚香 女 103
5 安琪拉 女 104
hive> SELECT *,ROW_NUMBER() OVER(PARTITION BY sex ORDER BY age) rn FROM student;
id name sex age rn
4 孙尚香 女 103 1
5 安琪拉 女 104 2
1 孙悟空 男 100 1
2 明世隐 男 101 2
3 高渐离 男 102 3