首页 > 其他 > 详细

关于hive hql时间函数如何使用

时间:2014-03-08 00:20:54      阅读:815      评论:0      收藏:0      [点我收藏+]

最近在搞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

关于hive hql时间函数如何使用

原文:http://lubing.blog.51cto.com/5293532/1369987

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!