简体   繁体   中英

How to use hive variable substitution rightly

When I'm using variable substitution in hive, I meet some errors, but I need your help.

My code:

set hievar:b='on t1.id=t2.id where t2.id is null';
select * from t_old as t1 full outer join t_new as t2 ${b};

when I run this code in hive shell, it give me some error about ${b} .

I also try this:

set hivevar:c='select * from t_old as t1 full outer join t_new as t2 on t1.id=t2.id where t2.id is null';
${c};

It gives me the same error.

Fix hivevar namespace name (in your code it is hievar ) and remove quotes, because they are also passed as is in Hive.

Example:

set hivevar:b=where 1=1; --without quotes
select 1 ${hivevar:b}; --you can do without hivevar: as in your example

Result:

OK
1
Time taken: 0.129 seconds, Fetched: 1 row(s)

Second example:

hive> set hivevar:c=select 1 where 1=1;
hive> ${c};
OK
1
Time taken: 0.491 seconds, Fetched: 1 row(s)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM