hive sql跟mysql还是有点区别的。这里整理下一些自己常用的函数。
一、关系函数
匹配某列是否等于某值或列,比如A <> B。
函数 | 语法及含义 | 注意及举例 |
= | 等值比较 | 不要用于NULL |
<> | 不等 | 不要用于NULL |
< | 小于 | 不要用于NULL |
<= | 小于等于 | 不要用于NULL |
> | 大于 | 不要用于NULL |
>= | 大于等于 | 不要用于NULL |
IS NULL | 空值判断 | |
IS NOT NULL | 非空判断 | |
LIKE | 也可以 NOT LIKE | 不要用于NULL |
RLIKE/REGEXP | 正则匹配 | 不要用于NULL |
二、日期函数
Hive设置大量的日期处理
函数 |
含义 |
语法 |
返回结果例子 |
current_date |
当前日期 |
current_date() |
2019-07-31 |
current_timestamp |
当前时间,到秒 |
current_timestamp() |
2019-07-31 21:48:59.906 |
from_unixtime |
时间戳转日期字符串 |
from_unixtime(bigint unixtime[, string format]) |
|
unix_timestamp |
获取当前unix时间戳 |
unix_timestamp() |
1564580955 |
unix_timestamp |
字符串时间转时间戳 |
unix_timestamp(string date) |
"yyyy-MM-dd HH:mm:ss”格式 |
unix_timestamp |
字符串时间转时间戳 |
unix_timestamp(string date, string pattern) |
|
to_date |
返回日期时间字段中的日期部分 |
to_date(string timestamp) |
|
year |
日期中的年 |
year(string date) |
|
month |
日期中的月 |
month(string date) |
|
day |
日期中的天 |
day (string date) |
|
hour |
日期中的小时 |
hour (string date) |
|
minute |
日期中的分钟 |
minute (string date) |
|