Support Questions
Find answers, ask questions, and share your expertise
Announcements
Alert: Welcome to the Unified Cloudera Community. Former HCC members be sure to read and learn how to activate your account here.

How to use current date as value for a variable in hive script

Highlighted

How to use current date as value for a variable in hive script

Expert Contributor

My script looks like this:

INSERT OVERWRITE DIRECTORY '/user/xyz/reports/oos_table_sales/${DATE}' ROW FORMAT DELIMITED FIELDS TERMINATED BY ',' SELECT * FROM outputs.oos_table_sale;

FOR $DATE, I would like current_date() to be used automatically. I have tried using function current_date but it is being taken as a string.How do I use value of current_date returned as value for ${DATE}

2 REPLIES 2
Highlighted

Re: How to use current date as value for a variable in hive script

@Simran Kaur

Try this hive -hiveconf dt=current_date -e 'select ${hiveconf:dt;'

Hope it helps!!

Re: How to use current date as value for a variable in hive script

Contributor

Hi @Simran Kaur

If you want to use this within the script, you can do the following.

set hivevar:DATE=current_date;

INSERT OVERWRITE DIRECTORY '/user/xyz/reports/oos_table_sales/${DATE}' ROW FORMAT DELIMITED FIELDS TERMINATED BY ',' SELECT * FROM outputs.oos_table_sale;

Cheers,

Sagar

Don't have an account?
Coming from Hortonworks? Activate your account here