Support Questions

Find answers, ask questions, and share your expertise

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

avatar
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

avatar

@Simran Kaur

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

Hope it helps!!

avatar
Rising Star

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