最近在搞oozie,通过oozie 定时调度hive hql来取数据和插入数据,其中有一个问题就是时间,如:取当前系统时间或系统日期。经过查询函数使用如下:
select from_unixtime(unix_timestamp()) from dual; (dual 表需要简单创建,然后可以往里插入一条数据)
最后返回
OK
2014-03-07 17:57:30
Time taken: 20.455 seconds, Fetched: 1 row(s)
select to_date(from_unixtime(unix_timestamp())) from dual
返回:
OK
2014-03-07
Time taken: 14.736 seconds, Fetched: 1 row(s)
如果要取前一天的日期
select date_sub(to_date(from_unixtime(unix_timestamp())),1) from dual;
返回:
OK
2014-03-06
Time taken: 14.502 seconds, Fetched: 1 row(s)
如果要取当前系统日期值,只需要直接使用date_sub(to_date(from_unixtime(unix_timestamp())),1)函数就行,如:
insert into table assessment_total_visits select count(*),date_sub(to_date(from_unixtime(unix_timestamp())),1) from structuredlognew where website=‘assess.tms.beisen.com‘ and time =date_sub(to_date(from_unixtime(unix_timestamp())),1);
但是hive里直接给时间设置变量好像行不通。
如 date = $(date +%Y-%m-%d=%H:%M) 这种方式
关于hive hql时间函数如何使用,布布扣,bubuko.com
原文:http://lubing.blog.51cto.com/5293532/1369987