简体   繁体   English

如何从时间戳中分离日期和时间并将其存储在Hive的另一个表中

[英]How to separate date and time from timestamp and store it in another table in hive

I have installed hive 2.1.1 on hadoop where I have created table with name data with columns (dis string,dt timestamp). 我已经在hadoop上安装了蜂巢2.1.1,在其中我创建了带有名称数据的表(dis string,dt timestamp)。 I wanted to store date and time in separate columns so i created another table with name data1 and columns (dis string, dat date,time string). 我想将日期和时间存储在单独的列中,所以我创建了另一个名称为data1和列(dis字符串,dat日期,时间字符串)的表。 How can i copy data from table data to data1. 我如何将数据从表数据复制到data1。 I have tried to it by doing "insert into table data1 select dis,convert(date,dt),convert(time,dt) from data;". 我已经尝试过通过“插入表data1从数据中选择dis,convert(date,dt),convert(time,dt);”来尝试这样做。

使用以下查询

insert into table data1 select dis,TO_DATE(dt),concat(HOUR(DT),':',MINUTE(dt)) from data;
select dis,to_date(dt),split(dt,' ')[1]

or 要么

select dis,to_date(dt),substr(dt,12,8)

Demo 演示

with t as (select timestamp '2017-04-06 04:20:33' as dt) 
select to_date(dt),split(dt,' ')[1] from t;
OK
_c0 _c1
2017-04-06  04:20:33

with t as (select timestamp '2017-04-06 04:20:33' as dt) 
select to_date(dt),substr(dt,12,8) from t;
OK
_c0 _c1
2017-04-06  04:20:33

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM