我如何在配置单元中添加时间戳列 [英] How can I add a timestamp column in hive

查看:126
本文介绍了我如何在配置单元中添加时间戳列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有2行如下:

  941 78 252 3008 86412 1718502 257796 2223252 292221 45514 114894 

980 78 258 3064 88318 1785623 269374 2322408 305467 46305 116970

我想插入当前的时间戳同时插入每一行。
终于在我的蜂巢表行中应该如下所示:


941 78 252 3008 86412 1718502 257796 2223252 292221 45514 114894
2014-10-21



980 78 258 3064 88318 1785623 269374 2322408 305467 46305 116970
2014-10-22

有没有什么办法可以在不使用猪脚本的情况下将时间戳直接插入配置单元?

/ div>

在插入时,您可以使用 from_unixtime(unix_timestamp())。例如,假设你有以下表格:

  create table t1(c1 String); 
创建表t2(c1 String,c2 timestamp);

现在您可以使用当前时间戳从t1填充表t2。

  insert into table t2 select *,from_unixtime(unix_timestamp())from t1; 


I have 2 rows like below:

941 78 252 3008 86412 1718502 257796 2223252 292221 45514 114894

980 78 258 3064 88318 1785623 269374 2322408 305467 46305 116970

I want to insert current time stamp while inserting each row. finally in my hive table row should be like below:

941 78 252 3008 86412 1718502 257796 2223252 292221 45514 114894 2014-10-21

980 78 258 3064 88318 1785623 269374 2322408 305467 46305 116970 2014-10-22

Is there any way I can insert timestamp directly into hive without using pig script?

解决方案

You can use from_unixtime(unix_timestamp()) while inserting.

For example, suppose you have following tables:

create table t1(c1 String);
create table t2(c1 String, c2 timestamp);

Now you can populate table t2 from t1 with current timestamp:

insert into table t2 select *, from_unixtime(unix_timestamp()) from t1;

这篇关于我如何在配置单元中添加时间戳列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆