连接两个表后hive timestamp值更改

bbmckpt7  于 2021-05-30  发布在  Hadoop
关注(0)|答案(3)|浏览(316)

我有两个配置单元表,一个保存一个带有timestamp数据类型的日期值。如果我使用键查询一个特定的记录,它会正确地显示日期值。从表1中选择科目关键字、开户日期,其中科目关键字=1234;

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

但是,当将此表与另一个表联接时,返回的时间戳值在2031年更改为某个值选择a.acct\ u key,b.account\ u open\ u date from table\ u 2 a left outer join on table\ u 1 b on a.acct\ u key=b.acct\ u key;

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

似乎这个问题只发生在unix epoch time(1970)之前的日期值。有什么建议吗?谢谢

cngwdvgl

cngwdvgl1#

我无法重现你所看到的,但你可以尝试铸造 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
dgjrabp2

dgjrabp22#

这里有两个问题,第一个是join不使用timestamp和epoch timestamp。在最后一行中,我假设join为其他时间戳返回了正确的时间戳。如果我错了,请纠正我。如果这个问题解决了,你可以看看这里来处理划时代的时间

ldioqlga

ldioqlga3#

我试过了。在嵌套查询中将时间戳转换为字符串,如下所示。我也尝试过不使用嵌套查询,但不起作用。有人知道为什么吗?
未工作版本:

SELECT 
   a.acct_id
  ,CAST(b.account_open_date AS STRING) new
  ,other_columns 
FROM 
  db.table1 a, 
  LEFT OUTER JOIN db.table2 b ON (a.acct_id = b.acct_id)
;

工作版本:

SELECT 
     a.acct_id
    ,b.new
    ,other_columns
FROM 
    db.table1 a
    LEFT OUTER JOIN (
        SELECT 
           *
          ,CAST(account_open_date AS STRING) new
       FROM 
          db.table2
    ) b
       ON (a.acct_id=b.acct_id)

相关问题