Support Questions

Find answers, ask questions, and share your expertise

Passing parameters in Hive

avatar

Hi

 

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/hive-log4j.properties
OK
Time taken: 8.393 seconds
WARN: The method class org.apache.commons.logging.impl.SLF4JLogFactory#release() was invoked.
WARN: Please see http://www.slf4j.org/codes.html#release for an explanation.

 

4 REPLIES 4

avatar
Rising Star
Hey,
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.
https://cwiki.apache.org/confluence/display/Hive/LanguageManual+VariableSubstitution

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

avatar
Super Guru

Hi,

 

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.

 

Thanks

 

 

avatar

Hi

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.

 

avatar
Explorer

 

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