Created on 09-26-2016 05:34 PM - edited 09-16-2022 03:41 AM
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.
Created 09-27-2016 07:13 AM
Created 09-30-2016 01:44 AM
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
Created 09-30-2016 02:32 PM
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.
Created 12-08-2017 09:40 AM
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