Hive内置函数地址
https://cwiki.apache.org/confluence/display/Hive/LanguageManual+UDF
日期函数
Hive 中支持以下内置日期函数:
返回类型 | 名称 | 描述 |
---|---|---|
字符串 | from_unixtime(bigint unixtime[, string format]) | 将 unix 纪元 (1970-01-01 00:00:00 UTC) 中的秒数转换为表示当前系统时区中该时刻的时间戳的字符串(使用配置"hive.local.time.zone"),格式为"uuuu-MM-dd HH:mm:ss" 示例"1970-01-01 00:00:00"。在 Hive 4.0.0 (HIVE-25458) 之前,它使用 [https://docs.oracle.com/javase/7/docs/api/java/text/SimpleDateFormat.html],因此支持的格式已更改。 |
bigint | unix_timestamp() | 获取当前 Unix 时间戳(以秒为单位)。此函数不是确定性的,并且其值对于查询执行的范围不是固定的,因此会阻止对查询进行适当的优化 - 自 2.0 以来已弃用,取而代之的是CURRENT_TIMESTAMP常量。 |
bigint | unix_timestamp(字符串日期) | 使用默认时区和默认区域设置(即(使用配置"hive.local.time.zone")通过 [https://docs.oracle.com/javase/8/docs/api/java/time/format/DateTimeFormatter.html] 将格式的时间字符串转换为 Unix 时间戳(以秒为单位),如果失败,则返回 0:unix_timestamp(‘2009-03-20 11:30:01’) = 1237573801uuuu-MM-dd HH:mm:ss 在 Hive 4.0.0 (HIVE-25458) 之前,它使用 [https://docs.oracle.com/javase/7/docs/api/java/text/SimpleDateFormat.html],因此引用的字符串格式为yyyy-MM-dd HH:mm:ss. |
bigint | unix_timestamp(字符串日期、字符串模式) | 将具有给定模式的时间字符串(参见 [https://docs.oracle.com/javase/8/docs/api/java/time/format/DateTimeFormatter.html])转换为 Unix 时间戳(以秒为单位),如果失败,则返回 0:unix_timestamp(‘2009-03-20’, ‘uuuu-MM-dd’) = 1237532400。在 Hive 4.0.0 (HIVE-25458) 之前,它使用 [https://docs.oracle.com/javase/7/docs/api/java/text/SimpleDateFormat.html],因此支持的模式已更改。 |
2.1.0 之前:字符串2.1.0 后: 日期 | to_date(字符串时间戳) | 返回时间戳字符串(Hive 2.1.0 之前)的日期部分:to_date(“1970-01-01 00:00:00”) = “1970-01-01”。从 Hive 2.1.0 开始,返回一个日期对象。在 Hive 2.1.0 (HIVE-13248) 之前,返回类型为 String,因为在创建该方法时不存在 Date 类型。 |
int | year(string date) | 返回日期或时间戳字符串的年份部分:year(“1970-01-01 00:00:00”) = 1970,year(“1970-01-01”) = 1970。 |
int | quarter(date/timestamp/string) | 返回日期、时间戳或字符串的一年中季度,范围为 1 到 4(从 Hive 1.3.0 开始)。示例:季度(‘2015-04-08’) = 2。 |
int | month(string date) | 返回日期或时间戳字符串的月份部分:month(“1970-11-01 00:00:00”) = 11, month(“1970-11-01”) = 11。 |
int | day(string date) dayofmonth(date) | 返回日期或时间戳字符串的 day 部分:day(“1970-11-01 00:00:00”) = 1,day(“1970-11-01”) = 1。 |
int | hour(string date) | 返回时间戳的小时:小时(‘2009-07-30 12:58:59’) = 12,小时(‘12:58:59’) = 12。 |
int | minute(string date) | 返回时间戳的分钟数。 |
int | second(string date) | 返回时间戳的第二个。 |
int | weekofyear(string date) | 返回时间戳字符串的周数:weekofyear(“1970-11-01 00:00:00”) = 44,weekofyear(“1970-11-01”) = 44。 |
int | extract(field FROM source) | 从源中检索天数或小时等字段(从 Hive |