How to pass multiple parameter in hive script
You should use --hivevar
instead with newer Hive versions. Earlier, developers were able to set configuration using --hiveconf
and it was also used for variables. However, later --hivevar
was implemented to have separate namespace for variables as mentioned in HIVE-2020.
Use following with beeline
beeline --hivevar table=employee --hivevar year=2016 -f sample.hql
With this, in the Hive script file you can access this variables directly or using hivevar namespace like below.
select * from ${table};select * from ${hivevar:table};
Please, note that you may need to specify URL string using -u <db_URL>
option.
By doing R&D found the correct answer, ${hiveconf:table} should define in script without ' '.sample.hql:-
use ${hiveconf:database}; select * from ${hiveconf:table} where year = ${hiveconf:year};
Running sample.hql
[cloudera@quickstart shell]$ hive -hiveconf database=octdb -hiveconf table=employee -hiveconf year=2016 -f sample.hql
Logging initialized using configuration in file:/etc/hive/conf.dist/hive-log4j.propertiesOK
Time taken: 1.484 secondsOK1 A 20162 B 20164 D 2016
Time taken: 4.423 seconds, Fetched: 3 row(s)