我正在尝试将一些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,这是一个select
... into
语句,但我继续为Hive做了create table
... as select
答案 0 :(得分: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;