Archives of Support Questions (Read Only)

This is an archived board for historical reference. Information and links may no longer be available or relevant
Announcements
This board is archived and read-only for historical reference. To ask a new question, please post a new topic on the appropriate active board.

How to set variable in hive partition ?

avatar
Rising Star

Hello all,

How to set variable in hive and insert value as partition? I have below commands and the partition is not getting from the variable that I set but getting constant "var" instead datetime.

set hiveVar:var= from_unixtime(unix_timestamp()-1*60*60*4, 'yyyyMMddHH');

INSERT INTO TABLE tmp Partition (datehour='${hiveVar:var}') SELECT * FROM tmp2;

Please help.

Thanks

JN

1 ACCEPTED SOLUTION

avatar

@JT Ng

Just omit the quotes and fire the insert.

INSERT INTO TABLE tmp Partition (datehour=${hiveVar:var}) SELECT * FROM tmp2;

You can also test before firing the insert like this:

select ${hiveVar:var};

You should be good.

Thanks

View solution in original post

2 REPLIES 2

avatar

@JT Ng

Just omit the quotes and fire the insert.

INSERT INTO TABLE tmp Partition (datehour=${hiveVar:var}) SELECT * FROM tmp2;

You can also test before firing the insert like this:

select ${hiveVar:var};

You should be good.

Thanks

avatar

@JT Ng

You might want to close the thread by accepting the answer.