如何将'%Y%m%d%H%i%s'列拆分为两列:一列包含%Y%m%d%,其中包含H%i%s in hive?

时间:2017-04-27 15:26:01

标签: hive impala

我有一列显示'%Y%m%d%H%i%s'(例如20150125145900)如何将其转换为两列,一列为“ymd”,另一列为“his”(例如2015/01 / 25和14:59:00)?

2 个答案:

答案 0 :(得分:0)

select datetime[0] as,datetime[1] as {小时{1}}

from (select split(from_unixtime(unix_timestamp('20150125145900','yyyyMMddhhmmss'),'yyyy-MM-dd HH:mm:ss'),' ') as datetime)e

答案 1 :(得分:0)

<强>蜂房

select  ts[0] as year
       ,ts[1] as hour

from   (select  split(from_unixtime(unix_timestamp('20150125145900','yyyyMMddHHmmss')
                    ,'yyyy-MM-dd HH:mm:ss'),' ') as ts
        ) t
+------------+----------+
|    year    |   hour   |
+------------+----------+
| 2015-01-25 | 14:59:00 |
+------------+----------+

<强>帕拉

select  split_part(ts,' ',1) as year
       ,split_part(ts,' ',2) as hour

from   (select  from_unixtime(unix_timestamp('20150125145900','yyyyMMddHHmmss')
                    ,'yyyy-MM-dd HH:mm:ss') as ts
        ) t
;
+------------+----------+
| year       | hour     |
+------------+----------+
| 2015-01-25 | 14:59:00 |
+------------+----------+