提问人:Hack-R 提问时间:3/15/2016 更新时间:3/15/2016 访问量:1521
使用 Hive 将 date 转换为 int
Convert date to int with Hive
问:
我正在尝试将一些T-SQL移植到Hive SQL,但遇到以下语句的问题:
create table param as
select convert( int, CONVERT( char(8), convert( date, begin_date ), 112 ) ) as begin_dtkey
, convert( int, CONVERT( char(8), convert( date, end_date ), 112 ) ) as end_dtkey
, convert( int, CONVERT( char(8), convert( date, cutoff_date ), 112 ) ) as cutoff_dtkey
, *
from tmp_param;
这个想法是将日期转换为它们的整数格式。有没有办法在 Hive (v0.13) 中做到这一点?
在 T-SQL 的情况下,这是一个 ...声明,但我继续做了......对于 Hive。select
into
create table
as select
答:
1赞
Gordon Linoff
3/15/2016
#1
可能最简单的方法(并且应该在两个数据库中都有效)是使用日期部分提取函数:
select (year(begin_date) * 10000 + month(begin_date) * 100 + day(begin_date)) as begin_dtkey,
(year(end_date) * 10000 + month(end_date) * 100 + day(end_date)) as end_dtkey,
(year(cutoff_date) * 10000 + month(cutoff_date) * 100 + day(cutoff_date)) as cutoff_dtkey,
p.*
from tmp_param p;
评论