Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
744 views
in Technique[技术] by (71.8m points)

hiveql - How can I add a timestamp column in hive

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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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;

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...