Posts: 17
Registered: ‎09-17-2016

Passing parameters in Hive



I want to pass the parameters to Hive Script:-

 Note:- I don't want to execute this script by using command line arguments. So I don't want to give any arguments during run time.


set current_date = 01-01-2015;
select * from glvc.product where date = '${hiveconf:start_date}';


when I use execute the script, I didn't get any result:-


[cloudera@quickstart ~]$ hive -hiveconf start_date=current_date -f argument_script.hql
2016-09-26 17:30:18,460 WARN [main] mapreduce.TableMapReduceUtil: The hbase-prefix-tree module jar containing PrefixTreeCodec is not present. Continuing without it.

Logging initialized using configuration in file:/etc/hive/conf.dist/
Time taken: 8.393 seconds
WARN: The method class org.apache.commons.logging.impl.SLF4JLogFactory#release() was invoked.
WARN: Please see for an explanation.


Cloudera Employee
Posts: 32
Registered: ‎08-16-2016

Re: Passing parameters in Hive

First you want to ensure that variable substitution is not disabled in your hive environment. So check the value of "hive.variable.substitute" property in your configuration.

A few examples are provided in the documentation wiki below.

There are multiple namespaces in hive (system, hiveconf, env etc). env looks at the environment variables. I think you want to use something other than hiveconf (because it meant for propertiesi n hive-site.xml file) Please find examples below and let me know if you still need help. Thanks
Cloudera Employee
Posts: 375
Registered: ‎03-23-2015

Re: Passing parameters in Hive



I can see that you are setting "current_date = 01-01-2015;", however you used ${hiveconf:start_date}, which I think should be ${hiveconf:current_date}


Also, when you run "hive -hiveconf start_date=current_date -f argument_script.hql" from command line, where do you set "current_date"? If it is on the command line, then I think you should be using $current_date instead.


Like Naveen mentioned, you should make sure that hive.variable.substitute=true first.





Posts: 17
Registered: ‎09-17-2016

Re: Passing parameters in Hive


The property is already true. As I know, I can pass arguments by two methods :-

1. Passing value through CLI

  command is =     hive -hiveconf current_date=01-01-2015 -f argument.hql


Here my script is -
select * from glvc.product where date = '${hiveconf:current_date}';

Here my command executes fine and I got the result.


2. Passing arguments

 In this case , I have already set the value in my script file and I don't want to pass the value through CLI.

 If I write command  =   hive -hiveconf:current_date -f argument.hql , I didnt get the result. That's why I had taken a variable earlier.

Script -

set current_date = 01-01-2015;
select * from glvc.product where date = '${hiveconf:current_date}';


I don't know how to use hiveconf in this case where the value is already set.

Kindly solve my problem in the case of passing arguments.


New Contributor
Posts: 5
Registered: ‎06-13-2017

Re: Passing parameters in Hive


the first thing you have to do in your script


set hive.variable.substitute=true;
set current_date=${hiveconf:current_date};


command should be  hive  -v --hiveconf current_date='01-01-2015' -f argument.hql


it will execute successfully 


-V willp rint the sql command in console appliocation 



read hiveconf and hivevar  concepts