当我从字符串转换时,timestamp被插入为null

时间:2017-09-27 10:53:24

标签: hive

我有2张桌子

CREATE TABLE table1(
ctn string
, platform_code string
, status string
, status_date date
)
PARTITIONED BY(time_key string)
STORED AS ORC;

CREATE TABLE table2(
time_key timestamp
, ctn string
, platform_code string
, status string
, status_date timestamp
)
ROW FORMAT DELIMITED FIELDS TERMINATED BY '\;'
STORED AS TEXTFILE;

在table1中,我有一些数据。实施例

(9056697563,C,,,2017-09-22)

status为空字符串,status_datenull。我需要在将2017-09-22转换为时间戳时插入此行。我试试这个时

SELECT from_unixtime(unix_timestamp(time_key, 'yyyy-MM-dd')) AS time_key
, ctn
, platform_code
, status
, from_unixtime(unix_timestamp(time_key, 'yyyy-MM-dd')) AS status_date
FROM table1
WHERE time_key = '2017-09-22';

time_keystatus_date都有值2017-09-22 00:00:00,但是当我尝试时

INSERT OVERWRITE TABLE table2
SELECT from_unixtime(unix_timestamp(time_key, 'yyyy-MM-dd')) AS time_key
, ctn
, platform_code
, status
, from_unixtime(unix_timestamp(time_key, 'yyyy-MM-dd')) AS status_date
FROM table1
WHERE time_key = '2017-09-22';

time_keynull结束,status_date结束为2017-09-22 00:00:00

为什么会这样?

修改

我删除了AS time_keyAS status_date后,它正常运行。有人知道为什么吗?

0 个答案:

没有答案