Hive数据库将epochtime转换为YYYY-MM-DD格式

时间:2013-07-25 16:04:17

标签: hive

我必须访问一个配置单元数据库。在该数据库中,时间存储为bigint列中的epochtime。我以yyyy-mm-dd格式检索数据。有人请帮我这个

表格说明

temp_table   名字串   ts bigint   age int

ts列以epoch时间戳格式存储数据

当我从temp_table

中给出select *时

重新获得的值是

bob 1374752536 12

我需要输出

bob 2013-07-25 12:14:17 12

1 个答案:

答案 0 :(得分:0)

您可以使用Hive提供的 from_unixtime()日期函数。它将时间戳转换为表示该时间戳的字符串。

用法:

hive> select from_unixtime(1374752536) from demo;

示例:

输入:

bob 1374752536 12
tariq 1374778369 25

查询:

  

蜂房>创建外部表demo2(name string,ts bigint,age int)行   格式分隔的字段以''location'/ inputs / date /';

结尾      

蜂房>从demo2中选择from_unixtime(ts);

输出:

OK

2013-07-25 17:12:16 
2013-07-26 00:22:49 
Time taken: 6.3 seconds

HTH

相关问题