如何在 hive 中添加时间戳列 [英] How can I add a timestamp column in hive
问题描述
我有如下两行:
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 1148942014-10-21
941 78 252 3008 86412 1718502 257796 2223252 292221 45514 114894 2014-10-21
980 78 258 3064 88318 1785623 269374 2322408 305467 46305 1169702014-10-22
980 78 258 3064 88318 1785623 269374 2322408 305467 46305 116970 2014-10-22
有没有什么办法可以不使用pig脚本直接将时间戳插入到hive中?
Is there any way I can insert timestamp directly into hive without using pig script?
推荐答案
插入时可以使用from_unixtime(unix_timestamp())
.
例如,假设您有以下表格:
For example, suppose you have following tables:
create table t1(c1 String);
create table t2(c1 String, c2 timestamp);
现在您可以使用当前时间戳从 t1 填充表 t2:
Now you can populate table t2 from t1 with current timestamp:
insert into table t2 select *, from_unixtime(unix_timestamp()) from t1;
这篇关于如何在 hive 中添加时间戳列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!