2015-06-20 29 views
0

我有两个Hive表,其中一个包含Timestamp数据类型的日期值。如果我使用该键在一个特定记录上查询,它会正确显示日期值。 从表1中选择acct_key,account_open_date,其中acct_key = 1234;加入两个表后的Hive时间戳值更改

acct_id account_open_date 
1234  1963-03-01 00:00:00 

但是与另一个表加入这个表时,返回的时间戳值2031 选择a.acct_key,b.account_open_date 从TABLE_2换到价值在一年TABLE_1左外JOIN B 上。 acct_key = b.acct_key;

acct_id account_open_date 
1234  2031-03-19 00:00:00 

似乎这个问题只发生在Unix纪元时间(1970年)之前的日期值。任何建议?谢谢

回答

0

这里有两个问题,第一件事加入不与时间戳和时代时间戳工作。用你的最后一行,我假设连接正在为其他时间戳返回正确的时间戳。纠正我,如果我错了。因此,如果这是解决了,你可以看看here处理划时代时间

0

我无法重现您所看到的,但仍然,你可以尝试铸造account_open_datestring

select a.acct_id 
    , b.new 
    , other_columns 
from db.table1 
left outer join (
    select * 
    , cast(account_open_date as string) new 
    from db.table2) b 
on a.acct_id=b.acct_id 
+0

感谢您的建议。想知道不是使用嵌套查询,我可以直接将其转换为如下所示的字符串。这两者有什么区别?选择a.acct_id ,cast(b.account_open_date as字符串)新的 ,other_columns from db.table1 a, left outer join db.table 2 b on a.acct_id = b.acct_id; –

+0

如上所述,我无法重现您所看到的内容,但我在'join'期间以某种方式假设时间戳列被更改。所以我做了'cast'然后'join'。如果这是你所担心的,我认为不会有太大的性能差异。 – gobrewers14

0

我试过了。在嵌套查询中将时间戳记投射为String,其工作方式如下。我也试过没有嵌套查询,但那不起作用。有人知道为什么

没有工作版本:

选择a.acct_id,浇铸(b.account_open_date作为字符串)新,从db.table1一个other_columns,左外连接db.table 2 B上a.acct_id = b.acct_id ;

工作版本:

选择a.acct_id ,b.new ,other_columns 从db.table1 左外连接( 选择* ,投(account_open_date作为字符串)新 从db.table2 )b on a.acct_id = b.acct_id